index.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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: 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 }, { text: '单颗彩钻', value: 5 }],
  34. category: 2,
  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. zscategory: 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. const info = diamondFilters()
  199. /// 动态添加数据
  200. if (info != undefined) {
  201. /// 类型
  202. data.zscategory = info.zscategory
  203. this.setData({ category: info.zscategory })
  204. /// 形状
  205. if (info.zsshapetype.length != 0) {
  206. data.zsshapetype = info.zsshapetype
  207. this.setData({ shape: Number(info.zsshapetype[0]) })
  208. }
  209. /// 净度
  210. if (info.zsclaritytype.length != 0) {
  211. data.zsclaritytype = info.zsclaritytype
  212. this.setData({ clarity: info.zsclaritytype[0] })
  213. }
  214. /// 切工
  215. if (info.zscuttype.length != 0) {
  216. data.zscuttype = info.zscuttype
  217. this.setData({ cut: info.zscuttype[0] })
  218. }
  219. /// 荧光
  220. if (info.zsfluorescencetype.length != 0) {
  221. data.zsfluorescencetype = info.zsfluorescencetype
  222. this.setData({ fluorescence: info.zsfluorescencetype[0] })
  223. }
  224. /// 总重量(克拉重量)-从
  225. if (info.weight1 != 0) { data.weight1 = info.weight1 }
  226. /// 总重量(克拉重量)-至
  227. if (info.weight2 != 0) { data.weight2 = info.weight2 }
  228. /// 对称
  229. if (info.zssymmetrytype.length != 0) { data.zssymmetrytype = info.zssymmetrytype }
  230. /// 抛光
  231. if (info.zspolishtype.length != 0) { data.zspolishtype = info.zspolishtype }
  232. /// 证书类型
  233. if (info.zscerttype.length != 0) { data.zscerttype = info.zscerttype }
  234. /// 货币类型
  235. if (info.zscurrencytype.length != 0) { data.zscurrencytype = info.zscurrencytype }
  236. /// 颜色
  237. if (info.zscolortype.length != 0) { data.zscolortype = info.zscolortype }
  238. }
  239. /// showLoading
  240. showLoading(() => {
  241. /// 钻石查询
  242. queryDiamond({
  243. data: {
  244. ...data
  245. },
  246. /// 加载成功
  247. success: (res) => {
  248. if (res.code != 200) {
  249. /// 加载失败
  250. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  251. return
  252. }
  253. /// 加载失败
  254. hideLoading(()=>{
  255. /// 数据赋值
  256. this.setData({
  257. isEmpty: res.data.length === 0,
  258. length: res.data.length ?? 0,
  259. sellOrders: res.data.map(itm => {
  260. var obj = itm
  261. obj.zscuttype1display = isnullstr(itm.zscuttype1display)
  262. obj.zspolishtype1display = isnullstr(itm.zspolishtype1display)
  263. obj.zsfluorescencetype1display = isnullstr(itm.zsfluorescencetype1display)
  264. obj.zssymmetrytype1display = isnullstr(itm.zssymmetrytype1display)
  265. obj.favorite = isMyFavorite(obj.wrtradeorderid)
  266. return obj
  267. })
  268. })
  269. })
  270. },
  271. fail: (emsg) => {
  272. /// 加载失败
  273. hideLoading(()=>{}, emsg)
  274. },
  275. complete: () => {
  276. /// 停止下拉刷新
  277. wx.stopPullDownRefresh()
  278. }
  279. })
  280. })
  281. },
  282. /// 查询求购大厅委托单
  283. queryBuyOrder() {
  284. /// loding.....
  285. showLoading(()=>{
  286. /// loding....
  287. queryBuyOrder({
  288. data: {
  289. /// 模糊搜索
  290. zsallproperties: this.data.zsallproperties
  291. },
  292. /// 加载成功
  293. success: (res) => {
  294. if (res.code != 200) {
  295. /// 加载失败
  296. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  297. return
  298. }
  299. hideLoading(()=>{
  300. /// 数据赋值
  301. this.setData({
  302. isEmpty: res.data.length === 0,
  303. length: res.data.length ?? 0,
  304. askOrders: res.data.map(itm => {
  305. var obj = itm
  306. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  307. obj.zssize = itm.zssize.replace(',', '-')
  308. obj.zsfluorescencetypedisplay = isnullstr(itm.zsfluorescencetypedisplay)
  309. obj.zssymmetrytypedisplay = isnullstr(itm.zssymmetrytypedisplay)
  310. obj.zsclaritytypedisplay = isnullstr(itm.zsclaritytypedisplay)
  311. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  312. obj.zscolortypedisplay = isnullstr(itm.zscolortypedisplay)
  313. obj.zspolishtypedisplay = isnullstr(itm.zspolishtypedisplay)
  314. obj.zssize = isnullstr(itm.zssize)
  315. return obj
  316. })
  317. })
  318. })
  319. },
  320. fail: (emsg) => {
  321. /// 加载失败
  322. hideLoading(()=>{}, emsg)
  323. },
  324. complete: () => {
  325. /// 停止下拉刷新
  326. wx.stopPullDownRefresh()
  327. }
  328. })
  329. })
  330. },
  331. /**
  332. * 生命周期函数--监听页面加载
  333. */
  334. onLoad() {
  335. const height = this.data.statusBarHeight+this.data.navHeight
  336. /// 显示默认数据
  337. this.setData({
  338. topHeight: height > 64 ? height : 74.0,
  339. /// 形状
  340. shapes: [{ value: 0, text: '形状' }].concat(getEnumList('ZSShapeType').map(obj => {
  341. return {
  342. value: obj.enumitemname,
  343. text: obj.enumdicname
  344. }
  345. })),
  346. /// 净度
  347. claritys: [{ value: 0, text: '净度' }].concat(getEnumList('ZSClarityType').map(obj => {
  348. return {
  349. value: obj.enumitemname,
  350. text: obj.enumdicname
  351. }
  352. })),
  353. /// 切工
  354. cuts: [{ value: 0, text: '切工' }].concat(getEnumList('ZSCutType').map(obj => {
  355. return {
  356. value: obj.enumitemname,
  357. text: obj.enumdicname
  358. }
  359. })),
  360. /// 荧光
  361. fluorescences: [{ value: 0, text: '荧光' }].concat(getEnumList('ZSFluorescenceType').map(obj => {
  362. return {
  363. value: obj.enumitemname,
  364. text: obj.enumdicname
  365. }
  366. })),
  367. })
  368. },
  369. onShow() {
  370. /// 获取激活想
  371. this.setData({ active: getTradeActive() })
  372. /// 更新数据
  373. const t = this
  374. setTimeout(function () { t.data.active == 0 ? t.queryDiamond() : t.queryBuyOrder() }, 300)
  375. /// 初始化Tabbar
  376. this.getTabBar().init()
  377. },
  378. /**
  379. * 生命周期函数--监听页面初次渲染完成
  380. */
  381. onReady() {
  382. },
  383. /**
  384. * 生命周期函数--监听页面隐藏
  385. */
  386. onHide() {
  387. },
  388. /**
  389. * 生命周期函数--监听页面卸载
  390. */
  391. onUnload() {
  392. },
  393. /**
  394. * 页面相关事件处理函数--监听用户下拉动作
  395. */
  396. onPullDownRefresh() {
  397. /// 查询数据
  398. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  399. },
  400. /**
  401. * 页面上拉触底事件的处理函数
  402. */
  403. onReachBottom() {
  404. },
  405. /**
  406. * 用户点击右上角分享
  407. */
  408. onShareAppMessage() {
  409. }
  410. })