import MyValidator from "../../utils/myValidator";
|
// @ts-ignore
|
const chooseLocation = requirePlugin('chooseLocation');
|
let validatorInstance: MyValidator;
|
Page({
|
data: {
|
doccode:null as any,
|
location:null as any,
|
street:'',
|
storeName:'',
|
images:'',
|
selectedStoreIdList:[]
|
},
|
onLoad(options) {
|
console.log(options);
|
let doccode = options.doccode;
|
if (doccode) {
|
this.setData({
|
doccode
|
})
|
this.getStoreData()
|
}
|
this.setData({
|
fileUploadUrl: "/shopping/customerStore.do?m=uploadAttachment",
|
fileDeleteUrl: "/shopping/customerStore.do?m=deleteAttachment",
|
});
|
// this.getMyFootprint();
|
const eventChannel = this.getOpenerEventChannel();
|
eventChannel.on('getStoreListFromStoreListPage', (data:any)=> {
|
console.log('获取新建活动时选中的门店',data)
|
this.setData({
|
selectedStoreIdList:data.selectedStoreIdList,
|
})
|
|
})
|
},
|
onReady() {
|
validatorInstance = new MyValidator({
|
rules: {
|
street: {
|
required: true,
|
},
|
storeName: {
|
required: true
|
},
|
},
|
messages: {
|
street: {
|
required: '请输入门店详细地址'
|
},
|
storeName: {
|
required: '请输入门店名称'
|
},
|
},
|
multiCheck:true
|
},this);
|
},
|
async getStoreData(){
|
let doccode = this.data.doccode;
|
let [error, result] = await wx.$utils.to(
|
wx.$http.request({
|
url:`/shopping/customerStore.do?m=getCustomerStore`,
|
data:{
|
doccode
|
}
|
})
|
)
|
if (error){
|
console.log(error);
|
return;
|
}
|
console.log(result);
|
let data = result.list[0];
|
this.setData({
|
street: data.street,
|
storeName:data.storeName,
|
imagesUrl:data.imagesUrl,
|
["location.province"]: data.provinceName,
|
["location.city"]: data.cityName,
|
["location.district"]: data.countyName,
|
["location.address"]: data.address,
|
["location.longitude"]: data.longitude,
|
["location.latitude"]: data.latitude,
|
["location.name"]: data.addressName,
|
})
|
},
|
selectLocation(){
|
const key = wx.globalData.TengXunMapLocationServiceKey;
|
if (!key) {
|
wx.showModal({
|
title: '提示',
|
content: '请配置腾讯地图服务所需要的key',
|
showCancel:false
|
})
|
return;
|
}
|
const referer = 'miniApp';
|
wx.navigateTo({
|
url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer
|
// + '&location=' + location + '&category=' + category
|
});
|
},
|
checkStreet(e:any){
|
let { value } = e.detail;
|
console.log(e);
|
let errorMsg = validatorInstance.checkField(`street`,value);
|
console.log(errorMsg);
|
if (errorMsg===''){
|
this.setData({
|
[`street`]: value,
|
[`streetError`]: errorMsg,
|
})
|
} else {
|
this.setData({
|
[`street`]: value,
|
[`streetError`]: errorMsg,
|
})
|
}
|
},
|
checkStoreName(e:any){
|
let { value } = e.detail;
|
console.log(e);
|
let errorMsg = validatorInstance.checkField(`storeName`,value);
|
console.log(errorMsg);
|
if (errorMsg===''){
|
this.setData({
|
[`storeName`]: value,
|
[`storeNameError`]: errorMsg,
|
})
|
} else {
|
this.setData({
|
[`storeName`]: value,
|
[`storeNameError`]: errorMsg,
|
})
|
}
|
},
|
// onDeleteStore() {
|
//
|
// // console.log(event);
|
// wx.pro.showModal({
|
// title: '确定删除该门店吗?',
|
// }).then((res:any) => {
|
// if (res.confirm) {
|
// console.log('用户点击确定')
|
// this.deleteStore();
|
//
|
// } else if (res.cancel) {
|
// console.log('用户点击取消')
|
// }
|
// // instance.close();
|
// });
|
// },
|
// async deleteStore(){
|
// let doccode = this.data.doccode;
|
// let [error, result] = await wx.$utils.to(
|
// wx.$http.request({
|
// url:`/shopping/panicBuyingStore.do?m=deleteStore`,
|
// data:{
|
// doccode
|
// }
|
// })
|
// )
|
// if (error){
|
// console.log(error);
|
// return;
|
// }
|
// console.log(result);
|
// wx.showToast({
|
// title:'删除成功'
|
// })
|
// setTimeout(() => {this.navigateBack('delete');},1000)
|
// },
|
async saveStore(){
|
let {
|
location,
|
street,
|
storeName,
|
doccode,
|
images
|
} = this.data;
|
let storeData = {
|
countryName:'中国',
|
provinceName: location.province,
|
cityName: location.city,
|
countyName: location.district,
|
address: location.address,
|
addressName: location.name,
|
longitude: location.longitude,
|
latitude: location.latitude,
|
street,
|
storeName,
|
images,
|
docCode:doccode
|
}
|
console.log('待保存的门店数据',storeData);
|
let [error, result] = await wx.$utils.to(
|
wx.$http.request({
|
url:`/shopping/customerStore.do?m=saveCustomerStore`,
|
data: storeData,
|
method:'POST'
|
})
|
)
|
if (error){
|
console.log(error);
|
return;
|
}
|
console.log(result);
|
wx.showToast({
|
title:'保存成功'
|
})
|
setTimeout(() => {this.navigateBack();},1500)
|
},
|
navigateBack(mode?:any){
|
let {selectedStoreIdList,doccode} = this.data;
|
if (mode =='delete'){
|
// @ts-ignore
|
selectedStoreIdList.splice(selectedStoreIdList.indexOf(doccode),1)
|
console.log('删除人员后的selectedStoreIdList',selectedStoreIdList);
|
}
|
|
let eventChannel = this.getOpenerEventChannel();
|
eventChannel.emit('getSelectedStoreIdListFromStoreEditPage', {
|
selectedStoreIdList,
|
});
|
wx.navigateBack();
|
},
|
onSave(){
|
let location = this.data.location;
|
if (!location) {
|
wx.showToast({
|
title:'请选择门店地址',
|
icon:'none'
|
})
|
return
|
}
|
|
let checkAllData = validatorInstance.checkAllData();
|
let fileUploaderMultiple = this.selectComponent('#file-uploader-multiple');
|
let checkImages = fileUploaderMultiple.checkImages("images", "请至少上传一张图片");
|
if (!checkAllData){
|
console.log('还有错误未处理');
|
return;
|
}
|
if (!checkImages) return;
|
let images = fileUploaderMultiple.getImagesUnid();
|
this.setData({
|
images
|
})
|
console.log('....提交成功');
|
this.saveStore();
|
},
|
onShow(){
|
const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
|
console.log(location);
|
if (location) {
|
this.setData({
|
location
|
})
|
}
|
|
},
|
onUnload () {
|
// 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
|
chooseLocation.setLocation(null);
|
}
|
|
})
|
export {}
|