index.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index"
  2. import { clientType, isEncrypted, protoHeader, userid, timetample, getEnumList, getErrorMsg, isMyFavorite, accountid, marketID, addMyFavotite, removeMyFavorite } 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, goodsno } = this.data.sellOrders[index]
  93. const show = accountid === this.data.taaccountid ? 0 : 1
  94. wx.navigateTo({
  95. url: this.data.active === 0 ? '/mHome/pages/goodsdetail/index?goodsno='+goodsno+'&ordertime='+formatDateString(ordertime, 'YYYY/MM/DD')+'&showTrade='+`${ show }` : ('/mTrade/pages/orderdetail/index?item='+JSON.stringify(this.data.askOrders[index]))
  96. })
  97. break;
  98. case 'delisting': /// 摘牌
  99. wx.navigateTo({ url: '/mTrade/pages/delistingsell/index?item='+JSON.stringify(this.data.askOrders[index])})
  100. break;
  101. case 'listing-buy': /// 我要求购
  102. wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' })
  103. break;
  104. case 'listing-sell': /// 我要出售
  105. wx.navigateTo({ url: '/mTrade/pages/listingsell/index' })
  106. break;
  107. case 'ask-buy': /// 求购信息
  108. wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' })
  109. break;
  110. default:
  111. break;
  112. }
  113. },
  114. onIconClick(e: any) {
  115. switch (e.currentTarget.id) {
  116. case 'listing-buy': /// 挂买
  117. wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' })
  118. break;
  119. case 'listing-sell': /// 挂卖
  120. wx.navigateTo({ url: '/mTrade/pages/listingsell/index' })
  121. break;
  122. case 'search': /// 搜索
  123. wx.navigateTo({ url: '/mHome/pages/search/index' })
  124. break;
  125. default: break;
  126. }
  127. },
  128. /**
  129. * 添加收藏
  130. */
  131. onAddFavorite(index: number) {
  132. /// loding.....
  133. showLoading(()=>{
  134. /// 委托单号
  135. const { wrtradeorderid, favorite } = this.data.sellOrders[index]
  136. /// 参数信息
  137. const info = JSON.stringify({
  138. UserID: userid(),
  139. OperateType: favorite ? 2 : 1,
  140. ClientType: clientType(),
  141. MarketID: marketID(67),
  142. ClientSerialNo: timetample().toString(),
  143. WRTradeOrderID: wrtradeorderid,
  144. Header: protoHeader(FunCode.GoodsFavoriteOperateReq, marketID(67))
  145. })
  146. /// 发送请求
  147. sendMsgToMQ({
  148. data: {
  149. data: encryptBody(info),
  150. funCodeReq: FunCode.GoodsFavoriteOperateReq,
  151. funCodeRsp: FunCode.GoodsFavoriteOperateRsp,
  152. isEncrypted: isEncrypted()
  153. },
  154. success: (res) => {
  155. /// 解析对象
  156. const data = JSON.parse(res.data.data)
  157. if (data.RetCode != 0) {
  158. hideLoading(() => {}, getErrorMsg(data.RetCode))
  159. return
  160. }
  161. /// 对其进行操作
  162. isMyFavorite(wrtradeorderid) ? removeMyFavorite(wrtradeorderid) : addMyFavotite(wrtradeorderid)
  163. /// 操作成功
  164. hideLoading(()=>{
  165. /// 更新数据
  166. wx.startPullDownRefresh()
  167. }, '请求成功'+res.msg, 'success')
  168. },
  169. fail: (emsg) => {
  170. /// 操作失败
  171. hideLoading(()=>{}, emsg)
  172. },
  173. complete: () => {
  174. wx.stopPullDownRefresh()
  175. }
  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. sellOrders: res.data.map(itm => {
  229. var obj = itm
  230. obj.zscuttype1display = isnullstr(itm.zscuttype1display)
  231. obj.zspolishtype1display = isnullstr(itm.zspolishtype1display)
  232. obj.zsfluorescencetype1display = isnullstr(itm.zsfluorescencetype1display)
  233. obj.zssymmetrytype1display = isnullstr(itm.zssymmetrytype1display)
  234. obj.favorite = isMyFavorite(obj.wrtradeorderid)
  235. return obj
  236. })
  237. })
  238. })
  239. },
  240. fail: (emsg) => {
  241. /// 加载失败
  242. hideLoading(()=>{}, emsg)
  243. },
  244. complete: () => {
  245. /// 停止下拉刷新
  246. wx.stopPullDownRefresh()
  247. }
  248. })
  249. })
  250. },
  251. /// 查询求购大厅委托单
  252. queryBuyOrder() {
  253. /// loding.....
  254. showLoading(()=>{
  255. /// loding....
  256. queryBuyOrder({
  257. data: {
  258. /// 模糊搜索
  259. zsallproperties: this.data.zsallproperties
  260. },
  261. /// 加载成功
  262. success: (res) => {
  263. if (res.code != 200) {
  264. /// 加载失败
  265. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  266. return
  267. }
  268. hideLoading(()=>{
  269. /// 数据赋值
  270. this.setData({
  271. isEmpty: res.data.length === 0,
  272. askOrders: res.data.map(itm => {
  273. var obj = itm
  274. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  275. obj.zssize = itm.zssize.replace(',', '-')
  276. obj.zsfluorescencetypedisplay = isnullstr(itm.zsfluorescencetypedisplay)
  277. obj.zssymmetrytypedisplay = isnullstr(itm.zssymmetrytypedisplay)
  278. obj.zsclaritytypedisplay = isnullstr(itm.zsclaritytypedisplay)
  279. obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay)
  280. obj.zscolortypedisplay = isnullstr(itm.zscolortypedisplay)
  281. obj.zspolishtypedisplay = isnullstr(itm.zspolishtypedisplay)
  282. obj.zssize = isnullstr(itm.zssize)
  283. return obj
  284. })
  285. })
  286. })
  287. },
  288. fail: (emsg) => {
  289. /// 加载失败
  290. hideLoading(()=>{}, emsg)
  291. },
  292. complete: () => {
  293. /// 停止下拉刷新
  294. wx.stopPullDownRefresh()
  295. }
  296. })
  297. })
  298. },
  299. /**
  300. * 生命周期函数--监听页面加载
  301. */
  302. onLoad() {
  303. /// 显示默认数据
  304. this.setData({
  305. /// 形状
  306. shapes: [{ value: 0, text: '形状' }].concat(getEnumList('ZSShapeType').map(obj => {
  307. return {
  308. value: obj.enumitemname,
  309. text: obj.enumdicname
  310. }
  311. })),
  312. /// 净度
  313. claritys: [{ value: 0, text: '净度' }].concat(getEnumList('ZSClarityType').map(obj => {
  314. return {
  315. value: obj.enumitemname,
  316. text: obj.enumdicname
  317. }
  318. })),
  319. /// 切工
  320. cuts: [{ value: 0, text: '切工' }].concat(getEnumList('ZSCutType').map(obj => {
  321. return {
  322. value: obj.enumitemname,
  323. text: obj.enumdicname
  324. }
  325. })),
  326. /// 荧光
  327. fluorescences: [{ value: 0, text: '荧光' }].concat(getEnumList('ZSFluorescenceType').map(obj => {
  328. return {
  329. value: obj.enumitemname,
  330. text: obj.enumdicname
  331. }
  332. })),
  333. })
  334. /// 查询数据
  335. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  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: Number(wx.getStorageSync('trade_active')) })
  357. },
  358. /**
  359. * 生命周期函数--监听页面初次渲染完成
  360. */
  361. onReady() {
  362. },
  363. /**
  364. * 生命周期函数--监听页面隐藏
  365. */
  366. onHide() {
  367. },
  368. /**
  369. * 生命周期函数--监听页面卸载
  370. */
  371. onUnload() {
  372. },
  373. /**
  374. * 页面相关事件处理函数--监听用户下拉动作
  375. */
  376. onPullDownRefresh() {
  377. /// 查询数据
  378. this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
  379. },
  380. /**
  381. * 页面上拉触底事件的处理函数
  382. */
  383. onReachBottom() {
  384. },
  385. /**
  386. * 用户点击右上角分享
  387. */
  388. onShareAppMessage() {
  389. }
  390. })