add.vue
4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<template>
<view>
<view class="content-top">
<view class="content-item u-f u-f-aic p-10">
<view class="title require u-f1">
物料编码
</view>
<view class="inp u-f3">
<input v-model="form.code" placeholder="请输入编码" />
</view>
</view>
<view class="content-item u-f u-f-aic p-10">
<view class="title require u-f1">
物料名称
</view>
<view class="inp u-f3">
<input v-model="form.name" placeholder="请输入名称" />
</view>
</view>
<view class="content-item u-f u-f-aic p-10">
<view class="title u-f1">
物料规格
</view>
<view class="inp u-f3">
<input v-model="form.spec" placeholder="请输入规格" />
</view>
</view>
<view class="content-item u-f p-10" @tap="selectUnit">
<view class="title u-f1">
物料单位
</view>
<view class="inp u-f3">
<view class="u-f u-f-aic fr">
<text class="unit">{{abc}}</text>
<uni-icons type="arrowright" size="18" color="gray"></uni-icons>
</view>
</view>
</view>
<view class="content-item u-f u-f-aic p-10">
<view class="title u-f1">
物料类型
</view>
<view class="inp u-f3">
<picker @change="bindPickerChange" :value="typeIndex" :range-key="'name'" :range="materialTypeArr">
<view class="uni-input">
<text class="placeholder-color" v-if="typeIndex == -1">请选择类型</text>
<text v-else>{{materialTypeArr[typeIndex].name}}</text>
</view>
</picker>
</view>
</view>
</view>
<view class="footer u-f u-f-aic">
<button class="btn" :loading="loading" type="warn" @tap="save" :disabled="disabled">保存</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
materialTypeArr: [],
typeIndex: -1,
loading: false,
disabled: false,
form: {
code: undefined,
name: undefined,
spec: undefined,
unit: undefined,
type: undefined
},
msg: "",
timer: null,
abc: ''
}
},
onLoad() {
this.getMaterialType();
this.getMaterialCode();
this.$http.material.listUnit().then(res => {
console.log(res)
});
},
onShow() {
var pages = getCurrentPages();
var currPage = pages[pages.length - 1];
console.log(this.abc)
},
onUnload() {
if(this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
},
methods: {
// 获取物料编码
getMaterialCode() {
this.$http.material.createMaterialCode().then(res => {
this.form.code = res.data.data
})
},
// 获取物料类型
getMaterialType() {
this.$http.material.getMaterialType().then(res => {
console.log(res);
this.materialTypeArr = res.data.data
})
},
// 选择单位
selectUnit() {
uni.navigateTo({
url: "unit/unit"
})
},
// 物料类型选择点击
bindPickerChange: function(e) {
this.typeIndex = e.target.value;
this.form.type = this.materialTypeArr[this.typeIndex].code;
},
// 保存按钮操作
save() {
if (this.loading) {
//判断是否加载中,避免重复点击请求
return false;
}
if (!this.form.code.trim()) {
this.$msg('物料编码不能为空');
return
}
if (!this.form.name.trim()) {
this.$msg('物料名称不能为空');
return
}
this.loading = true;
this.disabled = true;
this.$http.material.addMaterial(this.form).then(res => {
console.log(res);
if (res.data.code == 200) {
this.loading = false;
this.disabled = false;
this.$msg(res.data.msg);
uni.$emit('updateMaterial');
this.timer = setTimeout(() => {
uni.navigateBack()
}, 500)
} else {
this.$msg(res.data.msg);
this.loading = false;
this.disabled = false;
}
}).catch(err => {
this.loading = false;
this.disabled = false;
})
}
}
}
</script>
<style lang="scss" scoped>
.content-top {
background-color: $uni-bg-color;
.content-item {
height: 90rpx;
line-height: 90rpx;
border-bottom: 2rpx solid $uni-border-color;
.title {
font-size: $uni-font-size-lg;
}
.inp {
text-align: right;
font-size: $uni-font-size-lg;
}
.require {
position: relative;
padding-left: 10rpx;
&::after {
position: absolute;
content: '*';
color: red;
font-size: 50rpx;
top: 6rpx;
left: -14rpx;
}
}
}
}
.footer {
position: fixed;
bottom: 0;
width: 100%;
height: 140rpx;
background-color: #fff;
border-top: 2rpx solid #E1F3D8;
.btn {
width: 100%;
height: 80rpx;
line-height: 80rpx;
color: #fff;
text-align: center;
font-size: $uni-font-size-lg;
border-radius: 50rpx;
margin: 0 30rpx;
background-color: $uni-color-primary;
}
}
</style>