// pages/order/confirmOreder/confirmOreder.js const app = getApp(); const addr = require('../../my/address/addSite/addSite.js'); Page({ /** * 页面的初始数据 */ data: { currentList: [{ tit: '塑封包膜', num: "30", id: 1 }, { tit: '绒面鞋补色', num: "20", id: 2 }, { tit: '防水处理', num: "20", id: 3 }, { tit: '防水处理', num: "10", id: 4 }], mode: 1, checked: true, show1: false, show2: false, code: "", order_no: "", orderinfo: "", address: "", useraddr: "", remark: "", address_id:0, freight:0, total_price:0, }, onLoad(opticon) { let order_no = opticon.order_no; let currentList = this.data.currentList currentList.map(item => { item.active = false }) this.detail(order_no); this.setData({ currentList, order_no }) }, //详情 detail(order) { var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/order_detail", { order_no: order, }, "get").then(function (res) { if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 2000); } else { var unit=res.message.data.network.unit[res.message.data.network.unit.length-1]; var total_price=parseFloat(res.message.data.total_price); var price=parseFloat(unit.price); that.setData({ orderinfo: res.message.data, address: res.message.address.address, code: res.message.address.phone, name: res.message.address.username, address_id:res.message.address.id, useraddr: res.message.address, mode:unit.type, order_type:unit.type, freight:unit.price, total_price:(total_price+price).toFixed(2) }) } }).catch(function (err) { console.log(err); }) }, changeClose1(e) { this.setData({ show1: !this.data.show1 }) }, changeClose2(e) { // console.log(e) this.setData({ show2: !this.data.show2, remark: this.data.remark }) }, onChange(event) { console.log(event); this.setData({ checked: event.detail, }); }, chios(e) { let { item } = e.currentTarget.dataset let currentList = this.data.currentList currentList.map((it, index) => { if (item.id == it.id) { it.active = !it.active } }) this.setData({ currentList }) }, changeMode(e) { var id = e.currentTarget.dataset.id var key=e.currentTarget.dataset.indx; var unit=this.data.orderinfo.network.unit[key]; var total_price=parseFloat(this.data.orderinfo.total_price); var price=parseFloat(unit.price) this.setData({ mode: id, freight:unit.price, total_price:total_price+price }) }, goto() { if(!this.data.checked){ wx.showLoading({ title: '请阅读并同意洗护协议', }) setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 1000); }else{this.orderConfirm();} }, getPhoneNumber(e) { app.login(); console.log(e) var data = { 'mds': wx.getStorageSync('seisson_key'), 'encryptedData': e.detail.encryptedData, 'errMsg': e.detail.errMsg, 'iv': e.detail.iv, 'appid': wx.getAppBaseInfo().host.appId, } app.api.useApi(app.globalData.baseAppUrl+"api/user/getPhoneNumber",data,"post").then((res)=>{ if (res.code == 200) { var phone = res.message.data.phone console.log(phone); if (phone) { this.setData({ code: phone, }) } } }).catch((err)=>{ console.log(err) }) // console.log("fetch cloudfunction success", cloudResult.result) }, input1(e) { console.log(e.detail); this.setData({ name: e.detail.value }) }, input2(e) { this.setData({ code: e.detail.value }) }, input3(e) { this.setData({ address: e.detail.value }) }, input4(e) { this.setData({ remark: e.detail.value }) }, addAddress() { var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/address/create", { username: that.data.name, phone: that.data.code, address: that.data.address, }, "post").then(function (res) { if (res.code != 200) { wx.showLoading({ title: res.original.message.msg, }) setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 1000); } else { that.changeClose1(); that.setData({ address_id: res.message.data.address.id, }) } }).catch(function (err) { console.log(err); }) }, updateaddr(e) { var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/address/update", { username: that.data.name, phone: that.data.code, address: that.data.address, id: e.target.dataset.id, }, "post").then(function (res) { if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) } else { that.changeClose1(); // wx.navigateTo({ // url: '/pages/my/address/address', // }) } setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 2000); }).catch(function (err) { console.log(err.message); }) }, orderConfirm() { var that=this; app.api.useApi(app.globalData.baseAppUrl + "api/orders", { order_no: that.data.order_no, order_type: that.data.mode, user_remark: that.data.remark, address_id:that.data.address_id }, "post").then(function (res) { console.log(res) if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading({ success: (res) => { }, }) }, 1000); } else { wx.navigateTo({ url: '/pages/my/cashier/cashier?order_no='+that.data.order_no }) } }).catch(function (err) { // console.log(222); console.log(err) }) }, })