index.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { accountid, clientType, getErrorMsg, isEncrypted, marketID, protoHeader, timetample, userid } from "../../../../services/utils"
  2. import { hideLoading, showLoading } from "../../../../utils/message/index"
  3. import { encryptBody } from "../../../../utils/websocket/crypto"
  4. import { FunCode } from "../../../../constants/enum/funcode"
  5. import { sendMsgToMQ } from "../../../../services/api/common/index"
  6. import { formatDateString, getDecimalNum } from "../../../../utils/util"
  7. import { queryPermancePlanTmp } from "../../../../services/api/orders/index"
  8. import services from "../../../../services/index"
  9. import Long from "long"
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. navTitle: '预售详情',
  16. /// 底部安全区域
  17. safeBottom: getApp().globalData.safeBottom,
  18. /// 数据信息
  19. item: {},
  20. /// 认购数量
  21. orderQty: '',
  22. /// 选中履约模板
  23. tmp: <GuangZuan.PermancePlanTmp>({}),
  24. /// 颜色
  25. colors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown'],
  26. /// banner图
  27. banners: [''],
  28. /// 是否显示弹出层
  29. show: false
  30. },
  31. /**
  32. * 返回上层视图
  33. */
  34. backToParent() {
  35. /// 返回上层视图
  36. wx.navigateBack()
  37. },
  38. onClose() {
  39. if (!this.data.show) {
  40. return
  41. }
  42. /// 关闭弹出层
  43. this.setData({ show: false })
  44. },
  45. /// 显示弹出层
  46. showPopup() {
  47. if (this.data.show) {
  48. return
  49. }
  50. /// 关闭弹出层
  51. this.setData({ show: true })
  52. },
  53. // input输入中
  54. getInputNum (e: any) {
  55. /// 截取2位小数位
  56. let num = getDecimalNum(e.detail)
  57. this.setData({ orderQty: num})
  58. },
  59. /**
  60. * 立即购买
  61. */
  62. doSubmit() {
  63. /// 关闭弹出窗
  64. this.onClose()
  65. /// showLoading
  66. showLoading(() => {
  67. /// 请求参数
  68. const info = JSON.stringify({
  69. Header: protoHeader(FunCode.GZPresaleOrderReq),
  70. UserID: userid(),
  71. AccountID: accountid(),
  72. WRTradeOrderID: Long.fromNumber(this.data.item.sellwrtradeorderid),
  73. OrderQty: Number(this.data.orderQty),
  74. MarketID: marketID(63),
  75. ClientType: clientType(),
  76. ClientOrderTime: formatDateString(new Date().toString()),
  77. ClientSerialNo: timetample().toString()
  78. })
  79. /// 发送请求
  80. sendMsgToMQ({
  81. data: {
  82. data: encryptBody(info),
  83. funCodeReq: FunCode.GZPresaleOrderReq,
  84. funCodeRsp: FunCode.GZPresaleOrderRsp,
  85. isEncrypted: isEncrypted()
  86. },
  87. success: (res) => {
  88. /// 解析对象
  89. const data = JSON.parse(res.data.data)
  90. if (data.RetCode != 0) {
  91. hideLoading(() => {}, getErrorMsg(data.RetCode))
  92. return
  93. }
  94. /// 求购发布请求成功
  95. hideLoading(() => {
  96. wx.navigateBack()
  97. }, '立即购买申请成功', 'success')
  98. },
  99. fail: (emsg) => {
  100. hideLoading(()=>{}, emsg)
  101. }
  102. })
  103. }, '提交申请中....')
  104. },
  105. /// 获取履约模板信息
  106. queryPermancePlanTmp(performancetemplateid: number) {
  107. /// showLoading
  108. showLoading(() => {
  109. queryPermancePlanTmp({
  110. success: (res) => {
  111. /// 获取数据
  112. this.setData({
  113. tmp: res.data.filter(obj => { return obj.autoid === performancetemplateid })[0]
  114. })
  115. },
  116. complete: () => {
  117. /// hideLoading
  118. hideLoading()
  119. }
  120. })
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面加载
  125. */
  126. onLoad(options: any) {
  127. const obj = JSON.parse(options.item)
  128. /// 解析数据
  129. this.setData({
  130. item: obj,
  131. banners: String(obj.pictureurls).split(',').map(itm => {
  132. return (services.config.openApiUrl+itm).replace('./uploadFile', '/uploadFile')
  133. })
  134. })
  135. /// 查询履约模板
  136. this.queryPermancePlanTmp(obj.performancetemplateid)
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady() {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow() {
  147. },
  148. /**
  149. * 生命周期函数--监听页面隐藏
  150. */
  151. onHide() {
  152. },
  153. /**
  154. * 生命周期函数--监听页面卸载
  155. */
  156. onUnload() {
  157. },
  158. /**
  159. * 页面相关事件处理函数--监听用户下拉动作
  160. */
  161. onPullDownRefresh() {
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom() {
  167. },
  168. /**
  169. * 用户点击右上角分享
  170. */
  171. onShareAppMessage() {
  172. }
  173. })