index.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index"
  2. import { clientType, isEncrypted, marketid, protoHeader, userid, timetample } from "../../services/utils";
  3. import { FunCode } from "../../constants/enum/funcode";
  4. import { sendMsgToMQ } from "../../services/api/common/index";
  5. import { isnullstr } from "../../utils/util";
  6. import { hideLoading, showLoading, showToast } from "../../utils/message/index";
  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. values: [{ up: [''], dwn: [''] }],
  77. /// 左滑宽度
  78. width: 100,
  79. /// 数据是否为空
  80. isEmpty: true,
  81. /// 商品(查询字段-模糊查询)
  82. zsallproperties: '',
  83. /// 数据缓存
  84. storge: {}
  85. },
  86. /**
  87. * tab触发事件
  88. */
  89. onTabChange(e: any) {
  90. this.setData({ active: e.detail.index })
  91. /// 查询数据
  92. e.detail.index == 0 ? this.queryDiamond() : this.queryBuyOrder()
  93. /// 清空搜索条件
  94. const info = wx.getStorageSync('TradeParams')
  95. if (info) { wx.removeStorageSync('TradeParams') }
  96. },
  97. /// 搜索按钮点击
  98. onClick() {
  99. /// 查询求购数据
  100. this.queryBuyOrder()
  101. },
  102. /**
  103. * 下拉菜单触发时间
  104. */
  105. onDropdownChange(e: any) {
  106. switch (e.target.id) {
  107. case "categorys": /// 钻石分类
  108. this.setData({
  109. category: e.detail
  110. })
  111. break;
  112. case "shapes": /// 形状
  113. this.setData({
  114. shape: [e.detail.toString()]
  115. })
  116. break;
  117. case "claritys": /// 钻石净度
  118. this.setData({
  119. clarity: e.detail
  120. })
  121. break;
  122. case "cuts": /// 切工
  123. this.setData({ cut: e.detail })
  124. break;
  125. default: /// 荧光
  126. this.setData({ fluorescence: e.detail })
  127. break;
  128. }
  129. /// 数据查询
  130. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  131. },
  132. /**
  133. * 按钮点击响应事件
  134. */
  135. onButtonPressed(e: any){
  136. /// 获取对应的id
  137. const ids = (<string> e.target.id).split(' ')
  138. let id = (<string> e.target.id).split(' ')[0]
  139. const index = <number> <unknown>ids[1]
  140. switch (id) {
  141. case 'favorite': /// 添加收藏
  142. this.onAddFavorite(index)
  143. break
  144. case 'goods-info': /// 商品详情
  145. wx.navigateTo({ url: '/mHome/pages/goodsdetail/index?goodsno='+ this.data.sellOrders[index].goodsno})
  146. break;
  147. case 'search':
  148. wx.navigateTo({ url: '/mHome/pages/search/index' })
  149. break;
  150. case 'delisting': /// 摘牌
  151. wx.navigateTo({
  152. url: '/mTrade/pages/delistingbuy/index?item='+JSON.stringify(this.data.sellOrders[index])
  153. })
  154. break;
  155. case 'listing-buy': /// 我要求购
  156. wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' })
  157. break;
  158. case 'listing-sell': /// 我要出售
  159. wx.navigateTo({ url: '/mTrade/pages/listingsell/index' })
  160. break;
  161. case 'buy-inquiry': /// 我要询价
  162. wx.navigateTo({ url: '/mTrade/pages/buyinquiry/index' })
  163. break;
  164. case 'order-detail': /// 挂牌详情
  165. wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' })
  166. break;
  167. case 'ask-buy': /// 求购信息
  168. wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' })
  169. break;
  170. default:
  171. break;
  172. }
  173. },
  174. onIconClick(e: any) {
  175. switch (e.currentTarget.id) {
  176. case 'listing-buy': /// 挂买
  177. wx.navigateTo({
  178. url: '/mTrade/pages/listingbuy/index'
  179. })
  180. break;
  181. case 'listing-sell': /// 挂卖
  182. wx.navigateTo({
  183. url: '/mTrade/pages/listingsell/index'
  184. })
  185. break;
  186. case 'search': /// 搜索
  187. wx.navigateTo({
  188. url: '/mHome/pages/search/index'
  189. })
  190. break;
  191. default:
  192. break;
  193. }
  194. },
  195. /**
  196. * 添加收藏
  197. */
  198. onAddFavorite(index: number) {
  199. /// loding.....
  200. showLoading(()=>{
  201. /// 委托单号
  202. const wrtradeorderid = this.data.sellOrders[index].wrtradeorderid
  203. /// 参数信息
  204. const info = {
  205. UserID: userid(),
  206. OperateType: 1,
  207. ClientType: clientType(),
  208. MarketID: marketid(),
  209. ClientSerialNo: timetample().toString(),
  210. WRTradeOrderID: wrtradeorderid,
  211. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  212. }
  213. /// 发送请求
  214. sendMsgToMQ({
  215. data: {
  216. data: JSON.stringify(info),
  217. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  218. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  219. isEncrypted: isEncrypted()
  220. },
  221. success: (res) => {
  222. /// 操作失败
  223. if (res.code != 0) {
  224. hideLoading(()=>{}, '请求失败,原因:'+res.msg, 'error')
  225. return
  226. }
  227. /// 操作成功
  228. hideLoading(()=>{}, '请求成功'+res.msg, 'success')
  229. },
  230. fail: (emsg) => {
  231. /// 操作失败
  232. hideLoading(()=>{}, '请求失败,原因:'+emsg, 'error')
  233. }
  234. })
  235. })
  236. },
  237. /// 查询出售大厅委托单
  238. queryDiamond() {
  239. /// 数据存储
  240. var data = {
  241. /// 钻石分类
  242. zscategory: this.data.category,
  243. /// 形状
  244. zsshapetype: this.data.shape,
  245. /// 净度
  246. zsclaritytype: [this.data.clarity],
  247. /// 切工
  248. zscuttype: [this.data.cut],
  249. /// 荧光
  250. zsfluorescencetype: [this.data.fluorescence],
  251. }
  252. /// 获取参数
  253. const info = JSON.parse(wx.getStorageSync('TradeParams'))
  254. /// 钻石查询
  255. queryDiamond({
  256. data: {
  257. ...data,
  258. /// 颜色
  259. zscolortype: info ? info.zscolortype : [null],
  260. /// 货币类型
  261. zscurrencytype: info ? [info.zscurrencytype.toString()] : [null],
  262. /// 证书类型
  263. zscerttype: info ? [info.zscerttype.toString()] : [null],
  264. /// 抛光
  265. zspolishtype: info ? [info.zspolishtype] : [null],
  266. /// 对称
  267. zssymmetrytype: info ? [info.zssymmetrytype] : [null],
  268. /// 总重量(克拉重量)-从
  269. weight1: info ? info.weight1 : null,
  270. /// 总重量(克拉重量)-至
  271. weight2: info ? info.weight2 : null
  272. },
  273. /// 加载成功
  274. success: (res) => {
  275. if (res.code != 200) {
  276. /// 加载失败
  277. showToast('请求失败,原因:'+res.msg)
  278. return
  279. }
  280. /// 数据赋值
  281. this.setData({
  282. sellOrders: res.data,
  283. isEmpty: res.data.length === 0,
  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. showToast('请求失败,原因:'+emsg)
  302. },
  303. complete: () => {
  304. /// 停止下拉刷新
  305. wx.stopPullDownRefresh()
  306. }
  307. })
  308. },
  309. /// 查询求购大厅委托单
  310. queryBuyOrder() {
  311. /// loding.....
  312. showLoading(()=>{
  313. /// loding....
  314. queryBuyOrder({
  315. data: {
  316. /// 模糊搜索
  317. zsallproperties: this.data.zsallproperties
  318. },
  319. /// 加载成功
  320. success: (res) => {
  321. if (res.code != 200) {
  322. /// 加载失败
  323. hideLoading(()=>{}, '请求失败,原因:'+res.msg, 'error')
  324. return
  325. }
  326. hideLoading(()=>{
  327. /// 数据赋值
  328. this.setData({
  329. buyOrders: res.data,
  330. isEmpty: res.data.length === 0,
  331. /// 显示的值
  332. values: res.data.map(obj => {
  333. return {up: [isnullstr(obj.zsshapetypedisplay),
  334. obj.zssize,
  335. isnullstr(obj.zscategorydisplay)],
  336. dwn: [isnullstr(obj.zscolortypedisplay)+' | '+
  337. isnullstr(obj.zsclaritytypedisplay)+' | '+
  338. isnullstr(obj.zscuttypedisplay)+' | '+
  339. isnullstr(obj.zssymmetrytypedisplay)+' | '+
  340. isnullstr(obj.zspolishtypedisplay)+' | '+
  341. isnullstr(obj.zsfluorescencetypedisplay), '']}
  342. })
  343. })
  344. })
  345. },
  346. fail: (emsg) => {
  347. /// 加载失败
  348. hideLoading(()=>{}, '请求失败,原因:'+emsg, 'error')
  349. },
  350. complete: () => {
  351. /// 停止下拉刷新
  352. wx.stopPullDownRefresh()
  353. }
  354. })
  355. })
  356. },
  357. /**
  358. * 生命周期函数--监听页面加载
  359. */
  360. onLoad() {},
  361. onShow() {
  362. /// 获取参数
  363. const storge = JSON.parse(wx.getStorageSync('TradeParams'))
  364. if (storge) {
  365. /// 数据缓存
  366. this.setData({
  367. storge: storge,
  368. category: storge.category,
  369. cut: storge.zscuttype,
  370. shape: storge.zsshapetype,
  371. clarity: storge.zsclaritytype,
  372. fluorescence: storge.zsfluorescencetype
  373. })
  374. }
  375. /// 查询出售大厅委托单
  376. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  377. },
  378. /**
  379. * 生命周期函数--监听页面初次渲染完成
  380. */
  381. onReady() {
  382. },
  383. /**
  384. * 生命周期函数--监听页面隐藏
  385. */
  386. onHide() {
  387. },
  388. /**
  389. * 生命周期函数--监听页面卸载
  390. */
  391. onUnload() {
  392. },
  393. /**
  394. * 页面相关事件处理函数--监听用户下拉动作
  395. */
  396. onPullDownRefresh() {
  397. /// 查询数据
  398. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  399. },
  400. /**
  401. * 页面上拉触底事件的处理函数
  402. */
  403. onReachBottom() {
  404. },
  405. /**
  406. * 用户点击右上角分享
  407. */
  408. onShareAppMessage() {
  409. }
  410. })