index.ts 8.3 KB

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