index.ts 9.3 KB

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