Sanakey
2021-07-09 3fc241d02fb8b671289de3d9d80bf848349c04d4
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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 {}