index.ts 11 KB

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