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:'',
|
phone: '',
|
linkMan:'',
|
startTime:'00:00',
|
endTime:'24:00',
|
storeStatusList:[]
|
// 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
|
},
|
linkMan: {
|
required: true
|
},
|
phone: {
|
required: true,
|
mobile: true
|
}
|
},
|
messages: {
|
street: {
|
required: '请输入门店详细地址'
|
},
|
storeName: {
|
required: '请输入门店名称'
|
},
|
linkMan: {
|
required: '请输入负责人姓名'
|
},
|
phone: {
|
required: '请输入门店联系方式',
|
mobile: '手机号格式不正确'
|
},
|
},
|
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=getCustomerStoreDetail`,
|
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.name"]: data.addressName,
|
["location.longitude"]: data.longitude,
|
["location.latitude"]: data.latitude,
|
status: data.status,
|
startTime: data.fromBusinessHours,
|
endTime: data.toBusinessHours,
|
phone: data.telephone,
|
linkMan: data.linkMan,
|
storeStatusList:result.storeStatusList
|
})
|
},
|
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);
|
this.checkField(`street`,value);
|
},
|
checkStoreName(e:any){
|
let { value } = e.detail;
|
console.log(e);
|
this.checkField(`storeName`,value);
|
},
|
checkLinkMan(e:any){
|
let { value } = e.detail;
|
console.log(e);
|
this.checkField(`linkMan`,value);
|
},
|
checkPhone(e:any){
|
let { value } = e.detail;
|
console.log(e);
|
this.checkField(`phone`,value);
|
},
|
checkField(name:string,value:string){
|
let errorMsg = validatorInstance.checkField(`${name}`,value);
|
if (errorMsg===''){
|
this.setData({
|
[`${name}`]: value,
|
[`${name}Error`]: errorMsg,
|
})
|
} else {
|
this.setData({
|
[`${name}Name`]: value,
|
[`${name}Error`]: 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/customerStore.do?m=deleteCustomerStore`,
|
data:{
|
doccode
|
}
|
})
|
)
|
if (error){
|
console.log(error);
|
return;
|
}
|
console.log(result);
|
wx.showToast({
|
title:'删除成功'
|
})
|
setTimeout(() => {wx.navigateBack();},1000)
|
},
|
async saveStore(){
|
let timeSelector = this.selectComponent('#time-selector');
|
let {startTime,endTime} = timeSelector.getSelectedTime();
|
let storeStatus = this.selectComponent('#store-status');
|
let status = storeStatus.getStoreStatusValue();
|
let {
|
location,
|
street,
|
storeName,
|
doccode,
|
images,
|
linkMan,
|
phone
|
} = 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,
|
linkMan,
|
fromBusinessHours:startTime,
|
toBusinessHours:endTime,
|
telephone:phone,
|
docCode:doccode,
|
status
|
}
|
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(() => {wx.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:wx.$utils.debounce(function(this:any){
|
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 {}
|