index.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index"
  2. import Toast from "../../miniprogram_npm/@vant/weapp/toast/toast"
  3. import { clientType, isEncrypted, marketid, protoHeader, userid, timetample } from "../../services/utils";
  4. import { FunCode } from "../../constants/enum/funcode";
  5. import { sendMsgToMQ } from "../../services/api/common/index";
  6. import { isnullstr } from "../../utils/util";
  7. // pages/trade/index.ts
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. /// 底部安全区域
  14. safeBottom: getApp().globalData.safeBottom,
  15. /// tabs
  16. tabs: [{id: 1, name: '出售大厅'}, {id: 2, name: '求购大厅'}],
  17. /// tab索引
  18. active: 0,
  19. /// 出售大厅列头
  20. asktitles: [['形状', '尺寸', '分类'],
  21. ['颜色 | 净度 | 切工 | 对称 | 抛光 | 荧光 | 证书', '']],
  22. /// 求购大厅列头
  23. selltitles: [['重量', '形状', '尺寸', '分类'],
  24. ['颜色 | 净度 | 切工 | 对称 | 抛光 | 荧光', '价格']],
  25. /// 钻石分类
  26. categorys: [{ text: '单颗裸钻', value: 2 },
  27. { text: '单颗彩钻', value: 5 }],
  28. category: 2,
  29. /// 钻石形状
  30. shapes: [{ text: '圆明亮形', value: '1' },
  31. { text: '公主方形', value: '2' },
  32. { text: '心形', value: '3' },
  33. { text: '马眼形', value: '4' },
  34. { text: '三角形', value: '5' },
  35. { text: '垫形', value: '6' },
  36. { text: '祖母绿形', value: '7' },
  37. { text: '梨形', value: '8' },
  38. { text: '椭圆形', value: '9' },
  39. { text: '长方形', value: '10' },
  40. { text: '雷迪恩形', value: '11' },
  41. { text: '阿斯切形', value: '12' },
  42. { text: '其他', value: '13' }],
  43. shape: ['1'],
  44. /// 净度
  45. claritys: [{ text: 'FL', value: 1 },
  46. { text: 'IF', value: 2 },
  47. { text: 'VVS1', value: 3 },
  48. { text: 'VVS2', value: 4 },
  49. { text: 'VS1', value: 5 },
  50. { text: 'VS2', value: 6 },
  51. { text: 'SI1', value: 7 },
  52. { text: 'SI2', value: 8 },
  53. { text: 'SI3', value: 9 },
  54. { text: 'I1', value: 10 },
  55. { text: 'I2', value: 11 },
  56. { text: 'I3', value: 12 }],
  57. clarity: 1,
  58. /// 切工
  59. cuts: [{ text: 'EX', value: 1 },
  60. { text: 'VG', value: 2 },
  61. { text: 'G', value: 3 },
  62. { text: 'F', value: 4 },
  63. { text: 'P', value: 5 }],
  64. cut: 1,
  65. /// 荧光
  66. fluorescences: [{ text: '无', value: 1 },
  67. { text: '微弱', value: 2 },
  68. { text: '中等', value: 3 },
  69. { text: '强', value: 4 },
  70. { text: '极强', value: 5 }],
  71. fluorescence: 1,
  72. /// 卖大厅数据
  73. sellOrders: <GuangZuan.SellOrder[]>[],
  74. /// 买大厅数据
  75. askOrders: <GuangZuan.BuyOrder[]>[],
  76. /// 显示的值
  77. values: [{ up: [''], dwn: [''] }],
  78. /// 左滑宽度
  79. width: 100,
  80. /// 数据是否为空
  81. isEmpty: true,
  82. /// 商品(查询字段-模糊查询)
  83. zsallproperties: '',
  84. /// 数据缓存
  85. storge: {}
  86. },
  87. /**
  88. * tab触发事件
  89. */
  90. onTabChange(e: any) {
  91. this.setData({ active: e.detail.index })
  92. /// 查询数据
  93. e.detail.index == 0 ? this.queryDiamond() : this.queryBuyOrder()
  94. /// 清空搜索条件
  95. const info = wx.getStorageSync('TradeParams')
  96. if (info) { wx.removeStorageSync('TradeParams') }
  97. },
  98. /// 搜索按钮点击
  99. onClick() {
  100. /// 查询求购数据
  101. this.queryBuyOrder()
  102. },
  103. /**
  104. * 下拉菜单触发时间
  105. */
  106. onDropdownChange(e: any) {
  107. switch (e.target.id) {
  108. case "categorys": /// 钻石分类
  109. this.setData({
  110. category: e.detail
  111. })
  112. break;
  113. case "shapes": /// 形状
  114. this.setData({
  115. shape: [e.detail.toString()]
  116. })
  117. break;
  118. case "claritys": /// 钻石净度
  119. this.setData({
  120. clarity: e.detail
  121. })
  122. break;
  123. case "cuts": /// 切工
  124. this.setData({ cut: e.detail })
  125. break;
  126. default: /// 荧光
  127. this.setData({ fluorescence: e.detail })
  128. break;
  129. }
  130. /// 数据查询
  131. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  132. },
  133. /**
  134. * 按钮点击响应事件
  135. */
  136. onButtonPressed(e: any){
  137. /// 获取对应的id
  138. const ids = (<string> e.target.id).split(' ')
  139. let id = (<string> e.target.id).split(' ')[0]
  140. const index = <number> <unknown>ids[1]
  141. switch (id) {
  142. case 'favorite': /// 添加收藏
  143. this.onAddFavorite(index)
  144. break
  145. case 'goods-info': /// 商品详情
  146. wx.navigateTo({ url: '/mHome/pages/goodsdetail/index?goodsno='+ this.data.sellOrders[index].goodsno})
  147. break;
  148. case 'search':
  149. wx.navigateTo({ url: '/mHome/pages/search/index' })
  150. break;
  151. case 'delisting': /// 摘牌
  152. wx.navigateTo({
  153. url: '/mTrade/pages/delistingbuy/index?item='+JSON.stringify(this.data.sellOrders[index])
  154. })
  155. break;
  156. case 'listing-buy': /// 我要求购
  157. wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' })
  158. break;
  159. case 'listing-sell': /// 我要出售
  160. wx.navigateTo({ url: '/mTrade/pages/listingsell/index' })
  161. break;
  162. case 'buy-inquiry': /// 我要询价
  163. wx.navigateTo({ url: '/mTrade/pages/buyinquiry/index' })
  164. break;
  165. case 'order-detail': /// 挂牌详情
  166. wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' })
  167. break;
  168. case 'ask-buy': /// 求购信息
  169. wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' })
  170. break;
  171. default:
  172. break;
  173. }
  174. },
  175. onIconClick(e: any) {
  176. switch (e.currentTarget.id) {
  177. case 'listing-buy': /// 挂买
  178. wx.navigateTo({
  179. url: '/mTrade/pages/listingbuy/index'
  180. })
  181. break;
  182. case 'listing-sell': /// 挂卖
  183. wx.navigateTo({
  184. url: '/mTrade/pages/listingsell/index'
  185. })
  186. break;
  187. case 'search': /// 搜索
  188. wx.navigateTo({
  189. url: '/mHome/pages/search/index'
  190. })
  191. break;
  192. default:
  193. break;
  194. }
  195. },
  196. /**
  197. * 添加收藏
  198. */
  199. onAddFavorite(index: number) {
  200. /// loding.....
  201. Toast.loading({ message: '请求中.....'})
  202. /// 委托单号
  203. const wrtradeorderid = this.data.sellOrders[index].wrtradeorderid
  204. /// 参数信息
  205. const info = {
  206. UserID: userid(),
  207. OperateType: 1,
  208. ClientType: clientType(),
  209. MarketID: marketid(),
  210. ClientSerialNo: timetample().toString(),
  211. WRTradeOrderID: wrtradeorderid,
  212. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  213. }
  214. /// 发送请求
  215. sendMsgToMQ({
  216. data: {
  217. data: JSON.stringify(info),
  218. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  219. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  220. isEncrypted: isEncrypted()
  221. },
  222. success: (res) => {
  223. /// 操作失败
  224. if (res.code != 0) {
  225. Toast.fail({message: '请求失败,原因:'+res.msg})
  226. return
  227. }
  228. /// 操作成功
  229. Toast.success({message: '请求成功'})
  230. },
  231. fail: (emsg) => {
  232. /// 操作失败
  233. Toast.fail({ message: '请求失败,原因:'+emsg})
  234. }, complete: () => {}
  235. })
  236. },
  237. /// 查询出售大厅委托单
  238. queryDiamond() {
  239. /// loding.....
  240. Toast.loading({message: '加载中...'});
  241. /// 获取参数
  242. const storge = wx.getStorageSync('TradeParams')
  243. /// 数据存储
  244. var info
  245. if (this.data.storge) { info = JSON.parse(storge) }
  246. /// 钻石查询
  247. queryDiamond({
  248. data: {
  249. /// 钻石分类
  250. zscategory: this.data.category,
  251. /// 形状
  252. zsshapetype: this.data.shape,
  253. /// 净度
  254. zsclaritytype: [this.data.clarity],
  255. /// 切工
  256. zscuttype: [this.data.cut],
  257. /// 荧光
  258. zsfluorescencetype: [this.data.fluorescence],
  259. /// 颜色
  260. zscolortype: info ? info.zscolortype : [null],
  261. /// 货币类型
  262. zscurrencytype: info ? [info.zscurrencytype.toString()] : [null],
  263. /// 证书类型
  264. zscerttype: info ? [info.zscerttype.toString()] : [null],
  265. /// 抛光
  266. zspolishtype: info ? [info.zspolishtype] : [null],
  267. /// 对称
  268. zssymmetrytype: info ? [info.zssymmetrytype] : [null],
  269. /// 总重量(克拉重量)-从
  270. weight1: info ? info.weight1 : null,
  271. /// 总重量(克拉重量)-至
  272. weight2: info ? info.weight2 : null
  273. },
  274. /// 加载成功
  275. success: (res) => {
  276. if (res.code != 200) {
  277. /// 加载失败
  278. Toast.fail({ message: '加载失败,原因:'+res.msg});
  279. return
  280. }
  281. /// 数据赋值
  282. this.setData({
  283. sellOrders: res.data,
  284. /// 显示的值
  285. values: res.data.map(obj => {
  286. return {up: [obj.kpweight.toString()+'ct',
  287. isnullstr(obj.zsshapetypedisplay),
  288. isnullstr(obj.sizedisplay),
  289. isnullstr(obj.zscategorydisplay)],
  290. dwn: [isnullstr(obj.zscolortype1display)+' | '+
  291. isnullstr(obj.zsclaritytype1display)+' | '+
  292. isnullstr(obj.zscuttype1display)+' | '+
  293. isnullstr(obj.zssymmetrytype1display)+' | '+isnullstr(obj.zspolishtype1display)+' | '+
  294. isnullstr(obj.zsfluorescencetype1display),
  295. obj.zscurrencytypedisplayunit+obj.price]}
  296. })
  297. })
  298. },
  299. fail: (emsg) => {
  300. /// 加载失败
  301. Toast.fail({ message: '加载失败,原因:'+emsg});
  302. },
  303. complete: () => {
  304. /// Toast
  305. Toast.clear()
  306. /// 数据赋值
  307. this.setData({ isEmpty: this.data.values.length == 0 })
  308. /// 停止下拉刷新
  309. wx.stopPullDownRefresh()
  310. }
  311. })
  312. },
  313. /// 查询求购大厅委托单
  314. queryBuyOrder() {
  315. /// loding.....
  316. Toast.loading({message: '加载中...'});
  317. /// loding....
  318. queryBuyOrder({
  319. data: {
  320. /// 模糊搜索
  321. zsallproperties: this.data.zsallproperties
  322. },
  323. /// 加载成功
  324. success: (res) => {
  325. if (res.code != 200) {
  326. /// 加载失败
  327. Toast.success({ message: '加载失败...'});
  328. return
  329. }
  330. /// 数据赋值
  331. this.setData({
  332. buyOrders: res.data,
  333. /// 显示的值
  334. values: res.data.map(obj => {
  335. return {up: [isnullstr(obj.zsshapetypedisplay),
  336. obj.zssize,
  337. isnullstr(obj.zscategorydisplay)],
  338. dwn: [isnullstr(obj.zscolortypedisplay)+' | '+
  339. isnullstr(obj.zsclaritytypedisplay)+' | '+
  340. isnullstr(obj.zscuttypedisplay)+' | '+
  341. isnullstr(obj.zssymmetrytypedisplay)+' | '+
  342. isnullstr(obj.zspolishtypedisplay)+' | '+
  343. isnullstr(obj.zsfluorescencetypedisplay),
  344. '']}
  345. })
  346. })
  347. },
  348. fail: (emsg) => {
  349. /// 加载失败
  350. Toast.fail({ message: '加载失败...'+emsg});
  351. },
  352. complete: () => {
  353. /// Toast
  354. Toast.clear()
  355. /// 数据赋值
  356. this.setData({ isEmpty: this.data.values.length == 0 })
  357. /// 停止下拉刷新
  358. wx.stopPullDownRefresh()
  359. }
  360. })
  361. },
  362. /**
  363. * 生命周期函数--监听页面加载
  364. */
  365. onLoad() {},
  366. onShow() {
  367. /// 获取参数
  368. const storge = wx.getStorageSync('TradeParams')
  369. if (storge) {
  370. try {
  371. /// 数据存储
  372. const info = JSON.parse(storge)
  373. /// 数据缓存
  374. this.setData({ storge: info })
  375. /// 数据赋值
  376. if (info) {
  377. this.setData({
  378. category: info.category,
  379. cut: info.zscuttype,
  380. shape: info.zsshapetype,
  381. clarity: info.zsclaritytype,
  382. fluorescence: info.zsfluorescencetype
  383. })
  384. }
  385. } catch (error) {}
  386. }
  387. /// 查询出售大厅委托单
  388. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  389. },
  390. /**
  391. * 生命周期函数--监听页面初次渲染完成
  392. */
  393. onReady() {
  394. },
  395. /**
  396. * 生命周期函数--监听页面隐藏
  397. */
  398. onHide() {
  399. },
  400. /**
  401. * 生命周期函数--监听页面卸载
  402. */
  403. onUnload() {
  404. },
  405. /**
  406. * 页面相关事件处理函数--监听用户下拉动作
  407. */
  408. onPullDownRefresh() {
  409. /// 查询数据
  410. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  411. },
  412. /**
  413. * 页面上拉触底事件的处理函数
  414. */
  415. onReachBottom() {
  416. },
  417. /**
  418. * 用户点击右上角分享
  419. */
  420. onShareAppMessage() {
  421. }
  422. })