index.ts 7.8 KB

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