index.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import { queryMyFavorite } from "../../services/api/orders/index"
  2. import Toast from "../../miniprogram_npm/@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. import { isnullstr } from "../../utils/util";
  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. values: [{ up: [''], dwn: [''] }],
  29. /// 左滑宽度
  30. width: 50,
  31. },
  32. /**
  33. * 每行选中触发事件
  34. */
  35. onSelectItem(e: any) {
  36. var obj = this.data.favorites[e.currentTarget.id]
  37. obj.isChecked = !obj.isChecked
  38. this.data.favorites[e.currentTarget.id] = obj
  39. /// 数据赋值
  40. this.setData({ favorites: this.data.favorites })
  41. },
  42. /**
  43. * tab触发事件
  44. */
  45. onTabChange(e: any) {
  46. this.setData({ active: e.detail.index })
  47. /// 查询数据
  48. this.queryMyFavorite()
  49. },
  50. /**
  51. * 按钮点击事件
  52. */
  53. onButtonPressed() {
  54. /// 数据过滤
  55. const objs = this.data.favorites.filter(itm => {
  56. return itm.isChecked
  57. })
  58. /// 对比最多不能超过3项
  59. if (objs.length < 2 || objs.length > 3) {
  60. Toast('对比不能少于2项、最多不能超过3项')
  61. return
  62. }
  63. /// 页面跳转
  64. wx.navigateTo({
  65. url: '/mCircle/pages/contrast/index?params='+JSON.stringify(objs)
  66. })
  67. },
  68. /**
  69. * tab触发事件
  70. */
  71. onCancelFavorite(e: any) {
  72. /// loding.....
  73. Toast.loading({ message: '请求中.....'})
  74. /// 获取对应的id
  75. const ids = (<string> e.target.id).split(' ')
  76. const index = <number> <unknown>ids[1]
  77. const wrtradeorderid = this.data.favorites[index].wrtradeorderid
  78. /// 参数信息
  79. const info = {
  80. UserID: userid(),
  81. OperateType: 2,
  82. ClientType: clientType(),
  83. MarketID: marketid(),
  84. ClientSerialNo: timetample().toString(),
  85. WRTradeOrderID: wrtradeorderid,
  86. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  87. }
  88. /// 发送请求
  89. sendMsgToMQ({
  90. data: {
  91. data: JSON.stringify(info),
  92. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  93. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  94. isEncrypted: isEncrypted()
  95. },
  96. success: (res) => {
  97. /// 操作失败
  98. if (res.code != 0) {
  99. Toast.fail({message: '请求失败,原因:'+res.msg})
  100. return
  101. }
  102. /// 操作成功
  103. Toast.success({message: '请求成功'})
  104. /// 更新数据
  105. this.queryMyFavorite()
  106. },
  107. fail: (emsg) => {
  108. /// 操作失败
  109. Toast.fail({ message: '请求失败,原因:'+emsg})
  110. }, complete: () => {
  111. /// 清楚Toast
  112. Toast.clear()
  113. }
  114. })
  115. },
  116. /// 查询我的收藏数据信息
  117. queryMyFavorite() {
  118. /// 发送查询
  119. queryMyFavorite({
  120. data: {
  121. userid: userid(),
  122. zscategorys: this.data.active == 0 ? '2' : '5'
  123. },
  124. /// 加载成功
  125. success: (res) => {
  126. if (res.code != 200) {
  127. /// 加载失败
  128. Toast.fail({ message: '加载失败...'});
  129. return
  130. }
  131. /// 数据赋值
  132. this.setData({
  133. favorites: res.data,
  134. /// 显示的值
  135. values: res.data.map(obj => {
  136. return {up: [obj.weight.toString()+'ct',
  137. isnullstr(obj.zsshapetypedisplay),
  138. isnullstr(obj.sizedisplay),
  139. isnullstr(obj.zscategorydisplay)],
  140. dwn: [isnullstr(obj.zscolortype1display)+' | '+
  141. isnullstr(obj.zsclaritytype1display)+' | '+
  142. isnullstr(obj.zscuttype1display)+' | '+
  143. isnullstr(obj.zssymmetrytype1display)+' | '+
  144. isnullstr(obj.zspolishtype1display)+' | '+
  145. isnullstr(obj.zsfluorescencetype1display),
  146. obj.zscurrencytypedisplayunit+obj.price]}
  147. })
  148. })
  149. },
  150. fail: (emsg) => {
  151. /// 加载失败
  152. Toast.fail({ message: '加载失败...'+emsg});
  153. },
  154. complete: () => {
  155. /// 数据赋值
  156. this.setData({ isEmpty: this.data.values.length == 0 })
  157. /// 停止下拉刷新
  158. wx.stopPullDownRefresh()
  159. }
  160. })
  161. },
  162. /**
  163. * 生命周期函数--监听页面加载
  164. */
  165. onLoad() {
  166. /// 查询数据
  167. this.queryMyFavorite()
  168. },
  169. /**
  170. * 生命周期函数--监听页面初次渲染完成
  171. */
  172. onReady() {
  173. },
  174. /**
  175. * 生命周期函数--监听页面显示
  176. */
  177. onShow() {
  178. this.getTabBar().init()
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide() {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload() {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh() {
  194. /// 查询数据
  195. this.queryMyFavorite()
  196. },
  197. /**
  198. * 页面上拉触底事件的处理函数
  199. */
  200. onReachBottom() {
  201. },
  202. /**
  203. * 用户点击右上角分享
  204. */
  205. onShareAppMessage() {
  206. }
  207. })