index.ts 13 KB

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