index.ts 7.5 KB

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