index.ts 6.4 KB

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