import Scene from '../../index/scene' import { createInOrder, getPaperList} from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const math = require('../../../utils/math') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { safeBottom: app.globalData.safeBottom, paperList: null, form: { deductType: 1, isWithoutTare: 0 }, paperList: [], imageList: [], focus: 0, visible: false, amout: 0, nowItem: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.showLoading({ title: '正在获取', mask: true }) getPaperList({pageNum: 1, pageSize: 100}).then(result => { this.setData({ safeBottom: app.globalData.safeBottom, paperList: result.data.records }) wx.hideLoading() }).catch(err => { wx.hideLoading() this.setData({ safeBottom: app.globalData.safeBottom }) util.showToast(err) }) }, selectCustomer: function(){ var that = this wx.navigateTo({ url: `/pages/home/customer-list/index?type=1`, events: { onCallback: (data) => { if (data.what == 130) { that.data.form.factoryCustomerId = data.detail.id that.setData({ ['form.factoryCustomerName']: data.detail.name }) } } } }) }, showPlate: function (e) { this.keyboard = this.keyboard || this.selectComponent('#wux-keyboard') this.keyboard.show(this.data.form.plateNumber, 0) }, onPlatenumber: function({detail}){ if(detail && detail.plateNumber){ this.setData({ ['form.plateNumber']: detail.plateNumber }) } }, showCategory: function(){ this.setData({ visible: true }) }, onSelect: function({detail}){ this.data.nowItem = detail if(this.data.form.productId == detail.id){ return } this.data.form.productId = detail.id this.data.form.konePrice = '指导价格:' + detail.defaultUnitPrice this.data.form.unitPrice = '' this.data.form.productName = detail.name if(util.isEmpty(this.data.form.netWeight) || Number(this.data.form.netWeight) <= 0){ this.setData({ form: this.data.form, amout: null }) return } this.statAmount() }, changeDeductType: function(e){ var type = Number(e.currentTarget.dataset.type) this.setData({ ['form.deductType']: type, focus: type }) }, bindInput: function (e) { this.data.form[e.target.id] = e.detail if(e.target.id == 'totalWeight' || e.target.id == 'emptyWeight'){ if(!util.isEmpty(this.data.form.totalWeight) && !util.isEmpty(this.data.form.emptyWeight)){ this.setData({ ['form.netWeight']: math.minus(this.data.form.totalWeight, this.data.form.emptyWeight) }) } } else if(e.target.id == 'deductPercent'){ if(util.isEmpty(e.detail)){ this.data.form.deductWeight = null this.data.form.deductPercent = null } else { this.data.form.deductWeight = math.divide(math.times(this.data.form.netWeight, Number(e.detail)), 100).toFixed(2) } } else if(e.target.id == 'deductWeight'){ if(util.isEmpty(e.detail)){ this.data.form.deductWeight = null this.data.form.deductPercent = null } else { this.data.form.deductPercent = math.times(math.divide(Number(e.detail), this.data.form.netWeight), 100).toFixed(2) } } this.statAmount() }, statAmount: function(){ if(util.isEmpty(this.data.form.netWeight)){ return } this.data.form.settleWeight = this.data.form.netWeight if(!util.isEmpty(this.data.form.deductWeight)){ this.data.form.settleWeight = math.minus(this.data.form.netWeight, this.data.form.deductWeight) } if(!util.isEmpty(this.data.form.settleUnitPrice) && Number(this.data.form.settleUnitPrice) > 0){ this.data.amout = math.times(this.data.form.settleWeight, this.data.form.settleUnitPrice) if(app.userInfo.factory.settlePriceType == 2){ this.data.amout = Math.floor(this.data.amout) } else if(app.userInfo.factory.settlePriceType == 3){ this.data.amout = math.round(this.data.amout, 0) } } else { this.data.amout = null } this.setData({ form: this.data.form, amout: this.data.amout }) }, fileChange: function({detail}){ this.data.imageList = detail.fileList var imageUrls = [] for (let index = 0; index < this.data.imageList.length; index++) { imageUrls.push(this.data.imageList[index].url) } this.data.form.receiptImageList = imageUrls }, checkOrder: function(){ if(util.isEmpty(this.data.form.factoryCustomerId)){ util.showToast('请选择客户') return } if(util.isEmpty(this.data.form.netWeight)){ util.showToast('请输入净重') return } if(Number(this.data.form.netWeight) <= 0){ util.showToast('净重不能小于零') return } if(util.isEmpty(this.data.form.productId) || Number(this.data.form.productId) <= 0){ util.showToast('请选择纸品品类') return } if(util.isEmpty(this.data.form.settleUnitPrice) || Number(this.data.form.settleUnitPrice) <= 0){ util.showToast('请输入单价') return } if(this.data.nowItem){ if(this.data.nowItem.highestUnitPrice && Number(this.data.form.settleUnitPrice) > Number(this.data.nowItem.highestUnitPrice)){ util.showToast('输入单价过高,价格范围:' + this.data.nowItem.lowestUnitPrice + '元/公斤-'+ this.data.nowItem.highestUnitPrice + '元/公斤') return } // if(this.data.nowItem.lowestUnitPrice && Number(this.data.form.unitPrice) < Number(this.data.nowItem.lowestUnitPrice)){ // util.showToast('输入单价过低,价格范围:' + this.data.nowItem.lowestUnitPrice + '元/公斤-'+ this.data.nowItem.highestUnitPrice + '元/公斤') // return // } } if(!util.isEmpty(this.data.form.deductWeight) && Number(this.data.form.deductWeight) >= Number(this.data.form.totalWeight)){ util.showToast('扣重不得超过皮重') return } if(!util.isEmpty(this.data.form.deductPercent) && Number(this.data.form.deductPecent) >= 100){ util.showToast('扣点范围:0-100') return } if(Number(this.data.form.deductWeight) > 0){ this.data.form.deductWeight = Number(this.data.form.deductWeight) } if(Number(this.data.form.deductPercent) > 0){ this.data.form.deductPercent = Number(this.data.form.deductPercent) } wx.showLoading({ title: '处理中', mask: true }) createInOrder(this.data.form).then(result => { wx.hideLoading() event.emit('OrderMessage', { what: 12, desc: 'createInOrder' }) util.showBackToast('订单新增成功') }).catch(err => { wx.hideLoading() util.showToast(err) }) }, viewImage: function (e) { var imgList = [] for (let index = 0; index < this.data.form.totalWeighingPicture.length; index++) { var url = this.data.form.totalWeighingPicture[index].url if(!util.isEmpty(url) && 'error' != url){ imgList.push(url) } } if(imgList.length){ wx.previewImage({ urls: imgList, current: e.currentTarget.dataset.url }) } } })