index.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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, saveMyFavorites } 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: <string[]>[], dwn: <string[]>[] }],
  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. /// 保存我的收藏
  144. // saveMyFavorites(res.data)
  145. /// hideLoading
  146. hideLoading(()=>{
  147. /// 数据赋值
  148. this.setData({
  149. favorites: res.data.map(itm => {
  150. var obj = itm
  151. obj.imagepath = (services.config.openApiUrl+itm.imagepath).replace('./uploadFile', '/uploadFile')
  152. return obj
  153. }),
  154. isEmpty: res.data.length === 0,
  155. /// 显示的值
  156. values: res.data.map(obj => {
  157. return {up: [obj.weight.toString()+'ct',
  158. isnullstr(obj.zsshapetypedisplay),
  159. isnullstr(obj.sizedisplay),
  160. isnullstr(obj.goodsno)],
  161. dwn: [isnullstr(obj.zscolortype1display)+' | '+
  162. isnullstr(obj.zsclaritytype1display)+' | '+
  163. isnullstr(obj.zscuttype1display)+' | '+
  164. isnullstr(obj.zspolishtype1display)+' | '+
  165. isnullstr(obj.zssymmetrytype1display)+' | '+
  166. isnullstr(obj.zsfluorescencetype1display),
  167. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)]}
  168. })
  169. })
  170. })
  171. },
  172. fail: (emsg) => {
  173. /// 加载失败
  174. hideLoading(()=>{}, emsg)
  175. },
  176. complete: () => {
  177. /// 停止下拉刷新
  178. wx.stopPullDownRefresh()
  179. }
  180. })
  181. })
  182. },
  183. /**
  184. * 生命周期函数--监听页面加载
  185. */
  186. onLoad() {
  187. /// 查询数据
  188. this.queryMyFavorite()
  189. },
  190. /**
  191. * 生命周期函数--监听页面初次渲染完成
  192. */
  193. onReady() {
  194. },
  195. /**
  196. * 生命周期函数--监听页面显示
  197. */
  198. onShow() {
  199. this.getTabBar().init()
  200. },
  201. /**
  202. * 生命周期函数--监听页面隐藏
  203. */
  204. onHide() {
  205. },
  206. /**
  207. * 生命周期函数--监听页面卸载
  208. */
  209. onUnload() {
  210. },
  211. /**
  212. * 页面相关事件处理函数--监听用户下拉动作
  213. */
  214. onPullDownRefresh() {
  215. /// 查询数据
  216. this.queryMyFavorite()
  217. },
  218. /**
  219. * 页面上拉触底事件的处理函数
  220. */
  221. onReachBottom() {
  222. },
  223. /**
  224. * 用户点击右上角分享
  225. */
  226. onShareAppMessage() {
  227. }
  228. })