var _request = require('../../../../utils/request.js') var validator = require('../../../../utils/validator.js') var rid var fomlds = [] Page({ data: { order: {}, company: '', express: '', company1: '', express1: '', company2: '', express2: '', secondshow: false, thirdshow: false, }, bindCompany (e) { this.setData({ company: e.detail.value }) }, bindExpress (e) { this.setData({ express: e.detail.value }) }, bindCompany1 (e) { this.setData({ company1: e.detail.value }) }, bindExpress1 (e) { this.setData({ express1: e.detail.value }) }, bindCompany2 (e) { this.setData({ company2: e.detail.value }) }, bindExpress2 (e) { this.setData({ express2: e.detail.value }) }, onLoad: function (options) { rid = options.id this.getRadish() }, onHide: function (val) { this.sendFomlds() }, getRadish () { var that = this var url = 'v1/merchant/order/detail/' + rid var params = { } var success = function (res) { var data = res.data that.setData({ order: data }) if (that.data.order.ex_company_array.length === 1 && that.data.order.ex_order_no_array.length === 1) { that.setData({ company: data.ex_company_array[0], express: data.ex_order_no_array[0] }) } else if (that.data.order.ex_company_array.length === 2 && that.data.order.ex_order_no_array.length === 2) { that.setData({ secondshow: true, company: data.ex_company_array[0], express: data.ex_order_no_array[0], company1: data.ex_company_array[1], express1: data.ex_order_no_array[1] }) } else if (that.data.order.ex_company_array.length === 3 && that.data.order.ex_order_no_array.length === 3) { that.setData({ secondshow: true, thirdshow: true, company: data.ex_company_array[0], express: data.ex_order_no_array[0], company1: data.ex_company_array[1], express1: data.ex_order_no_array[1], company2: data.ex_company_array[2], express2: data.ex_order_no_array[2], }) } else if (getApp().globalData.merchant) { that.setData({ company: getApp().globalData.merchant }) } } _request.$get(url, params, success) }, setExpressRequest: function () { var id = this.data.order.order_id var that = this var url = 'v1/merchant/order/' + id var company = that.data.company var express = that.data.express if (that.data.secondshow === true) { company = that.data.company + '/' + that.data.company1 express = that.data.express + '/' + that.data.express1 } if (that.data.thirdshow === true) { company = that.data.company + '/' + that.data.company1 + '/' + that.data.company2 express = that.data.express + '/' + that.data.express1 + '/' + that.data.express2 } var params = { express_company: company, express_order_no: express, status: 'dispatch' } var success = function (res) { getApp().globalData.order = true getApp().globalData.merchant = that.data.company wx.navigateBack() } _request.$put(url, params, success) }, putExpressRequest: function () { var id = this.data.order.order_id var that = this var url = 'v1/merchant/order/' + id var company = that.data.company var express = that.data.express if (that.data.secondshow === true) { company = that.data.company + '/' + that.data.company1 express = that.data.express + '/' + that.data.express1 } if (that.data.thirdshow === true) { company = that.data.company + '/' + that.data.company1 + '/' + that.data.company2 express = that.data.express + '/' + that.data.express1 + '/' + that.data.express2 } var params = { express_company: company, express_order_no: express } var success = function (res) { getApp().globalData.order = true getApp().globalData.merchant = that.data.company wx.navigateBack() } _request.$put(url, params, success) }, jstext (val) { var strshow = val.indexOf('/') if (strshow >= 0) { return false } if (strshow < 0) { return true } }, validate () { var msg if (!validator.required(this.data.company)) { msg = '物流公司不能为空' } else if (!validator.required(this.data.express)) { msg = '物流号不能为空' } else if (!this.jstext(this.data.company) || !this.jstext(this.data.express)) { msg = '请不要输入"/"等特殊字符' } else if (this.data.secondshow === true && !validator.required(this.data.company1)) { msg = '物流公司不能为空' } else if (this.data.secondshow === true && !validator.required(this.data.express1)) { msg = '物流号不能为空' } else if (this.data.secondshow === true && (!this.jstext(this.data.company1) || !this.jstext(this.data.express1))) { msg = '请不要输入"/"等特殊字符' } else if (this.data.thirdshow === true && !validator.required(this.data.company2)) { msg = '物流公司不能为空' } else if (this.data.thirdshow === true && !validator.required(this.data.express2)) { msg = '物流号不能为空' } else if (this.data.secondshow === true && (!this.jstext(this.data.company2) || !this.jstext(this.data.express2))) { msg = '请不要输入"/"等特殊字符' } return { isOk: !msg, msg } }, setExpress: function (e) { this.formSubmit(e) var { isOk, msg } = this.validate() if (isOk) { this.setExpressRequest() } else { wx.showToast({ title: msg, icon: 'none', duration: 2000 }) } }, putExpress: function (e) { this.formSubmit(e) var { isOk, msg } = this.validate() if (isOk) { this.putExpressRequest() } else { wx.showToast({ title: msg, icon: 'none', duration: 2000 }) } }, getqcode: function () { var that = this wx.scanCode({ success: (res) => { that.setData({ express: res.result }) } }) }, getqcode1: function () { var that = this wx.scanCode({ success: (res) => { that.setData({ express1: res.result }) } }) }, getqcode2: function () { var that = this wx.scanCode({ success: (res) => { that.setData({ express2: res.result }) } }) }, formSubmit: function (e) { fomlds = e.detail.formId this.sendFomlds() }, sendFomlds: function () { var that = this var url = 'v1/formid' var params = { formIds: fomlds } var success = function (res) { console.log(res) } _request.$post(url, params, success) }, pluslist () { var that = this if (that.data.secondshow === false) { that.setData({ secondshow: true }) } else { that.setData({ thirdshow: true }) } }, miuslist () { var that = this if (that.data.secondshow === true && that.data.thirdshow === false) { that.setData({ secondshow: false, express1: '', company1: '', }) } else if (that.data.secondshow === true && that.data.thirdshow === true) { that.setData({ thirdshow: false, express2: '', company2: '', }) } } })