index.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import { FunCode } from "../../../constants/enum/funcode"
  2. import { EOrderSrc } from "../../../constants/enum/index"
  3. import { sendMsgToMQ } from "../../../services/api/common/index"
  4. import { getGoods, queryPermancePlanTmp } from "../../../services/api/orders/index"
  5. import { accountid, clientType, getErrorMsg, isEncrypted, loginid, marketid, protoHeader, timetample, userid } from "../../../services/utils"
  6. import { hideLoading, showLoading, showModel, showToast } from "../../../utils/message/index"
  7. import { encryptBody } from "../../../utils/websocket/crypto"
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. /// 底部安全区域
  14. safeBottom: getApp().globalData.safeBottom,
  15. /// 商品信息
  16. goods: <GuangZuan.GetGoods>({}),
  17. /// 商品编号
  18. goodsno: '',
  19. /// 选中履约模板
  20. tmp: <GuangZuan.PermancePlanTmp>({}),
  21. /// 卖单信息
  22. order: <GuangZuan.SellOrder>({}),
  23. /// 颜色
  24. colors: ['rebeccapurple', 'green', 'yellow', 'orange', 'darkgoldenrod'],
  25. /// 操作
  26. operator: 1
  27. },
  28. /**
  29. * 返回上层视图
  30. */
  31. backToParent() {
  32. /// 返回上层视图
  33. wx.navigateBack()
  34. },
  35. /**
  36. * 获取商品数据信息
  37. */
  38. getGoods() {
  39. showLoading(() => {
  40. /// 发送请求
  41. getGoods({
  42. data: {
  43. goodsno: this.data.goodsno
  44. },
  45. success: (res) => {
  46. hideLoading( ()=> {
  47. this.setData({ goods: res.data })
  48. })
  49. },
  50. fail: (emsg) => {
  51. hideLoading( ()=> {}, emsg, 'error')
  52. }
  53. })
  54. })
  55. },
  56. /// 获取履约模板信息
  57. queryPermancePlanTmp() {
  58. /// showLoading
  59. showLoading(() => {
  60. queryPermancePlanTmp({
  61. data: {
  62. marketid: marketid()
  63. },
  64. success: (res) => {
  65. /// 获取数据
  66. this.setData({
  67. tmps: res.data,
  68. tmp: res.data[0],
  69. actions: res.data.map(obj => { return obj.templatename })
  70. })
  71. },
  72. complete: () => {
  73. /// hideLoading
  74. hideLoading()
  75. }
  76. })
  77. })
  78. },
  79. /// 钻石买摘牌接口
  80. doZSBuyOrderDesting() {
  81. /// showModel
  82. showModel(() => {
  83. /// showLoding....
  84. showLoading(() => {
  85. /// 构建参数信息
  86. const info = JSON.stringify({
  87. Header: protoHeader(FunCode.ZSBuyOrderDestingReq),
  88. UserID: userid(),
  89. AccountID: accountid(),
  90. RelatedWRTradeOrderID: this.data.order.wrtradeorderid,
  91. OrderQty: this.data.order.remainqty,
  92. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  93. ClientSerialNo: timetample().toString(),
  94. ClientType: clientType(),
  95. OperatorID: loginid(),
  96. MarketID: marketid()
  97. })
  98. /// 发送请求
  99. sendMsgToMQ({
  100. data: {
  101. data: encryptBody(info),
  102. funCodeReq: FunCode.ZSBuyOrderDestingReq,
  103. funCodeRsp: FunCode.ZSBuyOrderDestingRsp,
  104. isEncrypted: isEncrypted(),
  105. },
  106. success: (res) => {
  107. /// 请求失败
  108. if (res.code ! = 0) {
  109. hideLoading(() => {}, res.msg, 'error')
  110. return
  111. }
  112. /// 解析对象
  113. const data = JSON.parse(res.data.data)
  114. if (data.RetCode != 0) {
  115. hideLoading(() => {}, getErrorMsg(data.RetCode), 'error')
  116. return
  117. }
  118. /// 请求成功
  119. hideLoading(() => {
  120. wx.navigateBack()
  121. }, '购买请求成功')
  122. },
  123. fail: (emsg) => {
  124. hideLoading(() => {
  125. showToast('购买操作请求失败,原因:'+emsg)
  126. })
  127. }
  128. })
  129. }, '请求中......')
  130. }, '提示', '确定要购买吗?', true)
  131. },
  132. /**
  133. * 添加收藏
  134. */
  135. onFavoriteOperator() {
  136. /// loding.....
  137. showLoading(()=>{
  138. /// 委托单号
  139. const wrtradeorderid = this.data.goods.wrtradeorderid
  140. /// 参数信息
  141. const info = JSON.stringify({
  142. UserID: userid(),
  143. OperateType: this.data.operator === 1 ? 2 : 1,
  144. ClientType: clientType(),
  145. MarketID: marketid(),
  146. ClientSerialNo: timetample().toString(),
  147. WRTradeOrderID: wrtradeorderid,
  148. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  149. })
  150. /// 发送请求
  151. sendMsgToMQ({
  152. data: {
  153. data: encryptBody(info),
  154. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  155. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  156. isEncrypted: isEncrypted()
  157. },
  158. success: (res) => {
  159. /// 解析对象
  160. const data = JSON.parse(res.data.data)
  161. if (data.RetCode != 0) {
  162. hideLoading(() => {}, getErrorMsg(data.RetCode), 'error')
  163. return
  164. }
  165. /// 操作成功
  166. hideLoading(()=>{
  167. /// 是否收藏
  168. this.setData({ operator: this.data.operator === 1 ? 2 : 1 })
  169. }, '请求成功', 'success')
  170. },
  171. fail: (emsg) => {
  172. /// 操作失败
  173. hideLoading(()=>{}, emsg, 'error')
  174. }
  175. })
  176. })
  177. },
  178. /**
  179. * 生命周期函数--监听页面加载
  180. */
  181. onLoad(options: any) {
  182. /// 单据信息
  183. const item = JSON.parse(options.item)
  184. if (item) {
  185. this.setData({ order: item })
  186. }
  187. /// 商品编号
  188. this.setData({ goodsno: options.goodsno })
  189. /// 获取商品数据
  190. this.getGoods()
  191. /// 查询履约模板信息
  192. this.queryPermancePlanTmp()
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady() {},
  198. /**
  199. * 生命周期函数--监听页面显示
  200. */
  201. onShow() {},
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide() {},
  206. /**
  207. * 生命周期函数--监听页面卸载
  208. */
  209. onUnload() {},
  210. /**
  211. * 页面相关事件处理函数--监听用户下拉动作
  212. */
  213. onPullDownRefresh() {
  214. },
  215. /**
  216. * 页面上拉触底事件的处理函数
  217. */
  218. onReachBottom() {
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage() {
  224. }
  225. })