index.ts 13 KB

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