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. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. /// 状态栏高度
  14. statusBarHeight: getApp().globalData.statusBarHeight,
  15. /// 导航栏高度
  16. navHeight: getApp().globalData.navHeight,
  17. /// 底部安全区域
  18. safeBottom: getApp().globalData.safeBottom,
  19. /// 窗口高度
  20. windowHeight: getApp().globalData.windowHeight,
  21. /// tabs
  22. tabs: [{id: 1, name: '出售大厅'}, {id: 2, name: '求购大厅'}],
  23. /// 功能菜单
  24. menus: [{id: "listing-buy", icon: appConfig.imgUrl+'trade-listingbuy', title: '求购', path: '/mTrade/pages/listingbuy/index'},
  25. {id: "listing-sell", icon: appConfig.imgUrl+'trade-listingsell', title: '出售', path: '/mTrade/pages/listingsell/index'},
  26. {id: "search", icon: appConfig.imgUrl+'trade-search', title: '筛选', path: '/mHome/pages/search/index'}],
  27. /// tab索引
  28. active: 0,
  29. /// 钻石分类
  30. categorys: [{ text: '单颗裸钻', value: 2 },
  31. { text: '单颗彩钻', value: 5 }],
  32. category: 2,
  33. /// 钻石形状
  34. shapes: [{ value: 1, text: '圆明亮形' }],
  35. shape: 1,
  36. /// 净度
  37. claritys: [{ text: 'FL', value: 1 }],
  38. clarity: 1,
  39. /// 切工
  40. cuts: [{ text: 'EX', value: 1 }],
  41. cut: 1,
  42. /// 荧光
  43. fluorescences: [{ text: '无', value: 1 }],
  44. fluorescence: 1,
  45. ///出售大厅数据
  46. sellOrders: <GuangZuan.SellOrder[]>[],
  47. /// 求购大厅数据
  48. askOrders: <GuangZuan.BuyOrder[]>[],
  49. /// 数据是否为空
  50. isEmpty: true,
  51. /// 商品(查询字段-模糊查询)
  52. zsallproperties: '',
  53. /// 数据缓存
  54. storge: {}
  55. },
  56. /**
  57. * tab触发事件
  58. */
  59. onTabChange(e: any) {
  60. this.setData({ active: e.detail.index })
  61. /// 查询数据
  62. e.detail.index == 0 ? this.queryDiamond() : this.queryBuyOrder()
  63. },
  64. /// 搜索按钮点击
  65. onClick() {
  66. /// 查询求购数据
  67. this.queryBuyOrder()
  68. },
  69. /**
  70. * 下拉菜单触发时间
  71. */
  72. onDropdownChange(e: any) {
  73. switch (e.target.id) {
  74. case "categorys": /// 钻石分类
  75. this.setData({ category: e.detail })
  76. break;
  77. case "shapes": /// 形状
  78. this.setData({ shape: e.detail })
  79. break;
  80. case "claritys": /// 钻石净度
  81. this.setData({ clarity: e.detail })
  82. break;
  83. case "cuts": /// 切工
  84. this.setData({ cut: e.detail })
  85. break;
  86. default: /// 荧光
  87. this.setData({ fluorescence: e.detail })
  88. break;
  89. }
  90. /// 数据查询
  91. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  92. },
  93. /**
  94. * 按钮点击响应事件
  95. */
  96. onButtonPressed(e: any){
  97. /// 获取对应的id
  98. const ids = (<string> e.target.id).split(' ')
  99. let id = (<string> e.target.id).split(' ')[0]
  100. const index = <number><unknown>ids[1]
  101. switch (id) {
  102. case 'favorite': /// 添加收藏
  103. this.onAddFavorite(index)
  104. break
  105. case 'detail': /// 商品详情
  106. wx.navigateTo({
  107. 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]))
  108. })
  109. break;
  110. case 'delisting': /// 摘牌
  111. wx.navigateTo({
  112. url: '/mTrade/pages/delistingsell/index?item='+JSON.stringify(this.data.askOrders[index])
  113. })
  114. break;
  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 'ask-buy': /// 求购信息
  122. wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' })
  123. break;
  124. default:
  125. break;
  126. }
  127. },
  128. onIconClick(e: any) {
  129. switch (e.currentTarget.id) {
  130. case 'listing-buy': /// 挂买
  131. wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' })
  132. break;
  133. case 'listing-sell': /// 挂卖
  134. wx.navigateTo({ url: '/mTrade/pages/listingsell/index' })
  135. break;
  136. case 'search': /// 搜索
  137. wx.navigateTo({ url: '/mHome/pages/search/index' })
  138. break;
  139. default: break;
  140. }
  141. },
  142. /**
  143. * 添加收藏
  144. */
  145. onAddFavorite(index: number) {
  146. /// loding.....
  147. showLoading(()=>{
  148. /// 委托单号
  149. const wrtradeorderid = this.data.sellOrders[index].wrtradeorderid
  150. /// 参数信息
  151. const info = JSON.stringify({
  152. UserID: userid(),
  153. OperateType: 1,
  154. ClientType: clientType(),
  155. MarketID: marketid(),
  156. ClientSerialNo: timetample().toString(),
  157. WRTradeOrderID: wrtradeorderid,
  158. Header: protoHeader(FunCode.GoodsFavoriteOperateReq)
  159. })
  160. /// 发送请求
  161. sendMsgToMQ({
  162. data: {
  163. data: encryptBody(info),
  164. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  165. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  166. isEncrypted: isEncrypted()
  167. },
  168. success: (res) => {
  169. /// 解析对象
  170. const data = JSON.parse(res.data.data)
  171. if (data.RetCode != 0) {
  172. hideLoading(() => {}, getErrorMsg(data.RetCode))
  173. return
  174. }
  175. /// 操作成功
  176. hideLoading(()=>{}, '请求成功'+res.msg, 'success')
  177. },
  178. fail: (emsg) => {
  179. /// 操作失败
  180. hideLoading(()=>{}, emsg)
  181. },
  182. complete: () => {
  183. wx.stopPullDownRefresh()
  184. }
  185. })
  186. })
  187. },
  188. /// 查询出售大厅委托单
  189. queryDiamond() {
  190. /// 数据存储
  191. var data = {
  192. /// 钻石分类
  193. zscategory: this.data.category,
  194. /// 形状
  195. zsshapetype: [this.data.shape.toString()],
  196. /// 净度
  197. zsclaritytype: [this.data.clarity],
  198. /// 切工
  199. zscuttype: [this.data.cut],
  200. /// 荧光
  201. zsfluorescencetype: [this.data.fluorescence],
  202. }
  203. // /// 获取参数
  204. // const info = JSON.parse(wx.getStorageSync('TradeParams'))
  205. /// 钻石查询
  206. queryDiamond({
  207. data: {
  208. ...data,
  209. // /// 颜色
  210. // zscolortype: info ? info.zscolortype : [null],
  211. // /// 货币类型
  212. // zscurrencytype: info ? [info.zscurrencytype.toString()] : [''],
  213. // /// 证书类型
  214. // zscerttype: info ? [info.zscerttype.toString()] : [''],
  215. // /// 抛光
  216. // zspolishtype: info ? [info.zspolishtype] : [],
  217. // /// 对称
  218. // zssymmetrytype: info ? [info.zssymmetrytype] : [],
  219. // /// 总重量(克拉重量)-从
  220. // weight1: info ? info.weight1 : 0.0,
  221. // /// 总重量(克拉重量)-至
  222. // weight2: info ? info.weight2 : 0
  223. },
  224. /// 加载成功
  225. success: (res) => {
  226. if (res.code != 200) {
  227. /// 加载失败
  228. showToast('请求失败,原因:'+res.msg)
  229. return
  230. }
  231. /// 数据赋值
  232. this.setData({
  233. sellOrders: res.data,
  234. isEmpty: res.data.length === 0,
  235. })
  236. },
  237. fail: (emsg) => {
  238. /// 加载失败
  239. showToast(emsg)
  240. },
  241. complete: () => {
  242. /// 停止下拉刷新
  243. wx.stopPullDownRefresh()
  244. }
  245. })
  246. },
  247. /// 查询求购大厅委托单
  248. queryBuyOrder() {
  249. /// loding.....
  250. showLoading(()=>{
  251. /// loding....
  252. queryBuyOrder({
  253. data: {
  254. /// 模糊搜索
  255. zsallproperties: this.data.zsallproperties
  256. },
  257. /// 加载成功
  258. success: (res) => {
  259. if (res.code != 200) {
  260. /// 加载失败
  261. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  262. return
  263. }
  264. hideLoading(()=>{
  265. /// 数据赋值
  266. this.setData({
  267. askOrders: res.data,
  268. isEmpty: res.data.length === 0
  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: getEnumList('ZSShapeType').map(obj => {
  291. return {
  292. value: obj.enumitemname,
  293. text: obj.enumdicname
  294. }
  295. }),
  296. /// 净度
  297. claritys: getEnumList('ZSClarityType').map(obj => {
  298. return {
  299. value: obj.enumitemname,
  300. text: obj.enumdicname
  301. }
  302. }),
  303. /// 切工
  304. cuts: getEnumList('ZSCutType').map(obj => {
  305. return {
  306. value: obj.enumitemname,
  307. text: obj.enumdicname
  308. }
  309. }),
  310. /// 荧光
  311. fluorescences: 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. })