提交 | 用户 | age
|
61abc9
|
1 |
import MyValidator from "../../utils/myValidator";
|
S |
2 |
// @ts-ignore
|
|
3 |
const chooseLocation = requirePlugin('chooseLocation');
|
|
4 |
let validatorInstance: MyValidator;
|
|
5 |
Page({
|
|
6 |
data: {
|
|
7 |
doccode:null as any,
|
|
8 |
location:null as any,
|
|
9 |
street:'',
|
|
10 |
storeName:'',
|
|
11 |
images:'',
|
9d3461
|
12 |
phone: '',
|
S |
13 |
linkMan:'',
|
|
14 |
startTime:'00:00',
|
|
15 |
endTime:'24:00',
|
|
16 |
storeStatusList:[]
|
|
17 |
// selectedStoreIdList:[]
|
61abc9
|
18 |
},
|
S |
19 |
onLoad(options) {
|
|
20 |
console.log(options);
|
|
21 |
let doccode = options.doccode;
|
|
22 |
if (doccode) {
|
|
23 |
this.setData({
|
|
24 |
doccode
|
|
25 |
})
|
|
26 |
this.getStoreData()
|
|
27 |
}
|
|
28 |
this.setData({
|
|
29 |
fileUploadUrl: "/shopping/customerStore.do?m=uploadAttachment",
|
|
30 |
fileDeleteUrl: "/shopping/customerStore.do?m=deleteAttachment",
|
|
31 |
});
|
|
32 |
// this.getMyFootprint();
|
9d3461
|
33 |
// const eventChannel = this.getOpenerEventChannel();
|
S |
34 |
// eventChannel.on('getStoreListFromStoreListPage', (data:any)=> {
|
|
35 |
// console.log('获取新建活动时选中的门店',data)
|
|
36 |
// this.setData({
|
|
37 |
// selectedStoreIdList:data.selectedStoreIdList,
|
|
38 |
// })
|
|
39 |
//
|
|
40 |
// })
|
61abc9
|
41 |
},
|
S |
42 |
onReady() {
|
|
43 |
validatorInstance = new MyValidator({
|
|
44 |
rules: {
|
|
45 |
street: {
|
|
46 |
required: true,
|
|
47 |
},
|
|
48 |
storeName: {
|
|
49 |
required: true
|
|
50 |
},
|
9d3461
|
51 |
linkMan: {
|
S |
52 |
required: true
|
|
53 |
},
|
|
54 |
phone: {
|
|
55 |
required: true,
|
|
56 |
mobile: true
|
|
57 |
}
|
61abc9
|
58 |
},
|
S |
59 |
messages: {
|
|
60 |
street: {
|
|
61 |
required: '请输入门店详细地址'
|
|
62 |
},
|
|
63 |
storeName: {
|
|
64 |
required: '请输入门店名称'
|
9d3461
|
65 |
},
|
S |
66 |
linkMan: {
|
|
67 |
required: '请输入负责人姓名'
|
|
68 |
},
|
|
69 |
phone: {
|
|
70 |
required: '请输入门店联系方式',
|
|
71 |
mobile: '手机号格式不正确'
|
61abc9
|
72 |
},
|
S |
73 |
},
|
|
74 |
multiCheck:true
|
|
75 |
},this);
|
|
76 |
},
|
|
77 |
async getStoreData(){
|
|
78 |
let doccode = this.data.doccode;
|
|
79 |
let [error, result] = await wx.$utils.to(
|
|
80 |
wx.$http.request({
|
9d3461
|
81 |
url:`/shopping/customerStore.do?m=getCustomerStoreDetail`,
|
61abc9
|
82 |
data:{
|
S |
83 |
doccode
|
|
84 |
}
|
|
85 |
})
|
|
86 |
)
|
|
87 |
if (error){
|
|
88 |
console.log(error);
|
|
89 |
return;
|
|
90 |
}
|
|
91 |
console.log(result);
|
|
92 |
let data = result.list[0];
|
|
93 |
this.setData({
|
|
94 |
street: data.street,
|
|
95 |
storeName:data.storeName,
|
|
96 |
imagesUrl:data.imagesUrl,
|
|
97 |
["location.province"]: data.provinceName,
|
|
98 |
["location.city"]: data.cityName,
|
|
99 |
["location.district"]: data.countyName,
|
|
100 |
["location.address"]: data.address,
|
9d3461
|
101 |
["location.name"]: data.addressName,
|
61abc9
|
102 |
["location.longitude"]: data.longitude,
|
S |
103 |
["location.latitude"]: data.latitude,
|
9d3461
|
104 |
status: data.status,
|
S |
105 |
startTime: data.fromBusinessHours,
|
|
106 |
endTime: data.toBusinessHours,
|
|
107 |
phone: data.telephone,
|
|
108 |
linkMan: data.linkMan,
|
|
109 |
storeStatusList:result.storeStatusList
|
61abc9
|
110 |
})
|
S |
111 |
},
|
|
112 |
selectLocation(){
|
|
113 |
const key = wx.globalData.TengXunMapLocationServiceKey;
|
|
114 |
if (!key) {
|
|
115 |
wx.showModal({
|
|
116 |
title: '提示',
|
|
117 |
content: '请配置腾讯地图服务所需要的key',
|
|
118 |
showCancel:false
|
|
119 |
})
|
|
120 |
return;
|
|
121 |
}
|
|
122 |
const referer = 'miniApp';
|
|
123 |
wx.navigateTo({
|
|
124 |
url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
|
|
125 |
// + '&location=' + location + '&category=' + category
|
|
126 |
});
|
|
127 |
},
|
|
128 |
checkStreet(e:any){
|
|
129 |
let { value } = e.detail;
|
|
130 |
console.log(e);
|
9d3461
|
131 |
this.checkField(`street`,value);
|
61abc9
|
132 |
},
|
S |
133 |
checkStoreName(e:any){
|
|
134 |
let { value } = e.detail;
|
|
135 |
console.log(e);
|
9d3461
|
136 |
this.checkField(`storeName`,value);
|
S |
137 |
},
|
|
138 |
checkLinkMan(e:any){
|
|
139 |
let { value } = e.detail;
|
|
140 |
console.log(e);
|
|
141 |
this.checkField(`linkMan`,value);
|
|
142 |
},
|
|
143 |
checkPhone(e:any){
|
|
144 |
let { value } = e.detail;
|
|
145 |
console.log(e);
|
|
146 |
this.checkField(`phone`,value);
|
|
147 |
},
|
|
148 |
checkField(name:string,value:string){
|
|
149 |
let errorMsg = validatorInstance.checkField(`${name}`,value);
|
61abc9
|
150 |
if (errorMsg===''){
|
S |
151 |
this.setData({
|
9d3461
|
152 |
[`${name}`]: value,
|
S |
153 |
[`${name}Error`]: errorMsg,
|
61abc9
|
154 |
})
|
S |
155 |
} else {
|
|
156 |
this.setData({
|
9d3461
|
157 |
[`${name}Name`]: value,
|
S |
158 |
[`${name}Error`]: errorMsg,
|
61abc9
|
159 |
})
|
S |
160 |
}
|
|
161 |
},
|
9d3461
|
162 |
onDeleteStore() {
|
S |
163 |
|
|
164 |
// console.log(event);
|
|
165 |
wx.pro.showModal({
|
|
166 |
title: '确定删除该门店吗?',
|
|
167 |
}).then((res:any) => {
|
|
168 |
if (res.confirm) {
|
|
169 |
console.log('用户点击确定')
|
|
170 |
this.deleteStore();
|
|
171 |
|
|
172 |
} else if (res.cancel) {
|
|
173 |
console.log('用户点击取消')
|
|
174 |
}
|
|
175 |
// instance.close();
|
|
176 |
});
|
|
177 |
},
|
|
178 |
async deleteStore(){
|
|
179 |
let doccode = this.data.doccode;
|
|
180 |
let [error, result] = await wx.$utils.to(
|
|
181 |
wx.$http.request({
|
|
182 |
url:`/shopping/customerStore.do?m=deleteCustomerStore`,
|
|
183 |
data:{
|
|
184 |
doccode
|
|
185 |
}
|
|
186 |
})
|
|
187 |
)
|
|
188 |
if (error){
|
|
189 |
console.log(error);
|
|
190 |
return;
|
|
191 |
}
|
|
192 |
console.log(result);
|
|
193 |
wx.showToast({
|
|
194 |
title:'删除成功'
|
|
195 |
})
|
|
196 |
setTimeout(() => {wx.navigateBack();},1000)
|
|
197 |
},
|
61abc9
|
198 |
async saveStore(){
|
9d3461
|
199 |
let timeSelector = this.selectComponent('#time-selector');
|
S |
200 |
let {startTime,endTime} = timeSelector.getSelectedTime();
|
|
201 |
let storeStatus = this.selectComponent('#store-status');
|
|
202 |
let status = storeStatus.getStoreStatusValue();
|
61abc9
|
203 |
let {
|
S |
204 |
location,
|
|
205 |
street,
|
|
206 |
storeName,
|
|
207 |
doccode,
|
9d3461
|
208 |
images,
|
S |
209 |
linkMan,
|
|
210 |
phone
|
61abc9
|
211 |
} = this.data;
|
S |
212 |
let storeData = {
|
|
213 |
countryName:'中国',
|
|
214 |
provinceName: location.province,
|
|
215 |
cityName: location.city,
|
|
216 |
countyName: location.district,
|
|
217 |
address: location.address,
|
|
218 |
addressName: location.name,
|
|
219 |
longitude: location.longitude,
|
|
220 |
latitude: location.latitude,
|
|
221 |
street,
|
|
222 |
storeName,
|
|
223 |
images,
|
9d3461
|
224 |
linkMan,
|
S |
225 |
fromBusinessHours:startTime,
|
|
226 |
toBusinessHours:endTime,
|
|
227 |
telephone:phone,
|
|
228 |
docCode:doccode,
|
|
229 |
status
|
61abc9
|
230 |
}
|
S |
231 |
console.log('待保存的门店数据',storeData);
|
|
232 |
let [error, result] = await wx.$utils.to(
|
|
233 |
wx.$http.request({
|
|
234 |
url:`/shopping/customerStore.do?m=saveCustomerStore`,
|
|
235 |
data: storeData,
|
|
236 |
method:'POST'
|
|
237 |
})
|
|
238 |
)
|
|
239 |
if (error){
|
|
240 |
console.log(error);
|
|
241 |
return;
|
|
242 |
}
|
|
243 |
console.log(result);
|
|
244 |
wx.showToast({
|
|
245 |
title:'保存成功'
|
|
246 |
})
|
9d3461
|
247 |
setTimeout(() => {wx.navigateBack();},1500)
|
61abc9
|
248 |
},
|
9d3461
|
249 |
// navigateBack(mode?:any){
|
S |
250 |
// let {selectedStoreIdList,doccode} = this.data;
|
|
251 |
// if (mode =='delete'){
|
|
252 |
// // @ts-ignore
|
|
253 |
// selectedStoreIdList.splice(selectedStoreIdList.indexOf(doccode),1)
|
|
254 |
// console.log('删除门店后的selectedStoreIdList',selectedStoreIdList);
|
|
255 |
// }
|
|
256 |
//
|
|
257 |
// let eventChannel = this.getOpenerEventChannel();
|
|
258 |
// eventChannel.emit('getSelectedStoreIdListFromStoreEditPage', {
|
|
259 |
// selectedStoreIdList,
|
|
260 |
// });
|
|
261 |
// wx.navigateBack();
|
|
262 |
// },
|
3fc241
|
263 |
onSave:wx.$utils.debounce(function(this:any){
|
61abc9
|
264 |
let location = this.data.location;
|
S |
265 |
if (!location) {
|
|
266 |
wx.showToast({
|
|
267 |
title:'请选择门店地址',
|
|
268 |
icon:'none'
|
|
269 |
})
|
|
270 |
return
|
|
271 |
}
|
|
272 |
|
|
273 |
let checkAllData = validatorInstance.checkAllData();
|
|
274 |
let fileUploaderMultiple = this.selectComponent('#file-uploader-multiple');
|
|
275 |
let checkImages = fileUploaderMultiple.checkImages("images", "请至少上传一张图片");
|
|
276 |
if (!checkAllData){
|
|
277 |
console.log('还有错误未处理');
|
|
278 |
return;
|
|
279 |
}
|
|
280 |
if (!checkImages) return;
|
|
281 |
let images = fileUploaderMultiple.getImagesUnid();
|
|
282 |
this.setData({
|
|
283 |
images
|
|
284 |
})
|
|
285 |
console.log('....提交成功');
|
|
286 |
this.saveStore();
|
3fc241
|
287 |
}),
|
61abc9
|
288 |
onShow(){
|
S |
289 |
const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
|
|
290 |
console.log(location);
|
|
291 |
if (location) {
|
|
292 |
this.setData({
|
|
293 |
location
|
|
294 |
})
|
|
295 |
}
|
|
296 |
|
|
297 |
},
|
|
298 |
onUnload () {
|
|
299 |
// 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
|
|
300 |
chooseLocation.setLocation(null);
|
|
301 |
}
|
|
302 |
|
|
303 |
})
|
|
304 |
export {}
|