dk-dropdown-menu.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*******************************************************************************
  2. * Copyright(c) 2024 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:查询条件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 周兴 2024-1-25 1.00 新建
  9. *******************************************************************************/
  10. const app = getApp()
  11. const Constants = require('../../../utils/Constants');
  12. Component({
  13. /**
  14. * 组件的属性列表
  15. */
  16. properties: {
  17. menuList: { //查询条件数组
  18. type: Array,
  19. value: []
  20. },
  21. //筛选数组
  22. pullMenuList: {
  23. type: Array,
  24. value: [],
  25. },
  26. // 是否开启大查询
  27. flgSearchText: {
  28. type: Boolean,
  29. value: true,
  30. },
  31. flgSearchFlag: {
  32. type: Boolean,
  33. value: false,
  34. },
  35. searchReadonly: {
  36. type: Boolean,
  37. value: false,
  38. },
  39. flgSearchTextSearchText: {
  40. type: String,
  41. },
  42. // 大查询的提示信息
  43. searchTextPlaceholder: {
  44. type: String,
  45. },
  46. // 自定义导航栏高度
  47. navBarHeight: {
  48. type: Number,
  49. value: 0
  50. },
  51. // 结果集
  52. value: {
  53. type: String,
  54. observer: function (newVal) {
  55. if (newVal) {
  56. this.setData({
  57. form: JSON.parse(newVal) || {}
  58. })
  59. }
  60. }
  61. }
  62. },
  63. /**
  64. * 组件的初始数据
  65. */
  66. data: {
  67. $t: app.globalData.lang,
  68. // 下拉
  69. dropDownFlag: false,
  70. // 单选下拉
  71. dropSingleDownFlag: false,
  72. // 筛选
  73. pickFlag: false,
  74. // 筛选中的日期组件显示标识
  75. dropDateFlag: false,
  76. dropType: null,
  77. dropCode: null,
  78. index: null,
  79. searchType: null,
  80. // 记录是哪个组件点击出现的日期
  81. dropDateCode: null,
  82. // 下拉多选数据源
  83. pullMSelectMenuList: [],
  84. // 下拉多选外数据源
  85. pullOtherMenuList: [],
  86. // 大查询条件
  87. searchText: '',
  88. // 是否是大查询进行的查询
  89. searchTextFlag: false,
  90. form: {}
  91. },
  92. lifetimes: {
  93. attached: function () {
  94. let pullMSelectMenuList = this.data.pullMenuList.filter(it => it.pullType == Constants.pullType.mSelect);
  95. let pullOtherMenuList = this.data.pullMenuList.filter(it => it.pullType != Constants.pullType.mSelect);
  96. this.setData({
  97. pullMSelectMenuList: pullMSelectMenuList,
  98. pullOtherMenuList: pullOtherMenuList
  99. })
  100. // 记录原始的title
  101. let menuList = this.data.menuList
  102. if (menuList && menuList.length > 0) {
  103. menuList.forEach(it => {
  104. it.titleOrginal = it.title
  105. })
  106. }
  107. },
  108. detached: function () {
  109. // 在组件实例被从页面节点树移除时执行
  110. },
  111. },
  112. /**
  113. * 组件的方法列表
  114. */
  115. methods: {
  116. /**
  117. * @desc : 展开下拉
  118. * @author : 周兴
  119. * @date : 2024/1/26 11:46
  120. */
  121. openDropdown(e) {
  122. let item = e.currentTarget.dataset.item;
  123. if (item.searchType === Constants.searchType.radio) {
  124. return;
  125. }
  126. let index = e.currentTarget.dataset.index;
  127. // 如果点击的不是同一个下拉就清空数据源
  128. if (this.data.index != index && this.selectComponent('#drop') != null) {
  129. this.selectComponent('#drop').clearAll();
  130. }
  131. if (!item.searchType || item.searchType === Constants.searchType.drop) {
  132. this.setData({
  133. dropDownFlag: true,
  134. dropSingleDownFlag: false,
  135. dropCode: item.code,
  136. index: index,
  137. dropType: item.dropType ? item.dropType : item.code,
  138. searchType: item.searchType ? item.searchType : Constants.searchType.drop
  139. })
  140. }
  141. // 筛选
  142. else if (item.searchType === Constants.searchType.dropSingle) {
  143. this.setData({
  144. dropDownFlag: false,
  145. dropSingleDownFlag: true,
  146. dropCode: item.code,
  147. index: index,
  148. dropType: item.dropType ? item.dropType : item.code,
  149. searchType: item.searchType ? item.searchType : Constants.searchType.drop
  150. })
  151. }
  152. // 筛选
  153. else if (item.searchType === Constants.searchType.pick) {
  154. this.setData({
  155. pickFlag: true,
  156. index: index,
  157. dropCode: item.dropType ? item.dropType : item.code,
  158. searchType: item.searchType
  159. })
  160. }
  161. else {
  162. this.setData({
  163. index: index,
  164. dropDownFlag: false,
  165. dropSingleDownFlag: false,
  166. pickFlag: false,
  167. dropCode: null,
  168. dropType: null
  169. })
  170. }
  171. },
  172. /**
  173. * @desc : 修改排序的值
  174. * @author : 周兴
  175. * @date : 2024/3/5 12:16
  176. */
  177. onChange(e) {
  178. let item = e.currentTarget.dataset.item;
  179. let index = e.currentTarget.dataset.index;
  180. // 排序
  181. if (item.searchType === 'radio') {
  182. let code = item.code
  183. let form = this.data.form
  184. form[code] = e.detail
  185. let menuList = this.data.menuList
  186. if (index || index == 0) {
  187. if (menuList.length > index) {
  188. let options = item.options;
  189. if (options) {
  190. let optionsIndex = options.findIndex(it => it.value == e.detail);
  191. menuList[index].title = options[optionsIndex].text;
  192. menuList[index].value = e.detail;
  193. }
  194. }
  195. }
  196. console.log('menuList', menuList, e.detail);
  197. this.setData({
  198. form: form,
  199. value: JSON.stringify(form),
  200. menuList: menuList
  201. })
  202. if (!e.detail.initFlag) {
  203. // 调取查询
  204. this.doSearch();
  205. }
  206. this.selectComponent('#' + item.code).toggle(false);
  207. }
  208. },
  209. /**
  210. * @desc : 查询条件
  211. * @author : 周兴
  212. * @date : 2024/1/26 12:16
  213. */
  214. onSearchText(e) {
  215. let form = this.data.form
  216. form.searchText = e.detail
  217. this.setData({
  218. form: form,
  219. value: JSON.stringify(form),
  220. searchTextFlag: e.detail ? true : false//TOP搜索输入标识
  221. })
  222. },
  223. /**
  224. * @desc : 执行查询
  225. * @author : 周兴
  226. * @date : 2024/1/26 12:16
  227. */
  228. doSearch() {
  229. let form = null;
  230. // 大查询
  231. if (this.data.searchTextFlag) {
  232. // form = {
  233. // searchText: this.data.searchText
  234. // }
  235. form = this.data.form
  236. } else {
  237. form = this.data.form
  238. form.searchText = undefined
  239. }
  240. console.log('form', form);
  241. this.setData({
  242. form: form,
  243. value: JSON.stringify(form)
  244. })
  245. this.triggerEvent('search');
  246. },
  247. /**
  248. * @desc : 日期组件后的回调
  249. * @author : 周兴
  250. * @date : 2024/1/26 12:16
  251. */
  252. dateCommit(e) {
  253. let data = e.detail.date
  254. let code = e.detail.code
  255. let form = this.data.form
  256. form[code + 'Start'] = data[0]
  257. form[code + 'End'] = data[1]
  258. let menuList = this.data.menuList
  259. let dateDefault = e.detail.dateDefault
  260. if (this.data.index || this.data.index == 0) {
  261. if (menuList.length > this.data.index) {
  262. menuList[this.data.index].defaultValue = dateDefault.value
  263. menuList[this.data.index].title = dateDefault.text
  264. }
  265. }
  266. console.log('menuList', menuList, e.detail);
  267. this.setData({
  268. form: form,
  269. value: JSON.stringify(form),
  270. menuList: menuList
  271. })
  272. if (!e.detail.initFlag) {
  273. // 调取查询
  274. this.doSearch();
  275. }
  276. this.selectComponent('#' + e.detail.code).toggle(false);
  277. },
  278. /**
  279. * @desc : 开关组件后的回调
  280. * @author : 周兴
  281. * @date : 2024/2/18 12:16
  282. */
  283. switchCommit(e) {
  284. let code = e.detail.code
  285. let key = e.detail.key
  286. let menuList = this.data.menuList
  287. let form = this.data.form
  288. if (key == 'valueList') {
  289. form[code + 'List'] = e.detail.valueList
  290. } else {
  291. form[code + 'List'] = e.detail.values
  292. }
  293. if (this.data.index || this.data.index == 0) {
  294. if (menuList.length > this.data.index) {
  295. menuList[this.data.index].list = e.detail.dataList
  296. }
  297. }
  298. this.setData({
  299. form: form,
  300. value: JSON.stringify(form),
  301. menuList: menuList
  302. })
  303. // 调取查询
  304. this.doSearch();
  305. this.selectComponent('#' + e.detail.code).toggle(false);
  306. },
  307. /**
  308. * @desc : 下拉多选确定
  309. * @author : 周兴
  310. * @date : 2024/1/26 12:16
  311. */
  312. mutiSearchAll(e) {
  313. let menuList = this.data.menuList
  314. if (!this.data.pickFlag && menuList.length > this.data.index) {
  315. if (e.detail.names) {
  316. menuList[this.data.index].title = e.detail.names;
  317. } else {
  318. // 把值恢复到初始值
  319. menuList[this.data.index].title = menuList[this.data.index].titleOrginal
  320. }
  321. }
  322. let form = this.data.form
  323. form[this.data.dropCode + 'Ids'] = e.detail.idList
  324. this.setData({
  325. form: form,
  326. value: JSON.stringify(form),
  327. menuList: menuList,
  328. dropDownFlag: false,
  329. pickFlag: false
  330. })
  331. this.selectComponent('#' + this.data.dropCode).toggle(false);
  332. // 调取查询
  333. this.doSearch();
  334. },
  335. /**
  336. * @desc : 选择数据
  337. * @author : 周兴
  338. * @date : 2024/1/26 11:46
  339. */
  340. chooseData(e) {
  341. let menuList = this.data.menuList
  342. if (!this.data.pickFlag && menuList.length > this.data.index) {
  343. if (e.detail.text) {
  344. menuList[this.data.index].title = e.detail.text;
  345. } else {
  346. // 把值恢复为初始值
  347. menuList[this.data.index].title = menuList[this.data.index].titleOrginal
  348. }
  349. }
  350. let form = this.data.form
  351. form[this.data.dropCode + 'Id'] = e.detail.value;
  352. this.setData({
  353. form: form,
  354. value: JSON.stringify(form),
  355. menuList: menuList,
  356. dropSingleDownFlag: false,
  357. })
  358. this.selectComponent('#' + this.data.dropCode).toggle(false);
  359. // 调取查询
  360. this.doSearch();
  361. },
  362. /**
  363. * @desc : 关闭下拉抽屉
  364. * @author : 周兴
  365. * @date : 2024/1/26 12:16
  366. */
  367. mutiCloseAll(e) {
  368. this.setData({
  369. pickFlag: false
  370. })
  371. this.selectComponent('#' + this.data.dropCode).toggle(false);
  372. },
  373. /**
  374. * @desc : 文本框改变事件
  375. * @author : 周兴
  376. * @date : 2024/1/26 12:16
  377. */
  378. handleFieldChange(e) {
  379. let key = e.currentTarget.dataset.key
  380. let form = this.data.form
  381. form[key] = e.detail
  382. this.setData({
  383. form: form,
  384. value: JSON.stringify(form),
  385. })
  386. },
  387. /**
  388. * @desc : check点击事件
  389. * @author : 周兴
  390. * @date : 2024/1/27 08:59
  391. */
  392. onChangeCheck(e) {
  393. let key = e.currentTarget.dataset.key
  394. let checkFlag = e.currentTarget.dataset.value
  395. let form = this.data.form
  396. form[key] = !checkFlag
  397. this.setData({
  398. form: form,
  399. value: JSON.stringify(form),
  400. })
  401. },
  402. /**
  403. * @desc : 筛选数据源组件点击事件
  404. * @author : 周兴
  405. * @date : 2024/1/27 08:59
  406. */
  407. onClickTag(e) {
  408. let key = e.detail.key
  409. let dataList = e.detail.dataList
  410. let codeList = e.detail.codeList
  411. let form = this.data.form
  412. form[key + 'List'] = dataList;
  413. if (codeList && codeList.length > 0) {
  414. form[key + 'List'] = codeList;
  415. }
  416. this.setData({
  417. form: form,
  418. value: JSON.stringify(form)
  419. })
  420. },
  421. /**
  422. * @desc : 打开筛选中的日期
  423. * @author : 周兴
  424. * @date : 2024/1/29 08:59
  425. */
  426. onClickDate(e) {
  427. this.setData({
  428. dropDateFlag: true,
  429. dropDateCode: e.currentTarget.dataset.key
  430. })
  431. },
  432. /**
  433. * @desc : 选择筛选中的日期
  434. * @author : 周兴
  435. * @date : 2024/1/29 08:59
  436. */
  437. pickDateCommit(e) {
  438. let form = this.data.form
  439. let date = e.detail.date[0] + '~' + e.detail.date[1]
  440. form[this.data.dropDateCode] = date
  441. form[this.data.dropDateCode + 'Start'] = e.detail.date[0];
  442. form[this.data.dropDateCode + 'End'] = e.detail.date[1];
  443. this.setData({
  444. form: form,
  445. value: JSON.stringify(form)
  446. })
  447. },
  448. /**
  449. * @desc : 筛选重置事件
  450. * @author : 周兴
  451. * @date : 2024/1/27 08:59
  452. */
  453. clearform() {
  454. let form = this.data.form;
  455. let pullMSelectMenuList = this.data.pullMSelectMenuList;
  456. let pullOtherMenuList = this.data.pullOtherMenuList;
  457. if (form != null) {
  458. // 多选下拉
  459. pullMSelectMenuList.forEach(it => {
  460. if (form[it.code + 'List']) {
  461. // 删除form中的属性
  462. delete form[it.code + 'List'];
  463. this.selectComponent("#" + it.code).clearForm();
  464. }
  465. })
  466. // 非多选下拉
  467. pullOtherMenuList.forEach(it => {
  468. if (form[it.code]) {
  469. // 删除form中的属性
  470. delete form[it.code];
  471. }
  472. // 如果有日期删除日期
  473. if (it.dataType == Constants.dataType.date) {
  474. delete form[it.code + "Start"];
  475. delete form[it.code + "End"];
  476. }
  477. })
  478. this.setData({
  479. form: form,
  480. value: JSON.stringify(form),
  481. dropDateCode: null
  482. })
  483. }
  484. },
  485. /**
  486. * @desc : 获取语言的方法
  487. * @author : 周兴
  488. * @date : 2024/1/19
  489. */
  490. $t(name) {
  491. if (this.data.$t[name]) {
  492. return this.data.$t[name];
  493. } else {
  494. return name;
  495. }
  496. },
  497. },
  498. })