index.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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, removeMyFavorite, addMyFavotite } from "../../../services/utils"
  7. import { hideLoading, showLoading, showModel, showToast } from "../../../utils/message/index"
  8. import { encryptBody } from "../../../utils/websocket/crypto"
  9. import { formatDateString, getDecimalNum, 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. show: false,
  45. /// 询价价格
  46. orderPrice: '',
  47. /// 备注信息
  48. remark: ''
  49. },
  50. /**
  51. * 返回上层视图
  52. */
  53. backToParent() {
  54. /// 返回上层视图
  55. wx.navigateBack()
  56. },
  57. onClose() {
  58. if (!this.data.show) {
  59. return
  60. }
  61. /// 关闭弹出层
  62. this.setData({ show: false })
  63. },
  64. /// 显示弹出层
  65. showPopup() {
  66. if (this.data.show) {
  67. return
  68. }
  69. /// 关闭弹出层
  70. this.setData({ show: true })
  71. },
  72. // input输入中
  73. getInputNum (e: any) {
  74. /// 截取2位小数位
  75. let num = getDecimalNum(e.detail)
  76. this.setData({ orderPrice: num})
  77. },
  78. /**
  79. * 获取商品数据信息
  80. */
  81. getGoods() {
  82. showLoading(() => {
  83. /// 发送请求
  84. getGoods({
  85. data: {
  86. goodsno: this.data.goodsno
  87. },
  88. success: (res) => {
  89. hideLoading( ()=> {
  90. /// 数据处理
  91. var obj = res.data
  92. obj.imagepath = (services.config.openApiUrl+obj.imagepath).replace('./uploadFile', '/uploadFile')
  93. obj.mobile = isnullstr(res.data.mobile)
  94. obj.zscuttype1display = isnullstr(res.data.zscuttype1display)
  95. this.setData({
  96. goods: obj,
  97. /// 显示单位
  98. unit: obj.zscurrencytypedisplayunit,
  99. /// 克拉单价
  100. priceper: Number(obj.priceper).toFixed(2),
  101. /// 显示价格
  102. price: (obj.zscurrencytype === 1 ? obj.price : obj.price*this.data.exchangerate).toFixed(2),
  103. operator: isMyFavorite(obj.wrtradeorderid) ? 1 : 2
  104. })
  105. /// 查询履约模板信息
  106. this.queryPermancePlanTmp(obj.performancetemplateid)
  107. })
  108. },
  109. fail: (emsg) => {
  110. hideLoading( ()=> {}, emsg)
  111. }
  112. })
  113. })
  114. },
  115. /// 获取履约模板信息
  116. queryPermancePlanTmp(performancetemplateid: number) {
  117. /// showLoading
  118. showLoading(() => {
  119. queryPermancePlanTmp({
  120. success: (res) => {
  121. /// 获取数据
  122. this.setData({
  123. tmps: res.data,
  124. tmp: res.data.filter(obj => { return obj.autoid === performancetemplateid })[0]
  125. })
  126. },
  127. complete: () => {
  128. /// hideLoading
  129. hideLoading()
  130. }
  131. })
  132. })
  133. },
  134. /// 钻石买摘牌接口
  135. doZSBuyOrderDesting() {
  136. /// showModel
  137. showModel(() => {
  138. /// showLoding....
  139. showLoading(() => {
  140. /// 构建参数信息
  141. const info = JSON.stringify({
  142. Header: protoHeader(FunCode.ZSBuyOrderDestingReq, marketID(67)),
  143. UserID: userid(),
  144. AccountID: accountid(),
  145. RelatedWRTradeOrderID: this.data.order.wrtradeorderid ? this.data.order.wrtradeorderid : this.data.goods.wrtradeorderid,
  146. OrderQty: this.data.order.remainqty ? this.data.order.remainqty: this.data.goods.remainqty,
  147. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  148. ClientSerialNo: timetample().toString(),
  149. ClientType: clientType(),
  150. OperatorID: loginid(),
  151. MarketID: marketID(67),
  152. ClientOrderTime: formatDateString(new Date().toString())
  153. })
  154. /// 发送请求
  155. sendMsgToMQ({
  156. data: {
  157. data: encryptBody(info),
  158. funCodeReq: FunCode.ZSBuyOrderDestingReq,
  159. funCodeRsp: FunCode.ZSBuyOrderDestingRsp,
  160. isEncrypted: isEncrypted(),
  161. },
  162. success: (res) => {
  163. /// 请求失败
  164. if (res.code ! = 0) {
  165. hideLoading(() => {}, res.msg)
  166. return
  167. }
  168. /// 解析对象
  169. const data = JSON.parse(res.data.data)
  170. if (data.RetCode != 0) {
  171. hideLoading(() => {}, getErrorMsg(data.RetCode))
  172. return
  173. }
  174. /// 请求成功
  175. hideLoading(() => {
  176. wx.navigateBack()
  177. }, '购买请求成功')
  178. },
  179. fail: (emsg) => {
  180. hideLoading(() => {
  181. showToast('购买操作请求失败,原因:'+emsg)
  182. })
  183. }
  184. })
  185. }, '请求中......')
  186. }, '提示', '确定要购买吗?', true )
  187. },
  188. /// 询价申请
  189. doBargainApply() {
  190. /// showLoding....
  191. showLoading(() => {
  192. /// 构建参数信息
  193. const info = JSON.stringify({
  194. Header: protoHeader(FunCode.ZSBuyOrderDestingNegPriceReq, marketID(67)),
  195. UserID: userid(),
  196. AccountID: accountid(),
  197. RelatedOrderID: this.data.order.wrtradeorderid ? this.data.order.wrtradeorderid : this.data.goods.wrtradeorderid,
  198. OrderQty: this.data.order.remainqty ? this.data.order.remainqty: this.data.goods.remainqty,
  199. ApplyPrice: Number(this.data.orderPrice),
  200. ApplyRemark: this.data.remark,
  201. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  202. ClientSerialNo: timetample().toString(),
  203. ClientType: clientType(),
  204. OperatorID: loginid(),
  205. MarketID: marketID(67),
  206. ClientOrderTime: formatDateString(new Date().toString())
  207. })
  208. /// 发送请求
  209. sendMsgToMQ({
  210. data: {
  211. data: encryptBody(info),
  212. funCodeReq: FunCode.ZSBuyOrderDestingNegPriceReq,
  213. funCodeRsp: FunCode.ZSBuyOrderDestingNegPriceRsp,
  214. isEncrypted: isEncrypted(),
  215. },
  216. success: (res) => {
  217. /// 请求失败
  218. if (res.code ! = 0) {
  219. hideLoading(() => {}, res.msg)
  220. return
  221. }
  222. /// 解析对象
  223. const data = JSON.parse(res.data.data)
  224. if (data.RetCode != 0) {
  225. hideLoading(() => {}, getErrorMsg(data.RetCode))
  226. return
  227. }
  228. /// 请求成功
  229. hideLoading(() => {
  230. wx.navigateBack()
  231. }, '购买请求成功')
  232. },
  233. fail: (emsg) => {
  234. hideLoading(() => {
  235. showToast('购买操作请求失败,原因:'+emsg)
  236. })
  237. }
  238. })
  239. }, '请求中......')
  240. },
  241. /**
  242. * 添加收藏
  243. */
  244. onFavoriteOperator() {
  245. /// loding.....
  246. showLoading(()=>{
  247. /// 委托单号
  248. const wrtradeorderid = this.data.goods.wrtradeorderid
  249. /// 参数信息
  250. const info = JSON.stringify({
  251. UserID: userid(),
  252. OperateType: this.data.operator === 1 ? 2 : 1,
  253. ClientType: clientType(),
  254. MarketID: marketID(67),
  255. ClientSerialNo: timetample().toString(),
  256. WRTradeOrderID: wrtradeorderid,
  257. Header: protoHeader(FunCode.GoodsFavoriteOperateReq, marketID(67))
  258. })
  259. /// 发送请求
  260. sendMsgToMQ({
  261. data: {
  262. data: encryptBody(info),
  263. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  264. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  265. isEncrypted: isEncrypted()
  266. },
  267. success: (res) => {
  268. /// 解析对象
  269. const data = JSON.parse(res.data.data)
  270. if (data.RetCode != 0) {
  271. hideLoading(() => {}, getErrorMsg(data.RetCode))
  272. return
  273. }
  274. hideLoading(()=>{
  275. /// 是否收藏
  276. this.setData({ operator: this.data.operator === 1 ? 2 : 1 })
  277. this.data.operator === 1 ? addMyFavotite(wrtradeorderid) : removeMyFavorite(wrtradeorderid)
  278. })
  279. /// 操作成功
  280. showToast('操作请求成功', 'success', 1000)
  281. },
  282. fail: (emsg) => {
  283. /// 操作失败
  284. hideLoading(()=>{}, emsg)
  285. }
  286. })
  287. })
  288. },
  289. /**
  290. * 生命周期函数--监听页面加载
  291. */
  292. onLoad(options: any) {
  293. /// 商品编号
  294. this.setData({ goodsno: options.goodsno, ordertime: options.ordertime })
  295. /// 是否显示交易
  296. if (options.showTrade) { this.setData({ showTrade: Number(options.showTrade)}) }
  297. /// 获取商品数据
  298. this.getGoods()
  299. /// 单据信息
  300. if (options.item) {
  301. const item = JSON.parse(options.item)
  302. if (item) { this.setData({ order: item }) }
  303. }
  304. },
  305. /// 查看大图
  306. previewImage() {
  307. /// 查看大图
  308. wx.previewImage({
  309. urls: [this.data.goods.imagepath],
  310. current: ''
  311. })
  312. },
  313. /**
  314. * 生命周期函数--监听页面初次渲染完成
  315. */
  316. onReady() {},
  317. /**
  318. * 生命周期函数--监听页面显示
  319. */
  320. onShow() {},
  321. /**
  322. * 生命周期函数--监听页面隐藏
  323. */
  324. onHide() {},
  325. /**
  326. * 生命周期函数--监听页面卸载
  327. */
  328. onUnload() {},
  329. /**
  330. * 页面相关事件处理函数--监听用户下拉动作
  331. */
  332. onPullDownRefresh() {
  333. },
  334. /**
  335. * 页面上拉触底事件的处理函数
  336. */
  337. onReachBottom() {
  338. },
  339. /**
  340. * 用户点击右上角分享
  341. */
  342. onShareAppMessage() {
  343. }
  344. })