index.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. import { getEnumList } from "../../../../services/utils"
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. /// 底部安全区域
  8. safeBottom: getApp().globalData.safeBottom,
  9. /// tabs
  10. tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}],
  11. /// tab索引
  12. active: 0,
  13. /// 形状
  14. shapes: [{ id: 1, name: '圆明亮形', isCheck: true }],
  15. /// 选中形状
  16. shape: ['1'],
  17. /// 颜色
  18. colors: [{id: 1, name: 'D', isCheck: true}],
  19. /// 选中形状
  20. color: [1],
  21. /// 净度
  22. neatness: [{ id: 1, name: 'FL', isCheck: true }],
  23. /// 选中净度
  24. neatnes: 1,
  25. /// 切工
  26. qiegongs: [{ id: 1, name: 'EX', isCheck: true }],
  27. /// 选中切工
  28. qiegong: 1,
  29. /// 对称
  30. duichengs: [{ id: 1, name: 'EX', isCheck: true }],
  31. duicheng: 1,
  32. /// 抛光
  33. paoguangs: [{ id: 1, name: 'EX', isCheck: true }],
  34. paoguang: 1,
  35. /// 莹光
  36. yingguangs: [{ id: 1, name: '无', isCheck: true }],
  37. /// 选中莹光
  38. yingguang: 1,
  39. /// 证书
  40. certificates: [{ id: 1, name: 'GIA', isCheck: true }],
  41. /// 选中证书
  42. certificate: 1,
  43. /// 币种
  44. currencys: [{id: 1, name: '人民币(¥)', isCheck: true},
  45. {id: 2, name: '美元($)', isCheck: false}],
  46. currency: 1,
  47. /// 最小重量
  48. minweight: 0.00,
  49. /// 最大重量
  50. maxweight: 0.00
  51. },
  52. /**
  53. * tab触发事件
  54. */
  55. onTabChange(e: any) {
  56. /// 设置激活项
  57. this.setData({ active: e.detail.index })
  58. },
  59. /**
  60. * 返回上层视图
  61. */
  62. backToParent() {
  63. /// 返回上层视图
  64. wx.navigateBack()
  65. },
  66. /// 按钮点击事件
  67. onButtonPressed(e: any) {
  68. /// 数据拼接
  69. const ids = (<string> e.target.id).split(' ')
  70. const id = (<string> e.target.id).split(' ')[0]
  71. const index = <number> <unknown>ids[1]
  72. switch (id) {
  73. case 'shape': /// 形状
  74. this.setData({ shapes: this.data.shapes.map(item => {
  75. if (item.id == index) { item.isCheck = !item.isCheck }
  76. return item
  77. }) })
  78. /// 赋值
  79. this.setData({ shape: this.data.shapes.map(item => {
  80. return item.id.toString()
  81. }) })
  82. break;
  83. case 'currency':
  84. this.setData({ currencys: this.data.currencys.map(item => {
  85. if (item.id == index) {
  86. item.isCheck = true
  87. /// 赋值
  88. this.setData({ currency: item.id })
  89. } else {
  90. item.isCheck = false
  91. }
  92. return item
  93. }) })
  94. break;
  95. case 'color': /// 颜色
  96. this.setData({ colors: this.data.colors.map(item => {
  97. if (item.id == index) { item.isCheck = !item.isCheck }
  98. return item
  99. }) })
  100. /// 赋值
  101. this.setData({ color: this.data.colors.map(item => { return item.id }) })
  102. break;
  103. case 'neatness': /// 净度
  104. this.setData({ neatness: this.data.neatness.map(item => {
  105. if (item.id == index) {
  106. item.isCheck = true
  107. /// 赋值
  108. this.setData({ neatnes: item.id })
  109. } else {
  110. item.isCheck = false
  111. }
  112. return item
  113. }) })
  114. break;
  115. case 'qiegong': /// 切工
  116. this.setData({ qiegongs: this.data.qiegongs.map(item => {
  117. if (item.id == index) {
  118. item.isCheck = true
  119. /// 赋值
  120. this.setData({ qiegong: item.id })
  121. } else {
  122. item.isCheck = false
  123. }
  124. return item
  125. }) })
  126. break;
  127. case 'duicheng': /// 对称
  128. this.setData({ duichengs: this.data.duichengs.map(item => {
  129. if (item.id == index) {
  130. item.isCheck = true
  131. /// 赋值
  132. this.setData({ duicheng: item.id })
  133. } else {
  134. item.isCheck = false
  135. }
  136. return item
  137. }) })
  138. break;
  139. case 'polishing': /// 抛光
  140. this.setData({ paoguangs: this.data.paoguangs.map(item => {
  141. if (item.id == index) {
  142. item.isCheck = true
  143. /// 赋值
  144. this.setData({ polishing: item.id })
  145. } else {
  146. item.isCheck = false
  147. }
  148. return item
  149. }) })
  150. break;
  151. case 'yingguang': /// 荧光
  152. this.setData({ yingguangs: this.data.yingguangs.map(item => {
  153. if (item.id == index) {
  154. item.isCheck = true
  155. /// 赋值
  156. this.setData({ yingguang: item.id })
  157. } else {
  158. item.isCheck = false
  159. }
  160. return item
  161. }) })
  162. break;
  163. case 'certificate': /// 证书
  164. this.setData({ certificates: this.data.certificates.map(item => {
  165. if (item.id == index) {
  166. item.isCheck = true
  167. /// 赋值
  168. this.setData({ certificate: item.id })
  169. } else {
  170. item.isCheck = false
  171. }
  172. return item
  173. }) })
  174. break;
  175. case 'search': /// 搜索
  176. /// 搜索页面跳转
  177. this.goToSearch()
  178. break;
  179. case 'clear': break;
  180. default: break;
  181. }
  182. },
  183. /// 重量范围值更改
  184. syncNumRange(e: any) {
  185. this.setData({
  186. minweight: e.detail.value[0],
  187. maxweight: e.detail.value[1],
  188. })
  189. },
  190. /// 搜索页面跳转
  191. goToSearch() {
  192. /// 数据拼接
  193. const info = {
  194. category: this.data.tabs[this.data.active].id,
  195. zsshapetype: this.data.shape,
  196. zsclaritytype: this.data.neatnes,
  197. zscuttype: this.data.qiegong,
  198. zssymmetrytype: this.data.duicheng,
  199. zspolishtype: this.data.paoguang,
  200. zsfluorescencetype: this.data.yingguang,
  201. zscurrencytype: this.data.currency,
  202. zscerttype: this.data.certificate,
  203. zscolortype: this.data.color,
  204. weight1: this.data.minweight,
  205. weight2: this.data.maxweight
  206. }
  207. /// 页面跳转
  208. wx.switchTab({
  209. url: '/pages/trade/index',
  210. /// 加载成功
  211. success: () => {
  212. /// 缓存数据
  213. wx.setStorageSync('TradeParams', JSON.stringify(info))
  214. }
  215. })
  216. },
  217. /**
  218. * 生命周期函数--监听页面加载
  219. */
  220. onLoad() {
  221. },
  222. /**
  223. * 生命周期函数--监听页面初次渲染完成
  224. */
  225. onReady() {
  226. /// 显示默认数据
  227. this.setData({
  228. /// 形状
  229. shapes: getEnumList('ZSShapeType').map(obj => {
  230. return {
  231. id: obj.enumitemname,
  232. name: obj.enumdicname,
  233. isCheck: false
  234. }
  235. }),
  236. /// 颜色
  237. colors: getEnumList('ZSColorType').map(obj => {
  238. return {
  239. id: obj.enumitemname,
  240. name: obj.enumdicname,
  241. isCheck: false
  242. }
  243. }),
  244. /// 净度
  245. neatness: getEnumList('ZSClarityType').map(obj => {
  246. return {
  247. id: obj.enumitemname,
  248. name: obj.enumdicname,
  249. isCheck: false
  250. }
  251. }),
  252. /// 切工
  253. qiegongs: getEnumList('ZSCutType').map(obj => {
  254. return {
  255. id: obj.enumitemname,
  256. name: obj.enumdicname,
  257. isCheck: false
  258. }
  259. }),
  260. /// 对称
  261. duichengs: getEnumList('ZSSymmetryType').map(obj => {
  262. return {
  263. id: obj.enumitemname,
  264. name: obj.enumdicname,
  265. isCheck: false
  266. }
  267. }),
  268. /// 抛光
  269. paoguangs: getEnumList('ZSPolishType').map(obj => {
  270. return {
  271. id: obj.enumitemname,
  272. name: obj.enumdicname,
  273. isCheck: false
  274. }
  275. }),
  276. /// 荧光
  277. yingguangs: getEnumList('ZSFluorescenceType').map(obj => {
  278. return {
  279. id: obj.enumitemname,
  280. name: obj.enumdicname,
  281. isCheck: false
  282. }
  283. }),
  284. /// 证书
  285. certificates: getEnumList('ZSCertType').map(obj => {
  286. return {
  287. id: obj.enumitemname,
  288. name: obj.enumdicname,
  289. isCheck: false
  290. }
  291. }),
  292. })
  293. },
  294. /**
  295. * 生命周期函数--监听页面显示
  296. */
  297. onShow() {
  298. },
  299. /**
  300. * 生命周期函数--监听页面隐藏
  301. */
  302. onHide() {
  303. },
  304. /**
  305. * 生命周期函数--监听页面卸载
  306. */
  307. onUnload() {
  308. },
  309. /**
  310. * 页面相关事件处理函数--监听用户下拉动作
  311. */
  312. onPullDownRefresh() {
  313. },
  314. /**
  315. * 页面上拉触底事件的处理函数
  316. */
  317. onReachBottom() {
  318. },
  319. /**
  320. * 用户点击右上角分享
  321. */
  322. onShareAppMessage() {
  323. }
  324. })