index.ts 6.0 KB

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