index.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. /**
  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. const { ordertime, accountid } = this.data.active === 0 ? this.data.sellOrders[index] : this.data.askOrders[index]
  93. const show = accountid === this.data.taaccountid ? 0 : 1
  94. /// 商品详情
  95. if (this.data.active === 0) {
  96. const { goodsno } = this.data.sellOrders[index]
  97. wx.navigateTo({
  98. url: '/mHome/pages/goodsdetail/index?goodsno='+goodsno+'&ordertime='+formatDateString(ordertime, 'YYYY/MM/DD')+'&showTrade='+`${ show }`
  99. })
  100. } else {
  101. wx.navigateTo({
  102. url: ('/mTrade/pages/orderdetail/index?item='+JSON.stringify(this.data.askOrders[index]))
  103. })
  104. }
  105. break;
  106. case 'delisting': /// 摘牌
  107. wx.navigateTo({ url: '/mTrade/pages/delistingsell/index?item='+JSON.stringify(this.data.askOrders[index])})
  108. break;
  109. default:
  110. break;
  111. }
  112. },
  113. onIconClick(e: any) {
  114. switch (e.currentTarget.id) {
  115. case 'listing-buy': /// 我要求购
  116. wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' })
  117. break;
  118. case 'listing-sell': /// 我要出售
  119. wx.navigateTo({ url: '/mTrade/pages/listingsell/index' })
  120. break;
  121. case 'search': /// 搜索
  122. wx.navigateTo({ url: '/mHome/pages/search/index' })
  123. break;
  124. default: break;
  125. }
  126. },
  127. /**
  128. * 添加收藏
  129. */
  130. onAddFavorite(index: number) {
  131. /// loding.....
  132. showLoading(()=>{
  133. /// 委托单号
  134. const { wrtradeorderid, favorite } = this.data.sellOrders[index]
  135. /// 参数信息
  136. const info = JSON.stringify({
  137. UserID: userid(),
  138. OperateType: favorite ? 2 : 1,
  139. ClientType: clientType(),
  140. MarketID: marketID(67),
  141. ClientSerialNo: timetample().toString(),
  142. WRTradeOrderID: wrtradeorderid,
  143. Header: protoHeader(FunCode.GoodsFavoriteOperateReq, marketID(67))
  144. })
  145. /// 发送请求
  146. sendMsgToMQ({
  147. data: {
  148. data: encryptBody(info),
  149. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  150. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  151. isEncrypted: isEncrypted()
  152. },
  153. success: (res) => {
  154. /// 解析对象
  155. const data = JSON.parse(res.data.data)
  156. if (data.RetCode != 0) {
  157. hideLoading(() => {}, getErrorMsg(data.RetCode))
  158. return
  159. }
  160. /// 对其进行操作
  161. isMyFavorite(wrtradeorderid) ? removeMyFavorite(wrtradeorderid) : addMyFavotite(wrtradeorderid)
  162. /// 操作成功
  163. hideLoading(()=>{
  164. setTimeout(function () {
  165. /// 更新数据
  166. this.queryDiamond()
  167. }, 30)
  168. /// 更新数据
  169. wx.startPullDownRefresh()
  170. }, '请求成功'+res.msg, 'success')
  171. },
  172. fail: (emsg) => {
  173. /// 操作失败
  174. hideLoading(()=>{}, emsg)
  175. },
  176. complete: () => {
  177. wx.stopPullDownRefresh()
  178. }
  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 = JSON.parse(wx.getStorageSync('TradeParams'))
  199. showLoading(() => {
  200. /// 钻石查询
  201. queryDiamond({
  202. data: {
  203. ...data,
  204. // /// 颜色
  205. // zscolortype: info ? info.zscolortype : [],
  206. // /// 货币类型
  207. // zscurrencytype: info ? [info.zscurrencytype.toString()] : [],
  208. // /// 证书类型
  209. // zscerttype: info ? [info.zscerttype.toString()] : [],
  210. // /// 抛光
  211. // zspolishtype: info ? [info.zspolishtype] : [],
  212. // /// 对称
  213. // zssymmetrytype: info ? [info.zssymmetrytype] : [],
  214. // /// 总重量(克拉重量)-从
  215. // weight1: info ? info.weight1 : 0.0,
  216. // /// 总重量(克拉重量)-至
  217. // weight2: info ? info.weight2 : 0
  218. },
  219. /// 加载成功
  220. success: (res) => {
  221. if (res.code != 200) {
  222. /// 加载失败
  223. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  224. return
  225. }
  226. /// 加载失败
  227. hideLoading(()=>{
  228. /// 数据赋值
  229. this.setData({
  230. isEmpty: 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. askOrders: res.data.map(itm => {
  276. var obj = itm
  277. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  278. obj.zssize = itm.zssize.replace(',', '-')
  279. obj.zsfluorescencetypedisplay = isnullstr(itm.zsfluorescencetypedisplay)
  280. obj.zssymmetrytypedisplay = isnullstr(itm.zssymmetrytypedisplay)
  281. obj.zsclaritytypedisplay = isnullstr(itm.zsclaritytypedisplay)
  282. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  283. obj.zscolortypedisplay = isnullstr(itm.zscolortypedisplay)
  284. obj.zspolishtypedisplay = isnullstr(itm.zspolishtypedisplay)
  285. obj.zssize = isnullstr(itm.zssize)
  286. return obj
  287. })
  288. })
  289. })
  290. },
  291. fail: (emsg) => {
  292. /// 加载失败
  293. hideLoading(()=>{}, emsg)
  294. },
  295. complete: () => {
  296. /// 停止下拉刷新
  297. wx.stopPullDownRefresh()
  298. }
  299. })
  300. })
  301. },
  302. /**
  303. * 生命周期函数--监听页面加载
  304. */
  305. onLoad() {
  306. /// 显示默认数据
  307. this.setData({
  308. /// 形状
  309. shapes: [{ value: 0, text: '形状' }].concat(getEnumList('ZSShapeType').map(obj => {
  310. return {
  311. value: obj.enumitemname,
  312. text: obj.enumdicname
  313. }
  314. })),
  315. /// 净度
  316. claritys: [{ value: 0, text: '净度' }].concat(getEnumList('ZSClarityType').map(obj => {
  317. return {
  318. value: obj.enumitemname,
  319. text: obj.enumdicname
  320. }
  321. })),
  322. /// 切工
  323. cuts: [{ value: 0, text: '切工' }].concat(getEnumList('ZSCutType').map(obj => {
  324. return {
  325. value: obj.enumitemname,
  326. text: obj.enumdicname
  327. }
  328. })),
  329. /// 荧光
  330. fluorescences: [{ value: 0, text: '荧光' }].concat(getEnumList('ZSFluorescenceType').map(obj => {
  331. return {
  332. value: obj.enumitemname,
  333. text: obj.enumdicname
  334. }
  335. })),
  336. })
  337. /// 查询数据
  338. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  339. },
  340. onShow() {
  341. // /// 获取参数
  342. // const storge = wx.getStorageSync('TradeParams')
  343. // if (storge) {
  344. // try {
  345. // const info = JSON.parse(storge)
  346. // if (storge) {
  347. // /// 数据缓存
  348. // this.setData({
  349. // storge: info,
  350. // category: info.category,
  351. // cut: info.zscuttype,
  352. // shape: info.zsshapetype,
  353. // clarity: info.zsclaritytype,
  354. // fluorescence: info.zsfluorescencetype
  355. // })
  356. // }
  357. // } catch (error) {}
  358. // }
  359. this.setData({ active: getTradeActive() })
  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. })