index.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import { EOrderSrc, EValidType } from "../../../constants/enum/index";
  2. import { FunCode } from "../../../constants/enum/funcode";
  3. import { sendMsgToMQ } from "../../../services/api/common/index";
  4. import { accountid, clientType, getErrorMsg, isEncrypted, marketid, protoHeader, timetample, userid } from "../../../services/utils";
  5. import { hideLoading, showLoading, showModel } from "../../../utils/message/index";
  6. import { isnullstr } from "../../../utils/util";
  7. import { queryMySellOrder, queryPermancePlanTmp } from "../../../services/api/orders/index";
  8. import { encryptBody } from "../../../utils/websocket/crypto";
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. /// 底部安全区域
  15. safeBottom: getApp().globalData.safeBottom,
  16. /// tabs
  17. tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}],
  18. /// tab索引
  19. active: 0,
  20. /// 出售挂牌
  21. sellorders: <GuangZuan.MySellOrder[]>[],
  22. /// 选中的单据
  23. sellorder: <GuangZuan.MySellOrder>({}),
  24. /// 列头
  25. titles: [['重量', '形状', '尺寸', '编号'],
  26. ['颜色 | 净度 | 切工 | 抛光 | 对称 | 荧光 | 证书', '价格']],
  27. /// 显示的值
  28. values: [{ up: [''], dwn: [''], isChecked: false }],
  29. /// 是否空数据
  30. isEmpty: false,
  31. /// 当前页
  32. page: 1,
  33. /// 履约模板信息
  34. tmps: <GuangZuan.PermancePlanTmp[]>[],
  35. /// 选中履约模板
  36. tmp: <GuangZuan.PermancePlanTmp>({}),
  37. /// 是否显示
  38. show: false,
  39. /// 显示信息
  40. actions: [''],
  41. /// 颜色
  42. colors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown']
  43. },
  44. /**
  45. * 返回上层视图
  46. */
  47. backToParent() {
  48. /// 返回上层视图
  49. wx.navigateBack()
  50. },
  51. /// 显示履约模板
  52. showPlanTmps() {
  53. this.setData({ show: true })
  54. },
  55. /// 关闭
  56. onClose() {
  57. this.setData({ show: false })
  58. },
  59. onSelect(e: any) {
  60. /// 默认显示项
  61. const { index } = e.detail;
  62. this.setData({ tmp: this.data.tmps[index], show: false })
  63. },
  64. /**
  65. * 每行选中触发事件
  66. */
  67. onSelectItem(e: any) {
  68. var objs = this.data.values
  69. objs.forEach(obj => {
  70. obj.isChecked = false
  71. })
  72. objs[e.currentTarget.id].isChecked = true
  73. /// 数据赋值
  74. this.setData({
  75. values: objs,
  76. sellorder: this.data.sellorders[e.currentTarget.id]
  77. })
  78. },
  79. /**
  80. * tab触发事件
  81. */
  82. onTabChange(e: any) {
  83. /// 设置激活项
  84. this.setData({
  85. active: e.detail.index,
  86. /// 设置列头
  87. titles: this.data.tabs[e.detail.index].id === 2 ? [['重量', '形状', '尺寸', '编号'],
  88. ['颜色 | 净度 | 切工 | 抛光 | 对称 | 荧光 | 证书', '价格']] : [['重量', '形状', '尺寸', '编号'],
  89. ['颜色 | 净度 | 抛光 | 对称 | 荧光 | 证书', '价格']],
  90. })
  91. /// 查询单据信息
  92. this.queryMySellOrder()
  93. },
  94. /// 获取履约模板信息
  95. queryPermancePlanTmp() {
  96. /// showLoading
  97. showLoading(() => {
  98. queryPermancePlanTmp({
  99. success: (res) => {
  100. /// 获取数据
  101. this.setData({
  102. tmps: res.data,
  103. tmp: res.data[0],
  104. actions: res.data.map(obj => { return obj.templatename })
  105. })
  106. },
  107. complete: () => {
  108. /// hideLoading
  109. hideLoading()
  110. /// 停止下拉刷新
  111. wx.stopPullDownRefresh()
  112. }
  113. })
  114. })
  115. },
  116. /// 查询出售挂牌
  117. queryMySellOrder() {
  118. /// loding
  119. showLoading(()=>{
  120. /// 数据查询请求
  121. queryMySellOrder({
  122. data: {
  123. userid: userid(),
  124. zscategorys: this.data.tabs[this.data.active].id.toString()
  125. },
  126. success: (res) => {
  127. /// 请求失败
  128. if (res.code != 200) {
  129. /// 加载失败
  130. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  131. return
  132. }
  133. hideLoading(()=>{
  134. /// 设置数据
  135. this.setData({
  136. /// 设置列头
  137. sellorders: res.data,
  138. isEmpty: res.data.length === 0,
  139. active: 0,
  140. /// 显示的值
  141. values: res.data.map(obj => {
  142. return this.data.tabs[this.data.active].id === 2 ? { up: [obj.totalqty+'ct',
  143. isnullstr(obj.zsshapetypedisplay),
  144. isnullstr(obj.sizedisplay),
  145. obj.goodsno],
  146. dwn: [isnullstr(obj.zscolortype1display)+' | '+
  147. isnullstr(obj.zsclaritytype1display)+' | '+
  148. isnullstr(obj.zscuttype1display)+' | '+
  149. isnullstr(obj.zspolishtype1display)+' | '+
  150. isnullstr(obj.zssymmetrytype1display)+' | '+
  151. isnullstr(obj.zsfluorescencetype1display)+' | '+
  152. isnullstr(obj.zscerttypedisplay),
  153. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)],
  154. isChecked: false } : { up: [obj.totalqty+'ct',
  155. isnullstr(obj.zsshapetypedisplay),
  156. isnullstr(obj.sizedisplay),
  157. obj.goodsno],
  158. dwn: [isnullstr(obj.zsczcolor1typedisplay)+' | '+
  159. isnullstr(obj.zsclaritytype1display)+' | '+
  160. isnullstr(obj.zspolishtype1display)+' | '+
  161. isnullstr(obj.zssymmetrytype1display)+' | '+
  162. isnullstr(obj.zsfluorescencetype1display)+' | '+
  163. isnullstr(obj.zscerttypedisplay),
  164. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)],
  165. isChecked: false }
  166. })
  167. })
  168. })
  169. },
  170. fail: (emsg) => {
  171. /// 加载失败
  172. hideLoading(()=>{}, emsg)
  173. },
  174. complete: () => {
  175. /// 停止下拉刷新
  176. wx.stopPullDownRefresh()
  177. }
  178. })
  179. })
  180. },
  181. /// 摘卖
  182. doListingSell() {
  183. /// showModel
  184. showModel(() => {
  185. /// showLoading
  186. showLoading(() => {
  187. const { wrstandardid, wrfactortypeid, totalqty } = this.data.sellorder
  188. const { autoid } = this.data.tmp
  189. /// 请求参数
  190. const info = JSON.stringify({
  191. Header: protoHeader(FunCode.ZSSellOrderListingReq),
  192. UserID: userid(),
  193. AccountID: accountid(),
  194. WRStandardID: wrstandardid,
  195. WRFactorTypeID: wrfactortypeid,
  196. OrderQty: totalqty,
  197. PerformanceTemplateID: autoid,
  198. TimevalidType: EValidType.VALIDTYPE_YZ,
  199. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  200. ClientSerialNo: timetample().toString(),
  201. ClientType: clientType(),
  202. MarketID: marketid(),
  203. })
  204. /// 发送请求
  205. sendMsgToMQ({
  206. data: {
  207. data: encryptBody(info),
  208. funCodeReq: FunCode.ZSSellOrderListingReq,
  209. funCodeRsp: FunCode.ZSSellOrderListingRsp,
  210. isEncrypted: isEncrypted()
  211. },
  212. success: (res) => {
  213. /// 解析对象
  214. const data = JSON.parse(res.data.data)
  215. if (data.RetCode != 0) {
  216. hideLoading(() => {}, getErrorMsg(data.RetCode))
  217. return
  218. }
  219. /// 求购发布请求成功
  220. hideLoading(() => {
  221. wx.navigateBack()
  222. }, '出售发布请求成功', 'success')
  223. },
  224. fail: (emsg) => {
  225. hideLoading(()=>{}, emsg)
  226. }
  227. })
  228. }, '出售请求中....')
  229. }, '提示', '确认要发布出售吗?')
  230. },
  231. /**
  232. * 生命周期函数--监听页面加载
  233. */
  234. onLoad() {
  235. /// 查询我的出售
  236. this.queryMySellOrder()
  237. /// 获取履约模板信息
  238. this.queryPermancePlanTmp()
  239. },
  240. /**
  241. * 生命周期函数--监听页面初次渲染完成
  242. */
  243. onReady() {
  244. },
  245. /**
  246. * 生命周期函数--监听页面显示
  247. */
  248. onShow() {
  249. },
  250. /**
  251. * 生命周期函数--监听页面隐藏
  252. */
  253. onHide() {
  254. },
  255. /**
  256. * 生命周期函数--监听页面卸载
  257. */
  258. onUnload() {
  259. },
  260. /**
  261. * 页面相关事件处理函数--监听用户下拉动作
  262. */
  263. onPullDownRefresh() {
  264. /// 查询我的出售
  265. this.queryMySellOrder()
  266. /// 获取履约模板信息
  267. this.queryPermancePlanTmp()
  268. },
  269. /**
  270. * 页面上拉触底事件的处理函数
  271. */
  272. onReachBottom() {
  273. },
  274. /**
  275. * 用户点击右上角分享
  276. */
  277. onShareAppMessage() {
  278. }
  279. })