index.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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'],
  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(e: any) {
  134. },
  135. /// 重量范围值更改
  136. syncNumRange(e: any) {
  137. this.setData({
  138. minSize: e.detail.value[0],
  139. maxSize: e.detail.value[1],
  140. })
  141. },
  142. /// 获取履约模板信息
  143. queryPermancePlanTmp() {
  144. /// showLoading
  145. showLoading(() => {
  146. queryPermancePlanTmp({
  147. success: (res) => {
  148. /// 获取数据
  149. this.setData({
  150. tmps: res.data,
  151. tmp: res.data[0],
  152. actions: res.data.map(obj => { return obj.templatename })
  153. })
  154. },
  155. complete: () => {
  156. /// hideLoading
  157. hideLoading()
  158. }
  159. })
  160. })
  161. },
  162. /// 发布求购
  163. doListingBuy() {
  164. /// showModel
  165. showModel(() => {
  166. /// showLoading
  167. showLoading(() => {
  168. /// 钻石属性
  169. const exinfo = {
  170. UserID: userid(),
  171. AccountID: accountid(),
  172. ZSCategory: this.data.tabs[this.data.active].id,
  173. ZSCurrencyType: [this.data.currency],
  174. ZSShapeType: [this.data.shape],
  175. ZSColorType: [this.data.color1, this.data.color2],
  176. ZSClarityType: [this.data.neatnes1, this.data.neatnes2],
  177. ZSCutType: [this.data.qiegong1, this.data.qiegong2],
  178. ZSSymmetryType: [this.data.duicheng1, this.data.duicheng2],
  179. ZSPolishType: [this.data.paoguang1, this.data.paoguang2],
  180. ZSFluorescenceType: [this.data.yingguang1, this.data.yingguang2],
  181. Size: [this.data.minSize, this.data.maxSize],
  182. ZSCZColor1Type: [this.data.color1, this.data.color2],
  183. }
  184. /// 请求参数
  185. const info = JSON.stringify({
  186. Header: protoHeader(FunCode.ZSBuyOrderListingReq),
  187. UserID: userid(),
  188. AccountID: accountid(),
  189. GZ_BuyOrderDetailExInfo: exinfo,
  190. PerformanceTemplateID: this.data.tmp.autoid,
  191. MarketID: marketid(),
  192. OrderSrc: EOrderSrc.ORDERSRC_CLIENT,
  193. ClientType: clientType(),
  194. ClientSerialNo: timetample().toString()
  195. })
  196. /// 发送请求
  197. sendMsgToMQ({
  198. data: {
  199. data: encryptBody(info),
  200. funCodeReq: FunCode.ZSBuyOrderListingReq,
  201. funCodeRsp: FunCode.ZSBuyOrderListingRsp,
  202. isEncrypted: isEncrypted()
  203. },
  204. success: (res) => {
  205. /// 解析对象
  206. const data = JSON.parse(res.data.data)
  207. if (data.RetCode != 0) {
  208. hideLoading(() => {}, getErrorMsg(data.RetCode))
  209. return
  210. }
  211. /// 求购发布请求成功
  212. hideLoading(() => {
  213. wx.navigateBack()
  214. }, '求购发布请求成功', 'success')
  215. },
  216. fail: (emsg) => {
  217. hideLoading(()=>{}, emsg)
  218. }
  219. })
  220. }, '求购请求中....')
  221. }, '提示', '确认要发布求购吗?')
  222. },
  223. /// 合规性校验
  224. check(): boolean {
  225. /// 请选择形状
  226. if (this.data.shape === 0) {
  227. showToast('请选择形状')
  228. return false
  229. }
  230. return true
  231. },
  232. /**
  233. * 生命周期函数--监听页面加载
  234. */
  235. onLoad() {
  236. this.setData({
  237. /// 形状
  238. shapes: getEnumList('ZSShapeType').map(obj => {
  239. return {
  240. id: obj.enumitemname,
  241. name: obj.enumdicname,
  242. isCheck: obj.enumitemname === this.data.shape
  243. }
  244. }),
  245. shape: getEnumList('ZSShapeType')[0].enumitemname,
  246. /// 颜色
  247. colors: getEnumList('ZSColorType').map(obj => {
  248. return {
  249. value: obj.enumitemname,
  250. text: obj.enumdicname
  251. }
  252. }),
  253. color1: getEnumList('ZSColorType')[0].enumitemname,
  254. color2: getEnumList('ZSColorType')[0].enumitemname,
  255. /// 净度
  256. neatness: getEnumList('ZSClarityType').map(obj => {
  257. return {
  258. value: obj.enumitemname,
  259. text: obj.enumdicname
  260. }
  261. }),
  262. neatnes1: getEnumList('ZSClarityType')[0].enumitemname,
  263. neatnes2: getEnumList('ZSClarityType')[0].enumitemname,
  264. /// 切工
  265. qiegongs: getEnumList('ZSCutType').map(obj => {
  266. return {
  267. value: obj.enumitemname,
  268. text: obj.enumdicname
  269. }
  270. }),
  271. qiegong1: getEnumList('ZSCutType')[0].enumitemname,
  272. qiegong2: getEnumList('ZSCutType')[0].enumitemname,
  273. /// 对称
  274. duichengs: getEnumList('ZSSymmetryType').map(obj => {
  275. return {
  276. value: obj.enumitemname,
  277. text: obj.enumdicname
  278. }
  279. }),
  280. duicheng1: getEnumList('ZSSymmetryType')[0].enumitemname,
  281. duicheng2: getEnumList('ZSSymmetryType')[0].enumitemname,
  282. /// 抛光
  283. paoguangs: getEnumList('ZSPolishType').map(obj => {
  284. return {
  285. value: obj.enumitemname,
  286. text: obj.enumdicname
  287. }
  288. }),
  289. paoguang1: getEnumList('ZSPolishType')[0].enumitemname,
  290. paoguang2: getEnumList('ZSPolishType')[0].enumitemname,
  291. /// 荧光
  292. yingguangs: getEnumList('ZSFluorescenceType').map(obj => {
  293. return {
  294. value: obj.enumitemname,
  295. text: obj.enumdicname
  296. }
  297. }),
  298. yingguang1: getEnumList('ZSFluorescenceType')[0].enumitemname,
  299. yingguang2: getEnumList('ZSFluorescenceType')[0].enumitemname,
  300. /// 币种信息
  301. currencys: getEnumList('ZSCurrencyType').map(obj => {
  302. return {
  303. value: obj.enumitemname,
  304. text: obj.enumdicname
  305. }
  306. }),
  307. currency: getEnumList('ZSCurrencyType')[0].enumitemname,
  308. })
  309. /// 获取履约模板信息
  310. this.queryPermancePlanTmp()
  311. },
  312. /**
  313. * 生命周期函数--监听页面初次渲染完成
  314. */
  315. onReady() {
  316. },
  317. /**
  318. * 生命周期函数--监听页面显示
  319. */
  320. onShow() {
  321. },
  322. /**
  323. * 生命周期函数--监听页面隐藏
  324. */
  325. onHide() {
  326. },
  327. /**
  328. * 生命周期函数--监听页面卸载
  329. */
  330. onUnload() {
  331. },
  332. /**
  333. * 页面相关事件处理函数--监听用户下拉动作
  334. */
  335. onPullDownRefresh() {
  336. },
  337. /**
  338. * 页面上拉触底事件的处理函数
  339. */
  340. onReachBottom() {
  341. },
  342. /**
  343. * 用户点击右上角分享
  344. */
  345. onShareAppMessage() {
  346. }
  347. })