// pages/store/edit1.js const utils = require('../../utils/util') const form = require('../../utils/formValidation') const util = require('../../utils/util.js'); const app = getApp(); const chooseLocation = requirePlugin('chooseLocation'); Page({ // 从地图选点插件返回后,在页面的onShow生命周期函数中能够调用插件接口,取得选点结果对象 onShow () { const location = chooseLocation.getLocation(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null console.log(location) if(location!=null){ console.log("") this.setData({ ["storeInfo.storeAddress"]: location.name, ["storeInfo.latitude"]: location.latitude, ["storeInfo.longitude"]: location.longitude, }); } }, onUnload () { // 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果 chooseLocation.setLocation(null); }, /** * 页面的初始数据 */ data: { selectList:[], multiArray: [], //picker数据 value: [0, 0, 0], text: "", dictList:[], isPickerRender: false, isPickerShow: false, pickerConfig: { endDate: true, dateLimit: true, initStartTime: "2020-01-01", initEndTime: "2020-12-01", limitStartTime: "2015-01-01", limitEndTime: "2095-01-01" }, values: { startTime: "2019-01-01 ", endTime: "2019-12-01" }, storeInfo:{ storeName: '', storePrincipal: '', storePrincipalPhone: '', storeTel: '', storeHouseNum: '', storeArea: '', storeAddress: '', businessBegin: '', businessEnd: '', }, dataStr: '', storeId:'', region: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ storeId: options.storeId }) this.getChildListByMtLei(); this.getDictByCode(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, timePickerShow: function () { this.setData({ isPickerShow: true, isPickerRender: true, chartHide: true }); }, pickerHide: function () { this.setData({ isPickerShow: false, chartHide: false }); }, setPickerTime: function (val) { console.log(val); let data = val.detail; let startTime = utils.formatDate(data.startTime,'hh:mm') let endTime = utils.formatDate(data.endTime,'hh:mm') this.setData({ ["values.startTime"]: startTime, ["values.endTime"]: endTime, dataStr: startTime +" ~ "+ endTime }); this.data.storeInfo.businessBegin = this.data.values.startTime.replace(/\s+/g,""); this.data.storeInfo.businessEnd = this.data.values.endTime.replace(/\s+/g,""); }, formSubmit: function(e) { //表单规则 let rules = [{ name: "storeName", rule: ["required"], //可使用区间,此处主要测试功能 msg: ["请输入门店名称"] }, { name: "storePrincipal", rule: ["required", "isChinese", "minLength:2", "maxLength:6"], msg: ["请输入负责人姓名", "姓名必须全部为中文", "姓名必须2个或以上字符", "姓名不能超过6个字符"] },{ name: "storePrincipalPhone", rule: ["required", "isMobile"], msg: ["请输入负责人手机号", "请输入正确的手机号"] }]; var that = this if(!that.data.storeInfo.businessBegin||!that.data.storeInfo.businessEnd){ util.toast("请输入营业时间") return; } if(!that.data.storeInfo.twoType){ util.toast("请输入二级品类") return; } if(!that.data.storeInfo.storeAddress){ util.toast("请输入详细地址") return; } //进行表单检查 let formData = e.detail.value; let checkRes = form.validation(formData, rules); if (!checkRes) { util.request(util.api.editStore, that.data.storeInfo, "PUT", false, true,app.globalData.token).then((res)=>{ if (res.code == 200) { wx.navigateBack({ url: '/pages/store/index', }) console.log("========================") console.log(storeInfo) } }).catch((res) => {}) // wx.showToast({ // title: "验证通过!", // icon: "none" // }); } else { wx.showToast({ title: checkRes, icon: "none" }); return; } }, delete:function(){ util.request(util.api.storeDelete,{id:this.data.storeId}, "DELETE", true, true,app.globalData.token).then((res)=>{ if (res.code == 200) { wx.navigateTo({ url: '/pages/store/index', }) console.log("========================") console.log(storeInfo) } }).catch((res) => {}) }, formReset: function(e) { console.log("清空数据") }, bindRegionChange: function (e) { console.log(e.detail.value) console.log(e.detail.code) this.setData({ region: e.detail.value }) this.data.storeInfo.storeArea = this.data.region.join(" ") }, bindStore(){ var that = this util.request(util.api.queryByStoreId, {id:that.data.storeId}, "GET", false, true,app.globalData.token).then((res)=>{ if (res.code == 200) { var oneTypeData = that.data.selectList.filter((e)=>e.id == res.result.oneType ); if(oneTypeData!=null&&oneTypeData.length>0){ var twoTypeData = oneTypeData[0].children.filter((e)=>e.id == res.result.twoType ); this.setData({ text: oneTypeData[0].name + " " + twoTypeData[0].name , }) } that.setData({ storeInfo: res.result, dataStr: res.result.businessBegin +" ~ "+ res.result.businessEnd, region: res.result.storeArea?(res.result.storeArea).split(" "):[] }) var peisongTypeData = that.data.dictList.filter((e)=>e.value == res.result.peisongType ); if(peisongTypeData !=null && peisongTypeData.length>0){ that.setData({ ['storeInfo.peisongTypeName']:peisongTypeData[0].text, }) } console.log("========================") console.log(storeInfo) } }).catch((res) => {}) }, inputedit: function (e) { let _this = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; let name = dataset.name; _this.data[name] = value; _this.setData({ [name]: _this.data[name] }); }, //选择地图 selectMap(){ const key = '3UWBZ-YVSWX-V4245-T2G6T-QQ5US-BJFMP'; //使用在腾讯位置服务申请的key const referer = '梦果宝盒'; //调用插件的app的名称 const location = JSON.stringify({ latitude: 39.89631551, longitude: 116.323459711 }); const category = '生活服务,娱乐休闲'; wx.navigateTo({ url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}&category=${category}` }); }, picker: function(e) { let value = e.detail.value; if (this.data.selectList.length > 0) { let provice = this.data.selectList[value[0]].name let city = this.data.selectList[value[0]].children[value[1]].name this.setData({ text: provice + " " + city , ["storeInfo.twoType"]: this.data.selectList[value[0]].children[value[1]].id, ["storeInfo.oneType"]: this.data.selectList[value[0]].id }) } }, toArr(object) { let arr = []; for (let i in object) { arr.push(object[i].name); } return arr; }, columnPicker: function(e) { console.log(2) //第几列 下标从0开始 let column = e.detail.column; //第几行 下标从0开始 let value = e.detail.value; if (column === 0) { this.setData({ multiArray: [ this.data.multiArray[0], this.toArr(this.data.selectList[value].children), // this.toArr(this.data.selectList[value].children[0].children) ], value: [value, 0, 0] }) } }, //获取美团品类 getChildListByMtLei(){ util.request(util.api.childListByMtLei, {}, "GET", false, true,app.globalData.token).then((res)=>{ if (res.code == 200) { this.setData({ selectList:res.result, multiArray: [ this.toArr(res.result), this.toArr(res.result[0].children), ] }) }else{ util.toast("获取不到美团品类") } }).catch((res) => {}) }, //配送类型 getDictByCode() { var that = this util.request(util.api.getDictByCode, {code:"peisong_type"}, "GET", false, true,app.globalData.token).then((res) => { if (res.code == 200) { that.setData({ dictList: res.result }) this.bindStore(); } }).catch((res) => {}) }, //选配送类型 bindDictPickerChange: function (e) { var item = this.data.dictList[e.detail.value] this.setData({ ['storeInfo.peisongType']: item.value, ['storeInfo.peisongTypeName']: item.text }) }, })