import { accountid, clientType, getErrorMsg, isEncrypted, marketID, protoHeader, timetample, userid } from "../../../../services/utils" import { hideLoading, showLoading, showToast } from "../../../../utils/message/index" import { encryptBody } from "../../../../utils/websocket/crypto" import { FunCode } from "../../../../constants/enum/funcode" import { sendMsgToMQ } from "../../../../services/api/common/index" import { formatDateString, getDecimalNum } from "../../../../utils/util" import { queryGZMyPresell, queryPermancePlanTmp } from "../../../../services/api/orders/index" import services from "../../../../services/index" Page({ /** * 页面的初始数据 */ data: { navTitle: '集采详情', /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// 数据信息 item: {}, /// 认购数量 orderQty: '', /// 选中履约模板 tmp: ({}), /// 颜色 colors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown'], /// banner图 banners: [''], /// 预售认购列表查询 sells: [], /// 是否显示弹出层 show: false }, /** * 返回上层视图 */ backToParent() { /// 返回上层视图 wx.navigateBack() }, /// 我的预售认购列表查询 queryGZMyPresell(presaleapplyid: number) { /// showLoading showLoading(() => { queryGZMyPresell({ data: { presaleapplyid: presaleapplyid }, success: (res) => { /// 获取数据 this.setData({ sells: res.data }) }, complete: () => { /// hideLoading hideLoading() } }) }) }, onClose() { if (!this.data.show) { return } /// 关闭弹出层 this.setData({ show: false }) }, /// 显示弹出层 showPopup() { if (this.data.show) { return } /// 关闭弹出层 this.setData({ show: true }) }, // input输入中 getInputNum (e: any) { /// 截取2位小数位 let num = getDecimalNum(e.detail) this.setData({ orderQty: num}) }, /** * 立即购买 */ doSubmit() { /// 关闭弹出窗 this.onClose() /// 合规性校验 if (!this.check()) { return } /// showLoading showLoading(() => { /// 请求参数 const info = JSON.stringify({ Header: protoHeader(FunCode.GZCenterPurchaseOrderReq, marketID(62)), UserID: userid(), AccountID: accountid(), WRTradeOrderID: this.data.item.sellwrtradeorderid.toString(), OrderQty: Number(this.data.orderQty), MarketID: marketID(62), ClientType: clientType(), ClientOrderTime: formatDateString(new Date().toString()), ClientSerialNo: timetample().toString() }) /// 发送请求 sendMsgToMQ({ data: { data: encryptBody(info), funCodeReq: FunCode.GZCenterPurchaseOrderReq, funCodeRsp: FunCode.GZCenterPurchaseOrderRsp, 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(performancetemplateid: number) { /// showLoading showLoading(() => { queryPermancePlanTmp({ success: (res) => { /// 获取数据 this.setData({ tmp: res.data.filter(obj => { return obj.autoid === performancetemplateid })[0] }) }, complete: () => { /// hideLoading hideLoading() } }) }) }, /// 合规性校验 check(): Boolean { if (Number(this.data.orderQty) === 0.0 || this.data.orderQty === '') { showToast('请输入采购数量。') return false } const { maxbuyqty, minbuyqty } = this.data.item if (Number(this.data.orderQty)>maxbuyqty || Number(this.data.orderQty) { return (services.config.openApiUrl+itm).replace('./uploadFile', '/uploadFile') }) }) // 查询履约模板 this.queryPermancePlanTmp(obj.performancetemplateid) /// 我的预售认购列表查询 this.queryGZMyPresell(obj.presaleapplyid) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })