index.ts 13 KB

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