| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- /*******************************************************************************
- * Copyright(c) 2024 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:查询条件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 周兴 2024-1-25 1.00 新建
- *******************************************************************************/
- const app = getApp()
- const Constants = require('../../../utils/Constants');
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- menuList: { //查询条件数组
- type: Array,
- value: []
- },
- //筛选数组
- pullMenuList: {
- type: Array,
- value: [],
- },
- // 是否开启大查询
- flgSearchText: {
- type: Boolean,
- value: true,
- },
- flgSearchFlag: {
- type: Boolean,
- value: false,
- },
- searchReadonly: {
- type: Boolean,
- value: false,
- },
- flgSearchTextSearchText: {
- type: String,
- },
- // 大查询的提示信息
- searchTextPlaceholder: {
- type: String,
- },
- // 自定义导航栏高度
- navBarHeight: {
- type: Number,
- value: 0
- },
- // 结果集
- value: {
- type: String,
- observer: function (newVal) {
- if (newVal) {
- this.setData({
- form: JSON.parse(newVal) || {}
- })
- }
- }
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- $t: app.globalData.lang,
- // 下拉
- dropDownFlag: false,
- // 单选下拉
- dropSingleDownFlag: false,
- // 筛选
- pickFlag: false,
- // 筛选中的日期组件显示标识
- dropDateFlag: false,
- dropType: null,
- dropCode: null,
- index: null,
- searchType: null,
- // 记录是哪个组件点击出现的日期
- dropDateCode: null,
- // 下拉多选数据源
- pullMSelectMenuList: [],
- // 下拉多选外数据源
- pullOtherMenuList: [],
- // 大查询条件
- searchText: '',
- // 是否是大查询进行的查询
- searchTextFlag: false,
- form: {}
- },
- lifetimes: {
- attached: function () {
- let pullMSelectMenuList = this.data.pullMenuList.filter(it => it.pullType == Constants.pullType.mSelect);
- let pullOtherMenuList = this.data.pullMenuList.filter(it => it.pullType != Constants.pullType.mSelect);
- this.setData({
- pullMSelectMenuList: pullMSelectMenuList,
- pullOtherMenuList: pullOtherMenuList
- })
- // 记录原始的title
- let menuList = this.data.menuList
- if (menuList && menuList.length > 0) {
- menuList.forEach(it => {
- it.titleOrginal = it.title
- })
- }
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- /**
- * @desc : 展开下拉
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- openDropdown(e) {
- let item = e.currentTarget.dataset.item;
- if (item.searchType === Constants.searchType.radio) {
- return;
- }
- let index = e.currentTarget.dataset.index;
- // 如果点击的不是同一个下拉就清空数据源
- if (this.data.index != index && this.selectComponent('#drop') != null) {
- this.selectComponent('#drop').clearAll();
- }
- if (!item.searchType || item.searchType === Constants.searchType.drop) {
- this.setData({
- dropDownFlag: true,
- dropSingleDownFlag: false,
- dropCode: item.code,
- index: index,
- dropType: item.dropType ? item.dropType : item.code,
- searchType: item.searchType ? item.searchType : Constants.searchType.drop
- })
- }
- // 筛选
- else if (item.searchType === Constants.searchType.dropSingle) {
- this.setData({
- dropDownFlag: false,
- dropSingleDownFlag: true,
- dropCode: item.code,
- index: index,
- dropType: item.dropType ? item.dropType : item.code,
- searchType: item.searchType ? item.searchType : Constants.searchType.drop
- })
- }
- // 筛选
- else if (item.searchType === Constants.searchType.pick) {
- this.setData({
- pickFlag: true,
- index: index,
- dropCode: item.dropType ? item.dropType : item.code,
- searchType: item.searchType
- })
- }
- else {
- this.setData({
- index: index,
- dropDownFlag: false,
- dropSingleDownFlag: false,
- pickFlag: false,
- dropCode: null,
- dropType: null
- })
- }
- },
- /**
- * @desc : 修改排序的值
- * @author : 周兴
- * @date : 2024/3/5 12:16
- */
- onChange(e) {
- let item = e.currentTarget.dataset.item;
- let index = e.currentTarget.dataset.index;
- // 排序
- if (item.searchType === 'radio') {
- let code = item.code
- let form = this.data.form
- form[code] = e.detail
- let menuList = this.data.menuList
- if (index || index == 0) {
- if (menuList.length > index) {
- let options = item.options;
- if (options) {
- let optionsIndex = options.findIndex(it => it.value == e.detail);
- menuList[index].title = options[optionsIndex].text;
- menuList[index].value = e.detail;
- }
- }
- }
- console.log('menuList', menuList, e.detail);
- this.setData({
- form: form,
- value: JSON.stringify(form),
- menuList: menuList
- })
- if (!e.detail.initFlag) {
- // 调取查询
- this.doSearch();
- }
- this.selectComponent('#' + item.code).toggle(false);
- }
- },
- /**
- * @desc : 查询条件
- * @author : 周兴
- * @date : 2024/1/26 12:16
- */
- onSearchText(e) {
- let form = this.data.form
- form.searchText = e.detail
- this.setData({
- form: form,
- value: JSON.stringify(form),
- searchTextFlag: e.detail ? true : false//TOP搜索输入标识
- })
- },
- /**
- * @desc : 执行查询
- * @author : 周兴
- * @date : 2024/1/26 12:16
- */
- doSearch() {
- let form = null;
- // 大查询
- if (this.data.searchTextFlag) {
- // form = {
- // searchText: this.data.searchText
- // }
- form = this.data.form
- } else {
- form = this.data.form
- form.searchText = undefined
- }
- console.log('form', form);
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- this.triggerEvent('search');
- },
- /**
- * @desc : 日期组件后的回调
- * @author : 周兴
- * @date : 2024/1/26 12:16
- */
- dateCommit(e) {
- let data = e.detail.date
- let code = e.detail.code
- let form = this.data.form
- form[code + 'Start'] = data[0]
- form[code + 'End'] = data[1]
- let menuList = this.data.menuList
- let dateDefault = e.detail.dateDefault
- if (this.data.index || this.data.index == 0) {
- if (menuList.length > this.data.index) {
- menuList[this.data.index].defaultValue = dateDefault.value
- menuList[this.data.index].title = dateDefault.text
- }
- }
- console.log('menuList', menuList, e.detail);
- this.setData({
- form: form,
- value: JSON.stringify(form),
- menuList: menuList
- })
- if (!e.detail.initFlag) {
- // 调取查询
- this.doSearch();
- }
- this.selectComponent('#' + e.detail.code).toggle(false);
- },
- /**
- * @desc : 开关组件后的回调
- * @author : 周兴
- * @date : 2024/2/18 12:16
- */
- switchCommit(e) {
- let code = e.detail.code
- let key = e.detail.key
- let menuList = this.data.menuList
- let form = this.data.form
- if (key == 'valueList') {
- form[code + 'List'] = e.detail.valueList
- } else {
- form[code + 'List'] = e.detail.values
- }
- if (this.data.index || this.data.index == 0) {
- if (menuList.length > this.data.index) {
- menuList[this.data.index].list = e.detail.dataList
- }
- }
- this.setData({
- form: form,
- value: JSON.stringify(form),
- menuList: menuList
- })
- // 调取查询
- this.doSearch();
- this.selectComponent('#' + e.detail.code).toggle(false);
- },
- /**
- * @desc : 下拉多选确定
- * @author : 周兴
- * @date : 2024/1/26 12:16
- */
- mutiSearchAll(e) {
- let menuList = this.data.menuList
- if (!this.data.pickFlag && menuList.length > this.data.index) {
- if (e.detail.names) {
- menuList[this.data.index].title = e.detail.names;
- } else {
- // 把值恢复到初始值
- menuList[this.data.index].title = menuList[this.data.index].titleOrginal
- }
- }
- let form = this.data.form
- form[this.data.dropCode + 'Ids'] = e.detail.idList
- this.setData({
- form: form,
- value: JSON.stringify(form),
- menuList: menuList,
- dropDownFlag: false,
- pickFlag: false
- })
- this.selectComponent('#' + this.data.dropCode).toggle(false);
- // 调取查询
- this.doSearch();
- },
- /**
- * @desc : 选择数据
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- chooseData(e) {
- let menuList = this.data.menuList
- if (!this.data.pickFlag && menuList.length > this.data.index) {
- if (e.detail.text) {
- menuList[this.data.index].title = e.detail.text;
- } else {
- // 把值恢复为初始值
- menuList[this.data.index].title = menuList[this.data.index].titleOrginal
- }
- }
- let form = this.data.form
- form[this.data.dropCode + 'Id'] = e.detail.value;
- this.setData({
- form: form,
- value: JSON.stringify(form),
- menuList: menuList,
- dropSingleDownFlag: false,
- })
- this.selectComponent('#' + this.data.dropCode).toggle(false);
- // 调取查询
- this.doSearch();
- },
- /**
- * @desc : 关闭下拉抽屉
- * @author : 周兴
- * @date : 2024/1/26 12:16
- */
- mutiCloseAll(e) {
- this.setData({
- pickFlag: false
- })
- this.selectComponent('#' + this.data.dropCode).toggle(false);
- },
- /**
- * @desc : 文本框改变事件
- * @author : 周兴
- * @date : 2024/1/26 12:16
- */
- handleFieldChange(e) {
- let key = e.currentTarget.dataset.key
- let form = this.data.form
- form[key] = e.detail
- this.setData({
- form: form,
- value: JSON.stringify(form),
- })
- },
- /**
- * @desc : check点击事件
- * @author : 周兴
- * @date : 2024/1/27 08:59
- */
- onChangeCheck(e) {
- let key = e.currentTarget.dataset.key
- let checkFlag = e.currentTarget.dataset.value
- let form = this.data.form
- form[key] = !checkFlag
- this.setData({
- form: form,
- value: JSON.stringify(form),
- })
- },
- /**
- * @desc : 筛选数据源组件点击事件
- * @author : 周兴
- * @date : 2024/1/27 08:59
- */
- onClickTag(e) {
- let key = e.detail.key
- let dataList = e.detail.dataList
- let codeList = e.detail.codeList
- let form = this.data.form
- form[key + 'List'] = dataList;
- if (codeList && codeList.length > 0) {
- form[key + 'List'] = codeList;
- }
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- },
- /**
- * @desc : 打开筛选中的日期
- * @author : 周兴
- * @date : 2024/1/29 08:59
- */
- onClickDate(e) {
- this.setData({
- dropDateFlag: true,
- dropDateCode: e.currentTarget.dataset.key
- })
- },
- /**
- * @desc : 选择筛选中的日期
- * @author : 周兴
- * @date : 2024/1/29 08:59
- */
- pickDateCommit(e) {
- let form = this.data.form
- let date = e.detail.date[0] + '~' + e.detail.date[1]
- form[this.data.dropDateCode] = date
- form[this.data.dropDateCode + 'Start'] = e.detail.date[0];
- form[this.data.dropDateCode + 'End'] = e.detail.date[1];
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- },
- /**
- * @desc : 筛选重置事件
- * @author : 周兴
- * @date : 2024/1/27 08:59
- */
- clearform() {
- let form = this.data.form;
- let pullMSelectMenuList = this.data.pullMSelectMenuList;
- let pullOtherMenuList = this.data.pullOtherMenuList;
- if (form != null) {
- // 多选下拉
- pullMSelectMenuList.forEach(it => {
- if (form[it.code + 'List']) {
- // 删除form中的属性
- delete form[it.code + 'List'];
- this.selectComponent("#" + it.code).clearForm();
- }
- })
- // 非多选下拉
- pullOtherMenuList.forEach(it => {
- if (form[it.code]) {
- // 删除form中的属性
- delete form[it.code];
- }
- // 如果有日期删除日期
- if (it.dataType == Constants.dataType.date) {
- delete form[it.code + "Start"];
- delete form[it.code + "End"];
- }
- })
- this.setData({
- form: form,
- value: JSON.stringify(form),
- dropDateCode: null
- })
- }
- },
- /**
- * @desc : 获取语言的方法
- * @author : 周兴
- * @date : 2024/1/19
- */
- $t(name) {
- if (this.data.$t[name]) {
- return this.data.$t[name];
- } else {
- return name;
- }
- },
- },
- })
|