import { queryPermancePlanTmp } from "../../../../services/api/orders/index" import { accountid, clientType, getErrorMsg, isEncrypted, marketid, protoHeader, timetample, userid } from "../../../../services/utils" import { hideLoading, showLoading, showModel, showToast } from "../../../../utils/message/index" import services from "../../../../services/index" import { formatDate, getDecimalNum } from "../../../../utils/util" import { FunCode } from "../../../../constants/enum/funcode" import { sendMsgToMQ } from "../../../../services/api/common/index" import { encryptBody } from "../../../../utils/websocket/crypto" Page({ /** * 页面的初始数据 */ data: { /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// 履约模板信息 tmps: [], /// 选中履约模板 tmp: ({}), /// 是否显示 show: false, /// 是否显示日历 showCal: false, /// 颜色 tcolors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown'], /// 是否开始日期 isstart: true, /// 开始日期 startdate: formatDate(new Date()), /// 结束日期 enddate: formatDate(new Date()), /// 文件上传列表 fileList: [], /// 上传的文件路径 filePath: '', /// 商品名称 wrstandname: '', /// 预售总量 pretotalqty: '0.0', /// 最小采购单位 minbuyqty: '0.0', /// 最大采购单位 maxbuyqty: '0.0', /// 最低成团量 minsuccessqty: '0.0', /// 采购保证金比例 buymarginvalue: '0.0', /// 形状 zsshape: '', /// 颜色 zscolor: '', /// 净度 zsclarity: '', /// 尺寸 zssize: '', /// 抛光 zspolish: '', /// 对称 zssymmetry: '', /// 切工 zscut: '', /// 荧光 zsfluorescence: '', /// 备注 remark: '', /// 钻石分类 categorys: [{ text: '单颗裸钻', value: 2 }, { text: '单颗彩钻', value: 5 }], category: 2, /// 列头 columns: ['序号', '数量 >=', '价格/(元/克拉)', '操作'], /// 显示信息 actions: [''], /// 数据信息 datas: [{ price: 0.0, qty: 0.0, step: 1 }] }, /** * 返回上层视图 */ backToParent() { /// 返回上层视图 wx.navigateBack() }, /** * 按钮点击响应事件 */ onButtonClick(e: any) { switch (e.target.id) { case 'startdate': /// 开始日期 this.setData({ showCal: true, isstart: true }) break; case 'enddate': /// 结束日期 this.setData({ showCal: true, isstart: false }) break case 'submit': /// 申请提交 this.doSubmit() break default: break; } }, check(): boolean { /// 请输入商品名称 if (this.data.wrstandname === '') { showToast('请输入商品名称') return false } /// 请输入预售总量 if ((this.data.pretotalqty === '') || (Number(this.data.pretotalqty) === 0.0) ) { showToast('请输入预售总量') return false } /// 请输入最小采购单位 if ((this.data.minbuyqty === '') || (Number(this.data.minbuyqty) === 0.0) ) { showToast('请输入最小采购单位') return false } /// 请输入最大采购单位 if ((this.data.maxbuyqty === '') || (Number(this.data.maxbuyqty) === 0.0) ) { showToast('请输入最大采购单位') return false } /// 请输入最低成团量 if ((this.data.minsuccessqty === '') || (Number(this.data.minsuccessqty) === 0.0) ) { showToast('请输入最低成团量') return false } /// 请输入采购保证金比例 if ((this.data.buymarginvalue === '') || (Number(this.data.buymarginvalue) === 0.0) ) { showToast('请输入采购保证金比例') return false } return true }, /// 日期确定触发 onConfirm(e: any) { this.setData({ showCal: false }) /// 开始日期 if (this.data.isstart) { this.setData({ startdate: formatDate(e.detail) }) } else { this.setData({ enddate: formatDate(e.detail) }) } }, /// 日期关闭触发 onCloseCal() { this.setData({ showCal: false }) }, /// 显示履约模板 showPlanTmps() { this.setData({ show: true }) }, /// 关闭 onClose() { this.setData({ show: false }) }, onSelect(e: any) { /// 默认显示项 const { index } = e.detail; this.setData({ tmp: this.data.tmps[index], show: false }) }, /// 删除图片 deleteImage(e: any) { const {index} = e.detail.index // 上传完成需要更新 fileList const { fileList = [] } = this.data; fileList.splice(index, 1) this.setData({ fileList }); }, onChange(e: any) { this.setData({ category: e.detail }); }, /// 照片上传 afterRead(e: any) { const { file } = e.detail; // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式 wx.uploadFile({ url: services.config.uploadUrl, filePath: file.url, name: 'file', formData: { user: 'test' }, success: (res) => { if (res.statusCode != 200) { showToast('图片上传失败,原因:'+res.errMsg) return } // 上传完成需要更新 fileList const { fileList = [] } = this.data; fileList.push({ ...file, url: res.data}); this.setData({ fileList }); /// 设置文件路径 this.setData({ filePath: JSON.parse(res.data)[0].filePath }) }, }); }, // input输入中 getInputNum (e: any) { /// 截取两位小数位 let num = getDecimalNum(e.detail) switch (e.target.id) { case 'maxbuyqty': /// 最大采购单位 this.setData({ maxbuyqty: num}) break; case 'pretotalqty': /// 预售总量 this.setData({ pretotalqty: num}) break; case 'buymarginvalue': /// 采购保证金 this.setData({ buymarginvalue: num}) break; case 'minbuyqty': /// 最小采购单位 this.setData({ minbuyqty: num}) break; case 'minsuccessqty': /// 最低成团量 this.setData({ minsuccessqty: num}) break; default: break; } }, /// 申请提交 doSubmit() { /// 校验不合规 if (!this.check()) { return } /// showModel showModel(() => { /// showLoading showLoading(() => { /// 钻石属性 var list = this.data.datas.map(obj => { return { StepIndex: obj.step, Qty: Number(obj.qty), Price: Number(obj.price) } }) /// 请求参数 const info = JSON.stringify({ Header: protoHeader(FunCode.GZCenterPurchaseApplyReq), SellUserID: userid(), SellAccountID: accountid(), WRStandardName: this.data.wrstandname, PresaleQty: Number(this.data.pretotalqty), MinBuyQty: Number(this.data.minbuyqty), MaxBuyQty: Number(this.data.maxbuyqty), MinSuccessQty: Number(this.data.minsuccessqty), StartDate: this.data.startdate, EndDate: this.data.enddate, BuyMarginAlgorithm: 1, BuyMarginValue: this.data.buymarginvalue, PerformanceTemplateID: this.data.tmp.autoid, YSZSCategory: this.data.category, ZSShapeTypeStr: this.data.zsshape, ZSColorTypeStr: this.data.zscolor, ZSClarityTypeStr: this.data.zsclarity, ZSCutTypeStr: this.data.zscut, ZSSymmetryTypeStr: this.data.zssymmetry, ZSPolishTypeStr: this.data.zspolish, ZSFluorescenceTypeStr: this.data.zsfluorescence, SizeStr: this.data.zssize, PictureUrls: this.data.filePath, Remark: this.data.remark, GZCenterPurchasePriceLists: list, MarketID: marketid(), ClientType: clientType(), ClientSerialNo: timetample().toString() }) /// 发送请求 sendMsgToMQ({ data: { data: encryptBody(info), funCodeReq: FunCode.GZCenterPurchaseApplyReq, funCodeRsp: FunCode.GZCenterPurchaseApplyRsp, isEncrypted: isEncrypted() }, success: (res) => { /// 解析对象 const data = JSON.parse(res.data.data) if (data.RetCode != 0) { hideLoading(() => {}, getErrorMsg(data.RetCode)) return } /// 求购发布请求成功 hideLoading(() => { wx.navigateBack() }, '提交申请成功', 'success') }, fail: (emsg) => { hideLoading(()=>{}, emsg) } }) }, '提交申请请求中....') }, '提示', '确认要提交申请吗?') }, /// 获取履约模板信息 queryPermancePlanTmp() { /// showLoading showLoading(() => { queryPermancePlanTmp({ // data: { // marketid: marketid() // }, success: (res) => { /// 获取数据 this.setData({ tmps: res.data, tmp: res.data[0], actions: res.data.map(obj => { return obj.templatename }) }) }, complete: () => { /// hideLoading hideLoading() } }) }) }, /** * 新增价格 */ addPrice() { this.setData({ datas: this.data.datas.concat([{price: 0.0, qty: 0.0, step: this.data.datas.length+1}]) }) }, /** * 删除某一行 */ deleteRow(e: any) { const row = e.target.id var obj = this.data.datas[row-1] if (obj.qty === 0.0 && row === '1') { showToast('第一条数据信息不能删除') return } /// 删除数据 this.data.datas.splice(row-1, 1) this.setData({ datas: this.data.datas }) }, /** * 数据变化 */ onRowChanged(e: any) { /// 获取对应的id const ids = ( e.target.id).split(' ') const row = ids[0] const id = ids[1] var obj = this.data.datas[row-1] /// 截取两位小数 let num = getDecimalNum(e.detail) /// 数据赋值 if (id === "qty") { obj.qty = num } else { obj.price = num } /// 删除数据 this.data.datas.splice(row-1, 1) this.data.datas.splice(row-1, 0, obj) this.setData({ datas: this.data.datas }) }, /** * 数据变化重新排序 */ onRowSort() { /// 数据排序 this.setData({ datas: this.data.datas.sort(function(a, b) { if (a.qty > b.qty) { return 1; } if (a.qty < b.qty) { return -1; } return 0; }) }) }, /** * 生命周期函数--监听页面加载 */ onLoad() { /// 获取履约模板信息 this.queryPermancePlanTmp() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })