index.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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, saveTradeActive, timetample, userid } from "../../../services/utils";
  5. import { hideLoading, showLoading, showModel } from "../../../utils/message/index";
  6. import { formatDateString, isnullstr } from "../../../utils/util";
  7. import { queryMyWRPosition, 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. dataList: <GuangZuan.MyWRPosition[]>[],
  22. /// 选中的单据
  23. postion: <GuangZuan.MyWRPosition>({}),
  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', '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 => { obj.isChecked = false })
  70. objs[e.currentTarget.id].isChecked = true
  71. /// 数据赋值
  72. this.setData({
  73. values: objs,
  74. postion: this.data.dataList[e.currentTarget.id]
  75. })
  76. },
  77. /**
  78. * tab触发事件
  79. */
  80. onTabChange(e: any) {
  81. /// 设置激活项
  82. this.setData({
  83. active: e.detail.index,
  84. /// 设置列头
  85. titles: this.data.tabs[e.detail.index].id === 2 ? [['重量', '形状', '尺寸', '编号'],
  86. ['颜色 | 净度 | 切工 | 抛光 | 对称 | 荧光 | 证书', '价格']] : [['重量', '形状', '尺寸', '编号'],
  87. ['颜色 | 净度 | 抛光 | 对称 | 荧光 | 证书', '价格']],
  88. })
  89. /// 查询单据信息
  90. this.queryMyWRPosition()
  91. },
  92. /// 获取履约模板信息
  93. queryPermancePlanTmp() {
  94. /// showLoading
  95. showLoading(() => {
  96. queryPermancePlanTmp({
  97. success: (res) => {
  98. /// 获取数据
  99. this.setData({
  100. tmps: res.data,
  101. tmp: res.data[0],
  102. actions: res.data.map(obj => { return obj.templatename })
  103. })
  104. },
  105. complete: () => {
  106. /// hideLoading
  107. hideLoading()
  108. /// 停止下拉刷新
  109. wx.stopPullDownRefresh()
  110. }
  111. })
  112. })
  113. },
  114. /// 查询我的库存
  115. queryMyWRPosition() {
  116. /// loding
  117. showLoading(()=>{
  118. /// 数据查询请求
  119. queryMyWRPosition({
  120. data: {
  121. wruserid: userid(),
  122. zscategorys: this.data.tabs[this.data.active].id.toString(),
  123. },
  124. success: (res) => {
  125. /// 请求失败
  126. if (res.code != 200) {
  127. /// 加载失败
  128. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  129. return
  130. }
  131. hideLoading(()=>{
  132. /// 设置数据
  133. this.setData({
  134. /// 设置列头
  135. dataList: res.data.filter(e => { return e.marketflag != 1 }),
  136. isEmpty: res.data.length === 0,
  137. active: 0,
  138. /// 显示的值
  139. values: res.data.filter(e => { return e.marketflag != 1 }).map(obj => {
  140. return this.data.tabs[this.data.active].id === 2 ? { up: [obj.ftotalqty+'ct',
  141. isnullstr(obj.zsshapetypedisplay),
  142. isnullstr(obj.sizedisplay),
  143. obj.goodsno],
  144. dwn: [isnullstr(obj.zscolortype1display)+' | '+
  145. isnullstr(obj.zsclaritytype1display)+' | '+
  146. isnullstr(obj.zscuttype1display)+' | '+
  147. isnullstr(obj.zspolishtype1display)+' | '+
  148. isnullstr(obj.zssymmetrytype1display)+' | '+
  149. isnullstr(obj.zsfluorescencetype1display)+' | '+
  150. isnullstr(obj.zscerttypedisplay),
  151. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)],
  152. isChecked: false } : { up: [obj.ftotalqty+'ct',
  153. isnullstr(obj.zsshapetypedisplay),
  154. isnullstr(obj.sizedisplay),
  155. obj.goodsno],
  156. dwn: [isnullstr(obj.zsczcolor3typedisplay)+' | '+
  157. isnullstr(obj.zsclaritytype1display)+' | '+
  158. isnullstr(obj.zspolishtype1display)+' | '+
  159. isnullstr(obj.zssymmetrytype1display)+' | '+
  160. isnullstr(obj.zsfluorescencetype1display)+' | '+
  161. isnullstr(obj.zscerttypedisplay),
  162. obj.zscurrencytypedisplayunit+obj.price.toFixed(2)],
  163. isChecked: false }
  164. })
  165. })
  166. })
  167. },
  168. fail: (emsg) => {
  169. /// 加载失败
  170. hideLoading(()=>{}, emsg)
  171. },
  172. complete: () => {
  173. /// 停止下拉刷新
  174. wx.stopPullDownRefresh()
  175. }
  176. })
  177. })
  178. },
  179. /// 摘卖
  180. doListingSell() {
  181. /// showModel
  182. showModel(() => {
  183. /// showLoading
  184. showLoading(() => {
  185. const { wrstandardid, ftotalqty, ladingbillid, subnum } = this.data.postion
  186. const { autoid } = this.data.tmp
  187. /// 请求参数
  188. const info = JSON.stringify({
  189. Header: protoHeader(FunCode.ZSSellOrderListingReq, marketID(67)),
  190. UserID: userid(),
  191. AccountID: accountid(),
  192. WRStandardID: wrstandardid,
  193. // WRFactorTypeID: wrfactortypeid,
  194. LadingBillID: ladingbillid,
  195. SubNum: subnum,
  196. OrderQty: ftotalqty,
  197. PerformanceTemplateID: autoid,
  198. TimevalidType: EValidType.VALIDTYPE_YZ,
  199. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  200. ClientSerialNo: timetample().toString(),
  201. ClientType: clientType(),
  202. MarketID: marketID(67),
  203. ClientOrderTime: formatDateString(new Date().toString())
  204. })
  205. /// 发送请求
  206. sendMsgToMQ({
  207. data: {
  208. data: encryptBody(info),
  209. funCodeReq: FunCode.ZSSellOrderListingReq,
  210. funCodeRsp: FunCode.ZSSellOrderListingRsp,
  211. isEncrypted: isEncrypted()
  212. },
  213. success: (res) => {
  214. /// 解析对象
  215. const data = JSON.parse(res.data.data)
  216. if (data.RetCode != 0) {
  217. hideLoading(() => {}, getErrorMsg(data.RetCode))
  218. return
  219. }
  220. /// 求购发布请求成功
  221. hideLoading(() => {
  222. saveTradeActive(0)
  223. wx.navigateBack()
  224. }, '出售发布请求成功', 'success')
  225. },
  226. fail: (emsg) => {
  227. hideLoading(()=>{}, emsg)
  228. }
  229. })
  230. }, '出售请求中....')
  231. }, '提示', '确认要发布出售吗?')
  232. },
  233. /**
  234. * 生命周期函数--监听页面加载
  235. */
  236. onLoad() {
  237. /// 查询我的出售
  238. this.queryMyWRPosition()
  239. /// 获取履约模板信息
  240. this.queryPermancePlanTmp()
  241. },
  242. /**
  243. * 生命周期函数--监听页面初次渲染完成
  244. */
  245. onReady() {
  246. },
  247. /**
  248. * 生命周期函数--监听页面显示
  249. */
  250. onShow() {
  251. },
  252. /**
  253. * 生命周期函数--监听页面隐藏
  254. */
  255. onHide() {
  256. },
  257. /**
  258. * 生命周期函数--监听页面卸载
  259. */
  260. onUnload() {
  261. },
  262. /**
  263. * 页面相关事件处理函数--监听用户下拉动作
  264. */
  265. onPullDownRefresh() {
  266. /// 查询我的出售
  267. this.queryMyWRPosition()
  268. /// 获取履约模板信息
  269. this.queryPermancePlanTmp()
  270. },
  271. /**
  272. * 页面上拉触底事件的处理函数
  273. */
  274. onReachBottom() {
  275. },
  276. /**
  277. * 用户点击右上角分享
  278. */
  279. onShareAppMessage() {
  280. }
  281. })