circle.ts 5.6 KB

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