trade.ts 11 KB

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