index.ts 12 KB

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