index.ts 6.2 KB

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