index.ts 12 KB

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