index.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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({ active: e.detail.index })
  85. /// 查询单据信息
  86. this.queryMySellOrder()
  87. },
  88. /// 获取履约模板信息
  89. queryPermancePlanTmp() {
  90. /// showLoading
  91. showLoading(() => {
  92. queryPermancePlanTmp({
  93. success: (res) => {
  94. /// 获取数据
  95. this.setData({
  96. tmps: res.data,
  97. tmp: res.data[0],
  98. actions: res.data.map(obj => { return obj.templatename })
  99. })
  100. },
  101. complete: () => {
  102. /// hideLoading
  103. hideLoading()
  104. /// 停止下拉刷新
  105. wx.stopPullDownRefresh()
  106. }
  107. })
  108. })
  109. },
  110. /// 查询出售挂牌
  111. queryMySellOrder() {
  112. /// loding
  113. showLoading(()=>{
  114. /// 数据查询请求
  115. queryMySellOrder({
  116. data: {
  117. userid: userid(),
  118. zscategorys: this.data.tabs[this.data.active].id.toString()
  119. },
  120. success: (res) => {
  121. /// 请求失败
  122. if (res.code != 200) {
  123. /// 加载失败
  124. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  125. return
  126. }
  127. hideLoading(()=>{
  128. /// 设置数据
  129. this.setData({
  130. /// 设置列头
  131. sellorders: res.data,
  132. isEmpty: res.data.length === 0,
  133. active: 0,
  134. /// 显示的值
  135. values: res.data.map(obj => {
  136. return { up: [obj.totalqty+'ct',
  137. isnullstr(obj.zsshapetypedisplay),
  138. isnullstr(obj.sizedisplay),
  139. obj.goodsno],
  140. dwn: [isnullstr(obj.zsczcolor1typedisplay)+' | '+
  141. isnullstr(obj.zsclaritytype1display)+' | '+
  142. isnullstr(obj.zscuttype1display)+' | '+
  143. isnullstr(obj.zspolishtype1display)+' | '+
  144. isnullstr(obj.zssymmetrytype1display)+' | '+
  145. isnullstr(obj.zsfluorescencetype1display)+' | '+
  146. isnullstr(obj.zscerttypedisplay),
  147. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)],
  148. isChecked: false}
  149. })
  150. })
  151. })
  152. },
  153. fail: (emsg) => {
  154. /// 加载失败
  155. hideLoading(()=>{}, emsg)
  156. },
  157. complete: () => {
  158. /// 停止下拉刷新
  159. wx.stopPullDownRefresh()
  160. }
  161. })
  162. })
  163. },
  164. /// 摘卖
  165. doListingSell() {
  166. /// showModel
  167. showModel(() => {
  168. /// showLoading
  169. showLoading(() => {
  170. const { wrstandardid, wrfactortypeid, totalqty } = this.data.sellorder
  171. const { autoid } = this.data.tmp
  172. /// 请求参数
  173. const info = JSON.stringify({
  174. Header: protoHeader(FunCode.ZSSellOrderListingReq),
  175. UserID: userid(),
  176. AccountID: accountid(),
  177. WRStandardID: wrstandardid,
  178. WRFactorTypeID: wrfactortypeid,
  179. OrderQty: totalqty,
  180. PerformanceTemplateID: autoid,
  181. TimevalidType: EValidType.VALIDTYPE_YZ,
  182. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  183. ClientSerialNo: timetample().toString(),
  184. ClientType: clientType(),
  185. MarketID: marketid(),
  186. })
  187. /// 发送请求
  188. sendMsgToMQ({
  189. data: {
  190. data: encryptBody(info),
  191. funCodeReq: FunCode.ZSSellOrderListingReq,
  192. funCodeRsp: FunCode.ZSSellOrderListingRsp,
  193. isEncrypted: isEncrypted()
  194. },
  195. success: (res) => {
  196. /// 解析对象
  197. const data = JSON.parse(res.data.data)
  198. if (data.RetCode != 0) {
  199. hideLoading(() => {}, getErrorMsg(data.RetCode))
  200. return
  201. }
  202. /// 求购发布请求成功
  203. hideLoading(() => {
  204. wx.navigateBack()
  205. }, '出售发布请求成功', 'success')
  206. },
  207. fail: (emsg) => {
  208. hideLoading(()=>{}, emsg)
  209. }
  210. })
  211. }, '出售请求中....')
  212. }, '提示', '确认要发布出售吗?')
  213. },
  214. /**
  215. * 生命周期函数--监听页面加载
  216. */
  217. onLoad() {
  218. /// 查询我的出售
  219. this.queryMySellOrder()
  220. /// 获取履约模板信息
  221. this.queryPermancePlanTmp()
  222. },
  223. /**
  224. * 生命周期函数--监听页面初次渲染完成
  225. */
  226. onReady() {
  227. },
  228. /**
  229. * 生命周期函数--监听页面显示
  230. */
  231. onShow() {
  232. },
  233. /**
  234. * 生命周期函数--监听页面隐藏
  235. */
  236. onHide() {
  237. },
  238. /**
  239. * 生命周期函数--监听页面卸载
  240. */
  241. onUnload() {
  242. },
  243. /**
  244. * 页面相关事件处理函数--监听用户下拉动作
  245. */
  246. onPullDownRefresh() {
  247. /// 查询我的出售
  248. this.queryMySellOrder()
  249. /// 获取履约模板信息
  250. this.queryPermancePlanTmp()
  251. },
  252. /**
  253. * 页面上拉触底事件的处理函数
  254. */
  255. onReachBottom() {
  256. },
  257. /**
  258. * 用户点击右上角分享
  259. */
  260. onShareAppMessage() {
  261. }
  262. })