index.ts 7.3 KB

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