index.ts 9.4 KB

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