circle.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { queryMyFavorite } from "../../services/api/orders/index"
  2. import Toast from '@vant/weapp/toast/toast';
  3. import { clientType, isEncrypted, marketid, protoHeader, userid, timetample } from "../../services/utils";
  4. import { sendMsgToMQ } from "../../services/api/common/index";
  5. import { FunCode } from "../../constants/enum/funcode";
  6. // pages/circle/circle.ts
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. /// 底部安全区域
  13. safeBottom: getApp().globalData.safeBottom,
  14. /// 窗口高度
  15. windowHeight: getApp().globalData.windowHeight,
  16. /// tabs
  17. tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}],
  18. /// tab索引
  19. active: 0,
  20. /// 列头
  21. titles: [['重量', '形状', '尺寸', '编号'],
  22. ['颜色', '净度', '切工', '对称', '抛光', '荧光', '证书', '价格']],
  23. /// 我的收藏
  24. favorites: <GuangZuan.MyFavorite[]>[],
  25. /// 是否空数据
  26. isEmpty: true
  27. },
  28. /**
  29. * tab触发事件
  30. */
  31. onTabChange(e: any) {
  32. this.setData({ active: e.detail.index })
  33. /// 查询数据
  34. this.queryMyFavorite()
  35. },
  36. /**
  37. * tab触发事件
  38. */
  39. onCancelFavorite(e: any) {
  40. /// loding.....
  41. Toast.loading({ message: '请求中.....'})
  42. const wrtradeorderid = this.data.favorites[e.target.id].wrtradeorderid
  43. /// 参数信息
  44. const info = {
  45. UserID: userid(),
  46. OperateType: 2,
  47. ClientType: clientType(),
  48. MarketID: marketid(),
  49. ClientSerialNo: timetample().toString(),
  50. WRTradeOrderID: wrtradeorderid,
  51. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  52. }
  53. /// 发送请求
  54. sendMsgToMQ({
  55. data: {
  56. data: JSON.stringify(info),
  57. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  58. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  59. isEncrypted: isEncrypted()
  60. },
  61. success: (res) => {
  62. /// 操作失败
  63. if (res.code != 0) {
  64. Toast.fail({message: '请求失败,原因:'+res.msg})
  65. return
  66. }
  67. console.log(res)
  68. /// 操作成功
  69. Toast.success({message: '请求成功'})
  70. /// 更新数据
  71. this.queryMyFavorite()
  72. },
  73. fail: (emsg) => {
  74. /// 操作失败
  75. Toast.fail({ message: '请求失败,原因:'+emsg})
  76. }, complete: () => {}
  77. })
  78. },
  79. /// 查询我的收藏数据信息
  80. queryMyFavorite() {
  81. /// loding.....
  82. Toast.loading({message: '加载中...'});
  83. /// 发送查询
  84. queryMyFavorite({
  85. data: {
  86. userid: userid(),
  87. zscategorys: this.data.active == 0 ? '2' : '5'
  88. },
  89. /// 加载成功
  90. success: (res) => {
  91. if (res.code != 200) {
  92. /// 加载失败
  93. Toast.fail({ message: '加载失败...'});
  94. return
  95. }
  96. /// 数据赋值
  97. this.setData({
  98. favorites: res.data,
  99. isEmpty: res.data.length == 0
  100. })
  101. },
  102. fail: (emsg) => {
  103. /// 加载失败
  104. Toast.fail({ message: '加载失败...'+emsg});
  105. },
  106. complete: () => {}
  107. })
  108. },
  109. /**
  110. * 生命周期函数--监听页面加载
  111. */
  112. onLoad() {
  113. /// 查询数据
  114. this.queryMyFavorite()
  115. },
  116. /**
  117. * 生命周期函数--监听页面初次渲染完成
  118. */
  119. onReady() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面显示
  123. */
  124. onShow() {
  125. this.getTabBar().init()
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide() {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload() {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh() {
  141. /// 查询数据
  142. this.queryMyFavorite()
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom() {
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage() {
  153. }
  154. })