index.ts 11 KB

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