index.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import { queryMyFavorite } from "../../services/api/orders/index"
  2. import { clientType, isEncrypted, protoHeader, userid, timetample, getErrorMsg, marketID, removeMyFavorite } from "../../services/utils";
  3. import { sendMsgToMQ } from "../../services/api/common/index";
  4. import { FunCode } from "../../constants/enum/funcode";
  5. import { formatDateString, isnullstr } from "../../utils/util";
  6. import { hideLoading, showLoading, showToast } from "../../utils/message/index";
  7. import { encryptBody } from "../../utils/websocket/crypto";
  8. import services from "../../services/index";
  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: <string[]>[], dwn: <string[]>[] }],
  35. /// 左滑宽度
  36. width: 100,
  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. showToast('对比不能少于2项、最多不能超过3项')
  67. return
  68. }
  69. /// 页面跳转
  70. wx.navigateTo({
  71. url: '/mCircle/pages/contrast/index?params='+JSON.stringify(objs)
  72. })
  73. },
  74. /// 跳转到商品详情
  75. goToGoodsDetail(e: any) {
  76. /// 获取对应的id
  77. const ids = (<string> e.currentTarget.id).split(' ')
  78. const index = <number><unknown>ids[1]
  79. const { goodsno } = this.data.favorites[index]
  80. /// 商品详情
  81. wx.navigateTo({
  82. url: '/mHome/pages/goodsdetail/index?goodsno='+goodsno+'&ordertime=-'+'&showTrade='+1
  83. })
  84. },
  85. /**
  86. * tab触发事件
  87. */
  88. onCancelFavorite(e: any) {
  89. /// loding.....
  90. showLoading(()=>{
  91. /// 获取对应的id
  92. const ids = (<string> e.target.id).split(' ')
  93. const index = <number> <unknown>ids[1]
  94. const { wrtradeorderid } = this.data.favorites[index]
  95. /// 参数信息
  96. const info = JSON.stringify({
  97. UserID: userid(),
  98. OperateType: 2,
  99. ClientType: clientType(),
  100. MarketID: marketID(67),
  101. ClientSerialNo: timetample().toString(),
  102. WRTradeOrderID: wrtradeorderid,
  103. Header: protoHeader(FunCode.GoodsFavoriteOperateReq, marketID(67))
  104. })
  105. /// 发送请求
  106. sendMsgToMQ({
  107. data: {
  108. data: encryptBody(info),
  109. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  110. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  111. isEncrypted: isEncrypted()
  112. },
  113. success: (res) => {
  114. /// 解析对象
  115. const data = JSON.parse(res.data.data)
  116. if (data.RetCode != 0) {
  117. hideLoading(() => {}, getErrorMsg(data.RetCode))
  118. return
  119. }
  120. /// 移除我的记录
  121. removeMyFavorite(wrtradeorderid)
  122. /// 操作成功
  123. hideLoading(()=>{
  124. /// 更新数据
  125. wx.startPullDownRefresh()
  126. }, '请求成功', 'success')
  127. },
  128. fail: (emsg) => {
  129. /// 操作失败
  130. hideLoading(()=>{}, emsg)
  131. },
  132. complete: () => {
  133. wx.stopPullDownRefresh()
  134. }
  135. })
  136. })
  137. },
  138. /// 查询我的收藏数据信息
  139. queryMyFavorite() {
  140. /// showLoading
  141. showLoading(()=> {
  142. /// 发送查询
  143. queryMyFavorite({
  144. data: {
  145. userid: userid(),
  146. zscategorys: this.data.active == 0 ? '2' : '5'
  147. },
  148. /// 加载成功
  149. success: (res) => {
  150. if (res.code != 200) {
  151. /// 加载失败
  152. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  153. return
  154. }
  155. /// hideLoading
  156. hideLoading(()=>{
  157. /// 数据赋值
  158. this.setData({
  159. favorites: res.data.map(itm => {
  160. var obj = itm
  161. obj.imagepath = (services.config.openApiUrl+itm.imagepath).replace('./uploadFile', '/uploadFile')
  162. return obj
  163. }),
  164. isEmpty: res.data.length === 0,
  165. /// 显示的值
  166. values: res.data.map(obj => {
  167. return {up: [obj.weight.toString()+'ct',
  168. isnullstr(obj.zsshapetypedisplay),
  169. isnullstr(obj.sizedisplay),
  170. isnullstr(obj.goodsno)],
  171. dwn: [isnullstr(obj.zscolortype1display)+' | '+
  172. isnullstr(obj.zsclaritytype1display)+' | '+
  173. isnullstr(obj.zscuttype1display)+' | '+
  174. isnullstr(obj.zspolishtype1display)+' | '+
  175. isnullstr(obj.zssymmetrytype1display)+' | '+
  176. isnullstr(obj.zsfluorescencetype1display),
  177. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)]}
  178. })
  179. })
  180. })
  181. },
  182. fail: (emsg) => {
  183. /// 加载失败
  184. hideLoading(()=>{}, emsg)
  185. },
  186. complete: () => {
  187. /// 停止下拉刷新
  188. wx.stopPullDownRefresh()
  189. }
  190. })
  191. })
  192. },
  193. /**
  194. * 生命周期函数--监听页面加载
  195. */
  196. onLoad() {
  197. /// 初始化Tabbar
  198. this.getTabBar().init()
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onReady() {
  204. },
  205. /**
  206. * 生命周期函数--监听页面显示
  207. */
  208. onShow() {
  209. /// 查询数据
  210. this.queryMyFavorite()
  211. /// 初始化tabbar
  212. this.getTabBar().init()
  213. },
  214. /**
  215. * 生命周期函数--监听页面隐藏
  216. */
  217. onHide() {
  218. },
  219. /**
  220. * 生命周期函数--监听页面卸载
  221. */
  222. onUnload() {
  223. },
  224. /**
  225. * 页面相关事件处理函数--监听用户下拉动作
  226. */
  227. onPullDownRefresh() {
  228. /// 查询数据
  229. this.queryMyFavorite()
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. onReachBottom() {
  235. },
  236. /**
  237. * 用户点击右上角分享
  238. */
  239. onShareAppMessage() {
  240. }
  241. })