trade.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. /**
  81. * tab触发事件
  82. */
  83. onTabChange(e: any) {
  84. this.setData({ active: e.detail.index })
  85. /// 查询数据
  86. e.detail.index == 0 ? this.queryDiamond() : this.queryBuyOrder()
  87. /// 清空搜索条件
  88. const info = wx.getStorageSync('TradeParams')
  89. if (info) { wx.removeStorageSync('TradeParams') }
  90. },
  91. /// 搜索按钮点击
  92. onClick() {
  93. /// 查询求购数据
  94. this.queryBuyOrder()
  95. },
  96. /**
  97. * 下拉菜单触发时间
  98. */
  99. onDropdownChange(e: any) {
  100. switch (e.target.id) {
  101. case "categorys": /// 钻石分类
  102. this.setData({
  103. category: e.detail
  104. })
  105. break;
  106. case "shapes": /// 形状
  107. this.setData({
  108. shape: e.detail
  109. })
  110. break;
  111. case "claritys": /// 钻石净度
  112. this.setData({
  113. clarity: e.detail
  114. })
  115. break;
  116. case "cuts": /// 切工
  117. this.setData({ cut: e.detail })
  118. break;
  119. default: /// 荧光
  120. this.setData({ fluorescence: e.detail })
  121. break;
  122. }
  123. /// 数据查询
  124. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  125. },
  126. /**
  127. * 按钮点击响应事件
  128. */
  129. onButtonPressed(e: any){
  130. /// 获取对应的id
  131. const ids = (<string> e.target.id).split(' ')
  132. let id = (<string> e.target.id).split(' ')[0]
  133. const index = <number> <unknown>ids[1]
  134. switch (id) {
  135. case 'favorite': /// 添加收藏
  136. this.onAddFavorite(index)
  137. break
  138. case 'goods-info': /// 商品详情
  139. wx.navigateTo({ url: '/mHome/pages/goodsdetail/goodsdetail' })
  140. break;
  141. case 'search':
  142. wx.navigateTo({ url: '/mHome/pages/search/search' })
  143. break;
  144. case 'delisting': /// 摘牌
  145. wx.navigateTo({
  146. url: this.data.active == 0 ? '/mTrade/pages/delistingbuy/delistingbuy' : '/mTrade/pages/delistingsell/delistingsell'
  147. })
  148. break;
  149. case 'listing-buy': /// 我要求购
  150. wx.navigateTo({ url: '/mTrade/pages/listingbuy/listingbuy' })
  151. break;
  152. case 'listing-sell': /// 我要出售
  153. wx.navigateTo({ url: '/mTrade/pages/listingsell/listingsell' })
  154. break;
  155. case 'buy-inquiry': /// 我要询价
  156. wx.navigateTo({ url: '/mTrade/pages/buyinquiry/buyinquiry' })
  157. break;
  158. case 'order-detail': /// 挂牌详情
  159. wx.navigateTo({ url: '/mTrade/pages/orderdetail/orderdetail' })
  160. break;
  161. case 'ask-buy': /// 求购信息
  162. wx.navigateTo({ url: '/mTrade/pages/orderdetail/orderdetail' })
  163. break;
  164. default:
  165. break;
  166. }
  167. },
  168. /**
  169. * 添加收藏
  170. */
  171. onAddFavorite(index: number) {
  172. /// loding.....
  173. Toast.loading({ message: '请求中.....'})
  174. /// 委托单号
  175. const wrtradeorderid = this.data.sellOrders[index].wrtradeorderid
  176. /// 参数信息
  177. const info = {
  178. UserID: userid(),
  179. OperateType: 1,
  180. ClientType: clientType(),
  181. MarketID: marketid(),
  182. ClientSerialNo: timetample().toString(),
  183. WRTradeOrderID: wrtradeorderid,
  184. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  185. }
  186. /// 发送请求
  187. sendMsgToMQ({
  188. data: {
  189. data: JSON.stringify(info),
  190. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  191. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  192. isEncrypted: isEncrypted()
  193. },
  194. success: (res) => {
  195. /// 操作失败
  196. if (res.code != 0) {
  197. Toast.fail({message: '请求失败,原因:'+res.msg})
  198. return
  199. }
  200. console.log(res)
  201. /// 操作成功
  202. Toast.success({message: '请求成功'})
  203. },
  204. fail: (emsg) => {
  205. /// 操作失败
  206. Toast.fail({ message: '请求失败,原因:'+emsg})
  207. }, complete: () => {}
  208. })
  209. },
  210. /// 查询出售大厅委托单
  211. queryDiamond() {
  212. /// loding.....
  213. Toast.loading({message: '加载中...'});
  214. /// 数据存储
  215. // const info = JSON.parse(wx.getStorageSync('TradeParams'))
  216. /// 钻石查询
  217. queryDiamond({
  218. data: {
  219. /// 钻石分类
  220. zscategory: this.data.category,
  221. // /// 形状
  222. // zsshapetype: [this.data.shape.toString()],
  223. // /// 净度
  224. // zsclaritytype: [this.data.clarity],
  225. // /// 切工
  226. // zscuttype: [this.data.cut],
  227. // /// 荧光
  228. // zsfluorescencetype: [this.data.fluorescence],
  229. // /// 颜色
  230. // zscolortype: info ? [info.zscolortype] : [null],
  231. // /// 货币类型
  232. // zscurrencytype: info ? [info.zscurrencytype.toString()] : [null],
  233. // /// 证书类型
  234. // zscerttype: info ? [info.zscerttype.toString()] : [null],
  235. // /// 抛光
  236. // zspolishtype: info ? [info.zspolishtype] : [null],
  237. // /// 对称
  238. // zssymmetrytype: info ? [info.zssymmetrytype] : [null],
  239. // /// 总重量(克拉重量)-从
  240. // weight1: info ? info.weight1 : null,
  241. // /// 总重量(克拉重量)-至
  242. // weight2: info ? info.weight2 : null
  243. },
  244. /// 加载成功
  245. success: (res) => {
  246. if (res.code != 200) {
  247. /// 加载失败
  248. Toast.fail({ message: '加载失败,原因:'+res.msg});
  249. return
  250. }
  251. /// 数据赋值
  252. this.setData({
  253. sellOrders: res.data,
  254. isEmpty: res.data.length == 0
  255. })
  256. },
  257. fail: (emsg) => {
  258. /// 加载失败
  259. Toast.fail({ message: '加载失败,原因:'+emsg});
  260. },
  261. complete: () => {}
  262. })
  263. },
  264. /// 查询求购大厅委托单
  265. queryBuyOrder() {
  266. /// loding.....
  267. Toast.loading({message: '加载中...'});
  268. /// loding....
  269. queryBuyOrder({
  270. data: {
  271. /// 模糊搜索
  272. zsallproperties: this.data.zsallproperties
  273. },
  274. /// 加载成功
  275. success: (res) => {
  276. if (res.code != 200) {
  277. /// 加载失败
  278. Toast.success({ message: '加载失败...'});
  279. return
  280. }
  281. /// 数据赋值
  282. this.setData({
  283. buyOrders: res.data,
  284. isEmpty: res.data.length == 0
  285. })
  286. },
  287. fail: (emsg) => {
  288. /// 加载失败
  289. Toast.fail({ message: '加载失败...'+emsg});
  290. },
  291. complete: () => {}
  292. })
  293. },
  294. /**
  295. * 生命周期函数--监听页面加载
  296. */
  297. onLoad() {},
  298. onShow() {
  299. try {
  300. /// 数据存储
  301. const info = JSON.parse(wx.getStorageSync('TradeParams'))
  302. if (info) {
  303. this.setData({
  304. category: info.category,
  305. cut: info.zscuttype,
  306. shape: info.zsshapetype,
  307. clarity: info.zsclaritytype,
  308. fluorescence: info.zsfluorescencetype
  309. })
  310. }
  311. } catch (error) {}
  312. /// 查询出售大厅委托单
  313. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  314. },
  315. /**
  316. * 生命周期函数--监听页面初次渲染完成
  317. */
  318. onReady() {
  319. },
  320. /**
  321. * 生命周期函数--监听页面隐藏
  322. */
  323. onHide() {
  324. },
  325. /**
  326. * 生命周期函数--监听页面卸载
  327. */
  328. onUnload() {
  329. },
  330. /**
  331. * 页面相关事件处理函数--监听用户下拉动作
  332. */
  333. onPullDownRefresh() {
  334. /// 查询数据
  335. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  336. },
  337. /**
  338. * 页面上拉触底事件的处理函数
  339. */
  340. onReachBottom() {
  341. },
  342. /**
  343. * 用户点击右上角分享
  344. */
  345. onShareAppMessage() {
  346. }
  347. })