index.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index"
  2. import { clientType, isEncrypted, marketid, protoHeader, userid, timetample, getEnumList, getErrorMsg, isMyFavorite } from "../../services/utils";
  3. import { FunCode } from "../../constants/enum/funcode";
  4. import { sendMsgToMQ } from "../../services/api/common/index";
  5. import { hideLoading, showLoading } 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: Number(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: Number(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: this.data.sellOrders[index].favorite ? 2 : 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 === 0 ? [] : [this.data.shape.toString()],
  178. /// 净度
  179. zsclaritytype: this.data.clarity === 0 ? [] : [this.data.clarity],
  180. /// 切工
  181. zscuttype: this.data.cut === 0 ? [] : [this.data.cut],
  182. /// 荧光
  183. zsfluorescencetype: this.data.fluorescence === 0 ? [] : [this.data.fluorescence],
  184. }
  185. /// 获取参数
  186. // const info = JSON.parse(wx.getStorageSync('TradeParams'))
  187. showLoading(() => {
  188. /// 钻石查询
  189. queryDiamond({
  190. data: {
  191. ...data,
  192. // /// 颜色
  193. // zscolortype: info ? info.zscolortype : [],
  194. // /// 货币类型
  195. // zscurrencytype: info ? [info.zscurrencytype.toString()] : [],
  196. // /// 证书类型
  197. // zscerttype: info ? [info.zscerttype.toString()] : [],
  198. // /// 抛光
  199. // zspolishtype: info ? [info.zspolishtype] : [],
  200. // /// 对称
  201. // zssymmetrytype: info ? [info.zssymmetrytype] : [],
  202. // /// 总重量(克拉重量)-从
  203. // weight1: info ? info.weight1 : 0.0,
  204. // /// 总重量(克拉重量)-至
  205. // weight2: info ? info.weight2 : 0
  206. },
  207. /// 加载成功
  208. success: (res) => {
  209. if (res.code != 200) {
  210. /// 加载失败
  211. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  212. return
  213. }
  214. /// 加载失败
  215. hideLoading(()=>{
  216. /// 数据赋值
  217. this.setData({
  218. isEmpty: res.data.length === 0,
  219. sellOrders: res.data.map(itm => {
  220. var obj = itm
  221. obj.zscuttype1display = isnullstr(itm.zscuttype1display)
  222. obj.zspolishtype1display = isnullstr(itm.zspolishtype1display)
  223. obj.zsfluorescencetype1display = isnullstr(itm.zsfluorescencetype1display)
  224. obj.zssymmetrytype1display = isnullstr(itm.zssymmetrytype1display)
  225. obj.favorite = isMyFavorite(obj.goodsno)
  226. return obj
  227. })
  228. })
  229. })
  230. },
  231. fail: (emsg) => {
  232. /// 加载失败
  233. hideLoading(()=>{}, emsg)
  234. },
  235. complete: () => {
  236. /// 停止下拉刷新
  237. wx.stopPullDownRefresh()
  238. }
  239. })
  240. })
  241. },
  242. /// 查询求购大厅委托单
  243. queryBuyOrder() {
  244. /// loding.....
  245. showLoading(()=>{
  246. /// loding....
  247. queryBuyOrder({
  248. data: {
  249. /// 模糊搜索
  250. zsallproperties: this.data.zsallproperties
  251. },
  252. /// 加载成功
  253. success: (res) => {
  254. if (res.code != 200) {
  255. /// 加载失败
  256. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  257. return
  258. }
  259. hideLoading(()=>{
  260. /// 数据赋值
  261. this.setData({
  262. isEmpty: res.data.length === 0,
  263. askOrders: res.data.map(itm => {
  264. var obj = itm
  265. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  266. obj.zssize = itm.zssize.replace(',', '-')
  267. obj.zsfluorescencetypedisplay = isnullstr(itm.zsfluorescencetypedisplay)
  268. obj.zssymmetrytypedisplay = isnullstr(itm.zssymmetrytypedisplay)
  269. obj.zsclaritytypedisplay = isnullstr(itm.zsclaritytypedisplay)
  270. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  271. obj.zscolortypedisplay = isnullstr(itm.zscolortypedisplay)
  272. obj.zspolishtypedisplay = isnullstr(itm.zspolishtypedisplay)
  273. obj.zssize = isnullstr(itm.zssize)
  274. return obj
  275. })
  276. })
  277. })
  278. },
  279. fail: (emsg) => {
  280. /// 加载失败
  281. hideLoading(()=>{}, emsg)
  282. },
  283. complete: () => {
  284. /// 停止下拉刷新
  285. wx.stopPullDownRefresh()
  286. }
  287. })
  288. })
  289. },
  290. /**
  291. * 生命周期函数--监听页面加载
  292. */
  293. onLoad() {
  294. /// 显示默认数据
  295. this.setData({
  296. /// 形状
  297. shapes: [{ value: 0, text: '形状' }].concat(getEnumList('ZSShapeType').map(obj => {
  298. return {
  299. value: obj.enumitemname,
  300. text: obj.enumdicname
  301. }
  302. })),
  303. /// 净度
  304. claritys: [{ value: 0, text: '净度' }].concat(getEnumList('ZSClarityType').map(obj => {
  305. return {
  306. value: obj.enumitemname,
  307. text: obj.enumdicname
  308. }
  309. })),
  310. /// 切工
  311. cuts: [{ value: 0, text: '切工' }].concat(getEnumList('ZSCutType').map(obj => {
  312. return {
  313. value: obj.enumitemname,
  314. text: obj.enumdicname
  315. }
  316. })),
  317. /// 荧光
  318. fluorescences: [{ value: 0, text: '荧光' }].concat(getEnumList('ZSFluorescenceType').map(obj => {
  319. return {
  320. value: obj.enumitemname,
  321. text: obj.enumdicname
  322. }
  323. })),
  324. })
  325. /// 查询数据
  326. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  327. },
  328. onShow() {
  329. // /// 获取参数
  330. // const storge = wx.getStorageSync('TradeParams')
  331. // if (storge) {
  332. // try {
  333. // const info = JSON.parse(storge)
  334. // if (storge) {
  335. // /// 数据缓存
  336. // this.setData({
  337. // storge: info,
  338. // category: info.category,
  339. // cut: info.zscuttype,
  340. // shape: info.zsshapetype,
  341. // clarity: info.zsclaritytype,
  342. // fluorescence: info.zsfluorescencetype
  343. // })
  344. // }
  345. // } catch (error) {}
  346. // }
  347. this.setData({ active: Number(wx.getStorageSync('trade_active')) })
  348. },
  349. /**
  350. * 生命周期函数--监听页面初次渲染完成
  351. */
  352. onReady() {
  353. },
  354. /**
  355. * 生命周期函数--监听页面隐藏
  356. */
  357. onHide() {
  358. },
  359. /**
  360. * 生命周期函数--监听页面卸载
  361. */
  362. onUnload() {
  363. },
  364. /**
  365. * 页面相关事件处理函数--监听用户下拉动作
  366. */
  367. onPullDownRefresh() {
  368. /// 查询数据
  369. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  370. },
  371. /**
  372. * 页面上拉触底事件的处理函数
  373. */
  374. onReachBottom() {
  375. },
  376. /**
  377. * 用户点击右上角分享
  378. */
  379. onShareAppMessage() {
  380. }
  381. })