const cityData = require('../../utils/picker.city.all.js') const util = require('../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { selectList: cityData, //接口返回picker数据,此处就直接使用本地测试数据 multiArray: [], //picker数据 values:{ receiver:'', receiverPhone:'', receiverArea:'', recevierAddress:'', storeId:'', productOrderDetailList:[] }, area: [0, 0, 0], totalPrice:0, region: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.values.storeId = options.storeId if(options && options.strJson){ var list = JSON.parse(decodeURIComponent(options.strJson)) var totalPrice = 0 list.forEach((e)=>{ totalPrice += e.productPrice * e.productNum }) this.setData({ totalPrice: totalPrice, ["values.productOrderDetailList"]: list }) } this.setData({ multiArray: [ this.toArr(this.data.selectList), this.toArr(this.data.selectList[0].children), this.toArr(this.data.selectList[0].children[0].children) ] }) }, picker: function(e) { let value = e.detail.value; if (this.data.selectList.length > 0) { let provice = this.data.selectList[value[0]].text let city = this.data.selectList[value[0]].children[value[1]].text let district = this.data.selectList[value[0]].children[value[1]].children[value[2]].text this.setData({ ["values.receiverArea"]: provice + " " + city + " " + district, id: this.data.selectList[value[0]].children[value[1]].children[value[2]].value }) } }, toArr(object) { let arr = []; for (let i in object) { arr.push(object[i].text); } return arr; }, columnPicker: function(e) { //第几列 下标从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) ], area: [value, 0, 0] }) } else if (column === 1) { this.setData({ multiArray: [ this.data.multiArray[0], this.data.multiArray[1], this.toArr(this.data.selectList[this.data.value[0]].children[value].children) ], area: [this.data.value[0], value, 0] }) } }, productNumChange(e){ let that = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; var list = that.data.values.productOrderDetailList var index = dataset.index; var itemProduct = dataset.item itemProduct.productNum = value list.splice(index,1,itemProduct) that.setData({ ["values.productOrderDetailList"]:list }) var list = this.data.values.productOrderDetailList.filter((e)=>e.productNum > 0) var totalPrice = 0 list.forEach((e)=>{ totalPrice += e.productPrice * e.productNum }) this.setData({ totalPrice: totalPrice }) }, bindRegionChange: function (e) { console.log(e.detail.value) console.log(e.detail.code) this.setData({ region: e.detail.value }) this.data.values.receiverArea = this.data.region.join(" ") }, submitPay(){ var that = this var list = that.data.values.productOrderDetailList.filter((e)=>e.productNum > 0) if(list.length < 1){ util.toast('请选择下单商品,并且订货数量必须大于0') return } var that = this // util.request(util.api.generateOrder, {openId:app.globalData.openId,deviceId:app.globalData.deviceId,gridNum:that.data.productGrid}, "POST", true, true,app.globalData.token).then((res)=>{ // if (res.code == 200) { // wx.requestPayment({ // 'timeStamp': res.result.result.timeStamp + '', // 'nonceStr': res.result.result.nonceStr, // 'package': res.result.result.packageValue, // 'signType': 'MD5', // 'paySign': res.result.result.paySign, // 'success': function (res) { // that.openGrate(1) // wx.redirectTo({ // url: 'success' // }) // }, // 'fail': function (res) { // } // }) // }else if(res.code == 500){ // util.toast(res.message) // } // }) // }, util.request(util.api.addMerchantOrder, that.data.values, "POST", false, true, app.globalData.token).then((res) => { if (res.code == 200) { wx.requestPayment({ 'timeStamp': res.result.result.timeStamp + '', 'nonceStr': res.result.result.nonceStr, 'package': res.result.result.packageValue, 'signType': 'MD5', 'paySign': res.result.result.paySign, 'success': function (res) { wx.redirectTo({ url: 'success' }) }, 'fail': function (res) { } }) }else if(res.code == 500){ util.toast(res.message) } // if (res.code == 200) { // util.toast("下单成功") // wx.redirectTo({ // url: '/pages/orderGoods/order', // }) // } }).catch((res) => {}) }, inputedit: function (e) { let _this = this; let dataset = e.currentTarget.dataset; let value = e.detail.value; let name = dataset.name; if (dataset.type && dataset.type == 'float') { _this.data[name] = parseFloat(value * 100); } else { _this.data[name] = value; } _this.setData({ [name]: _this.data[name] }); } })