index.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. import { EOrderSrc } from "../../../constants/enum/index";
  2. import { FunCode } from "../../../constants/enum/funcode";
  3. import { sendMsgToMQ } from "../../../services/api/common/index";
  4. import { accountid, clientType, getEnumList, getErrorMsg, isEncrypted, marketid, protoHeader, timetample, userid } from "../../../services/utils";
  5. import { hideLoading, showLoading, showModel, showToast } from "../../../utils/message/index";
  6. import { queryPermancePlanTmp } from "../../../services/api/orders/index";
  7. import { encryptBody } from "../../../utils/websocket/crypto";
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. /// 底部安全区域
  14. safeBottom: getApp().globalData.safeBottom,
  15. /// 颜色
  16. tcolors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown'],
  17. /// tabs
  18. tabs: [{ id: 2, name: '单颗裸钻' }, { id: 5, name: '单颗彩钻' }],
  19. /// tab索引
  20. active: 0,
  21. /// 币种信息
  22. currencys: [{ value: 1, text: '人民币' }],
  23. /// 币种类型
  24. currency: 1,
  25. /// 形状
  26. shapes: [{ id: 1, name: '圆形', isCheck: true }],
  27. /// 选中形状
  28. shape: 1,
  29. /// 颜色
  30. colors: [{ value: 1, text: 'D' }],
  31. /// 选中颜色1
  32. color1: 1,
  33. /// 选中颜色2
  34. color2: 1,
  35. /// 切工
  36. qiegongs: [{ value: 1, text: 'EX' }],
  37. /// 选中切工1
  38. qiegong1: 1,
  39. /// 选中切工2
  40. qiegong2: 1,
  41. /// 对称
  42. duichengs: [{ value: 1, text: 'EX' }],
  43. /// 选中对称1
  44. duicheng1: 1,
  45. /// 选中对称2
  46. duicheng2: 2,
  47. /// 抛光
  48. paoguangs: [{ value: 1, text: 'EX' }],
  49. /// 选中抛光1
  50. paoguang1: 1,
  51. /// 选中抛光2
  52. paoguang2: 2,
  53. /// 莹光
  54. yingguangs: [{ value: 1, text: 'N' }],
  55. /// 选中莹光1
  56. yingguang1: 1,
  57. /// 选中莹光2
  58. yingguang2: 2,
  59. /// 净度
  60. neatness: [{ value: 1, text: 'FL/IF' }],
  61. /// 选中净度1
  62. neatnes1: 1,
  63. /// 选中净度2
  64. neatnes2: 1,
  65. /// 履约模板信息
  66. tmps: <GuangZuan.PermancePlanTmp[]>[],
  67. /// 选中履约模板
  68. tmp: <GuangZuan.PermancePlanTmp>({}),
  69. /// 是否显示
  70. show: false,
  71. /// 显示信息
  72. actions: [''],
  73. /// 最小尺寸
  74. minSize: 0.0,
  75. /// 最大尺寸
  76. maxSize: 0.0
  77. },
  78. /**
  79. * tab触发事件
  80. */
  81. onTabChange(e: any) {
  82. /// 激活项
  83. this.setData({ active: e.detail.index })
  84. },
  85. /// 单选框
  86. onChange(e: any) {
  87. switch (e.target.id) {
  88. default: break;
  89. }
  90. },
  91. /**
  92. * 返回上层视图
  93. */
  94. backToParent() {
  95. /// 返回上层视图
  96. wx.navigateBack()
  97. },
  98. /// 形状按钮点击事件
  99. onButtonPressed(e: any) {
  100. const ids = (<string> e.target.id).split(' ')
  101. let id = (<string> e.target.id).split(' ')[0]
  102. const index = <number> <unknown>ids[1]
  103. switch (id) {
  104. case 'shape': /// 形状
  105. this.setData({ shapes: this.data.shapes.map(item => {
  106. if (item.id == index) {
  107. if (item.isCheck) {
  108. item.isCheck = false
  109. } else {
  110. item.isCheck = true
  111. }
  112. }
  113. return item
  114. }) })
  115. break;
  116. default:
  117. break;
  118. }
  119. },
  120. /// 显示履约模板
  121. showPlanTmps() {
  122. this.setData({ show: true })
  123. },
  124. /// 关闭
  125. onClose() {
  126. this.setData({ show: false })
  127. },
  128. onSelect(e: any) {
  129. /// 默认显示项
  130. const { index } = e.detail;
  131. this.setData({ tmp: this.data.tmps[index], show: false })
  132. },
  133. onRadioChange() {},
  134. /// 重量范围值更改
  135. syncNumRange(e: any) {
  136. this.setData({
  137. minSize: e.detail.value[0],
  138. maxSize: e.detail.value[1],
  139. })
  140. },
  141. /// 获取履约模板信息
  142. queryPermancePlanTmp() {
  143. /// showLoading
  144. showLoading(() => {
  145. queryPermancePlanTmp({
  146. success: (res) => {
  147. /// 获取数据
  148. this.setData({
  149. tmps: res.data,
  150. tmp: res.data[0],
  151. actions: res.data.map(obj => { return obj.templatename })
  152. })
  153. },
  154. complete: () => {
  155. /// hideLoading
  156. hideLoading()
  157. }
  158. })
  159. })
  160. },
  161. /// 发布求购
  162. doListingBuy() {
  163. /// showModel
  164. showModel(() => {
  165. /// showLoading
  166. showLoading(() => {
  167. /// 钻石属性
  168. const exinfo = {
  169. UserID: userid(),
  170. AccountID: accountid(),
  171. ZSCategory: this.data.tabs[this.data.active].id,
  172. ZSCurrencyType: [this.data.currency],
  173. ZSShapeType: [this.data.shape],
  174. ZSColorType: [this.data.color1, this.data.color2],
  175. ZSClarityType: [this.data.neatnes1, this.data.neatnes2],
  176. ZSCutType: [this.data.qiegong1, this.data.qiegong2],
  177. ZSSymmetryType: [this.data.duicheng1, this.data.duicheng2],
  178. ZSPolishType: [this.data.paoguang1, this.data.paoguang2],
  179. ZSFluorescenceType: [this.data.yingguang1, this.data.yingguang2],
  180. Size: [this.data.minSize, this.data.maxSize],
  181. ZSCZColor1Type: [this.data.color1, this.data.color2],
  182. }
  183. /// 请求参数
  184. const info = JSON.stringify({
  185. Header: protoHeader(FunCode.ZSBuyOrderListingReq),
  186. UserID: userid(),
  187. AccountID: accountid(),
  188. GZ_BuyOrderDetailExInfo: exinfo,
  189. PerformanceTemplateID: this.data.tmp.autoid,
  190. MarketID: marketid(),
  191. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  192. ClientType: clientType(),
  193. ClientSerialNo: timetample().toString()
  194. })
  195. /// 发送请求
  196. sendMsgToMQ({
  197. data: {
  198. data: encryptBody(info),
  199. funCodeReq: FunCode.ZSBuyOrderListingReq,
  200. funCodeRsp: FunCode.ZSBuyOrderListingRsp,
  201. isEncrypted: isEncrypted()
  202. },
  203. success: (res) => {
  204. /// 解析对象
  205. const data = JSON.parse(res.data.data)
  206. if (data.RetCode != 0) {
  207. hideLoading(() => {}, getErrorMsg(data.RetCode))
  208. return
  209. }
  210. /// 求购发布请求成功
  211. hideLoading(() => {
  212. wx.navigateBack()
  213. }, '求购发布请求成功', 'success')
  214. },
  215. fail: (emsg) => {
  216. hideLoading(()=>{}, emsg)
  217. }
  218. })
  219. }, '求购请求中....')
  220. }, '提示', '确认要发布求购吗?')
  221. },
  222. /// 合规性校验
  223. check(): boolean {
  224. /// 请选择形状
  225. if (this.data.shape === 0) {
  226. showToast('请选择形状')
  227. return false
  228. }
  229. return true
  230. },
  231. /**
  232. * 生命周期函数--监听页面加载
  233. */
  234. onLoad() {
  235. this.setData({
  236. /// 形状
  237. shapes: getEnumList('ZSShapeType').map(obj => {
  238. return {
  239. id: obj.enumitemname,
  240. name: obj.enumdicname,
  241. isCheck: obj.enumitemname === this.data.shape
  242. }
  243. }),
  244. shape: getEnumList('ZSShapeType')[0].enumitemname,
  245. /// 颜色
  246. colors: getEnumList('ZSColorType').map(obj => {
  247. return {
  248. value: obj.enumitemname,
  249. text: obj.enumdicname
  250. }
  251. }),
  252. color1: getEnumList('ZSColorType')[0].enumitemname,
  253. color2: getEnumList('ZSColorType')[0].enumitemname,
  254. /// 净度
  255. neatness: getEnumList('ZSClarityType').map(obj => {
  256. return {
  257. value: obj.enumitemname,
  258. text: obj.enumdicname
  259. }
  260. }),
  261. neatnes1: getEnumList('ZSClarityType')[0].enumitemname,
  262. neatnes2: getEnumList('ZSClarityType')[0].enumitemname,
  263. /// 切工
  264. qiegongs: getEnumList('ZSCutType').map(obj => {
  265. return {
  266. value: obj.enumitemname,
  267. text: obj.enumdicname
  268. }
  269. }),
  270. qiegong1: getEnumList('ZSCutType')[0].enumitemname,
  271. qiegong2: getEnumList('ZSCutType')[0].enumitemname,
  272. /// 对称
  273. duichengs: getEnumList('ZSSymmetryType').map(obj => {
  274. return {
  275. value: obj.enumitemname,
  276. text: obj.enumdicname
  277. }
  278. }),
  279. duicheng1: getEnumList('ZSSymmetryType')[0].enumitemname,
  280. duicheng2: getEnumList('ZSSymmetryType')[0].enumitemname,
  281. /// 抛光
  282. paoguangs: getEnumList('ZSPolishType').map(obj => {
  283. return {
  284. value: obj.enumitemname,
  285. text: obj.enumdicname
  286. }
  287. }),
  288. paoguang1: getEnumList('ZSPolishType')[0].enumitemname,
  289. paoguang2: getEnumList('ZSPolishType')[0].enumitemname,
  290. /// 荧光
  291. yingguangs: getEnumList('ZSFluorescenceType').map(obj => {
  292. return {
  293. value: obj.enumitemname,
  294. text: obj.enumdicname
  295. }
  296. }),
  297. yingguang1: getEnumList('ZSFluorescenceType')[0].enumitemname,
  298. yingguang2: getEnumList('ZSFluorescenceType')[0].enumitemname,
  299. /// 币种信息
  300. currencys: getEnumList('ZSCurrencyType').map(obj => {
  301. return {
  302. value: obj.enumitemname,
  303. text: obj.enumdicname
  304. }
  305. }),
  306. currency: getEnumList('ZSCurrencyType')[0].enumitemname,
  307. })
  308. /// 获取履约模板信息
  309. this.queryPermancePlanTmp()
  310. },
  311. /**
  312. * 生命周期函数--监听页面初次渲染完成
  313. */
  314. onReady() {
  315. },
  316. /**
  317. * 生命周期函数--监听页面显示
  318. */
  319. onShow() {
  320. },
  321. /**
  322. * 生命周期函数--监听页面隐藏
  323. */
  324. onHide() {
  325. },
  326. /**
  327. * 生命周期函数--监听页面卸载
  328. */
  329. onUnload() {
  330. },
  331. /**
  332. * 页面相关事件处理函数--监听用户下拉动作
  333. */
  334. onPullDownRefresh() {
  335. },
  336. /**
  337. * 页面上拉触底事件的处理函数
  338. */
  339. onReachBottom() {
  340. },
  341. /**
  342. * 用户点击右上角分享
  343. */
  344. onShareAppMessage() {
  345. }
  346. })