index.ts 12 KB

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