FilterUser.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <div class="filter-user">
  3. <div class="filter-option">
  4. <el-select
  5. v-model="filterType"
  6. class="filter-item"
  7. :placeholder="$t('common.selectType')"
  8. @change="handleFilterTypeChange"
  9. >
  10. <el-option v-for="(item,key) in allFilterTypes" :key="key" :label="item.name" :value="key" />
  11. </el-select>
  12. <el-select
  13. v-model="filterSymbol"
  14. class="filter-item"
  15. :placeholder="$t('common.selectFunction')"
  16. >
  17. <el-option v-for="(item,key) in filterSymbols" :key="key" :label="item" :value="key" />
  18. </el-select>
  19. <template
  20. v-if="filterType !== '' && allFilterTypes[filterType].hasOwnProperty('other') && allFilterTypes[filterType].other === 'date'"
  21. >
  22. <el-date-picker
  23. v-model="filterValue"
  24. class="filter-item"
  25. value-format="yyyy-MM-dd HH:mm:ss"
  26. type="datetime"
  27. :placeholder="$t('common.selectDate')"
  28. />
  29. </template>
  30. <template
  31. v-else-if="filterType !== '' && allFilterTypes[filterType].hasOwnProperty('other') && allFilterTypes[filterType].other === 'month'"
  32. >
  33. <el-date-picker
  34. v-model="filterValue"
  35. class="filter-item"
  36. value-format="yyyyMM"
  37. type="month"
  38. :placeholder="$t('common.selectMonth')"
  39. />
  40. </template>
  41. <template
  42. v-else-if="filterType !== '' && allFilterTypes[filterType].hasOwnProperty('other') && allFilterTypes[filterType].other === 'area'"
  43. >
  44. <el-cascader
  45. v-model="filterAreaValue"
  46. class="filter-item"
  47. :options="regionData"
  48. :props="{ checkStrictly: true }"
  49. />
  50. </template>
  51. <template
  52. v-else-if="filterType !== '' && allFilterTypes[filterType].hasOwnProperty('other') && allFilterTypes[filterType].other === 'select'"
  53. >
  54. <el-select
  55. v-model="filterValue"
  56. class="filter-item"
  57. :placeholder="`请选择${allFilterTypes[filterType].name}`"
  58. >
  59. <el-option
  60. v-for="(item,key) in allFilterTypes[filterType].selectData"
  61. :key="key"
  62. :label="item.name"
  63. :value="item.id"
  64. />
  65. </el-select>
  66. </template>
  67. <template
  68. v-else-if="filterType !== '' && allFilterTypes[filterType].hasOwnProperty('other') && filterCustomType.hasOwnProperty(allFilterTypes[filterType].other)"
  69. >
  70. <el-select v-model="filterValue" class="filter-item" :placeholder="`${filterCustomType[allFilterTypes[filterType].other].placeholder}`">
  71. <el-option v-for="(item,key) in filterCustomType[allFilterTypes[filterType].other].values" :key="key" :label="item[filterCustomType[allFilterTypes[filterType].other].labelField]" :value="item[filterCustomType[allFilterTypes[filterType].other].valueField]" />
  72. </el-select>
  73. </template>
  74. <template v-else>
  75. <el-input v-model="filterValue" class="filter-item filter-value" :placeholder="$t('common.pleaseInputContent')" />
  76. </template>
  77. <el-select
  78. v-model="filterRelation"
  79. class="filter-item filter-relation"
  80. :placeholder="$t('common.relation')"
  81. >
  82. <el-option v-for="(item,key) in filterRelations" :key="key" :label="item" :value="key" />
  83. </el-select>
  84. <el-button class="filter-item" icon="el-icon-plus" @click="handleOptionPlus" />
  85. <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilterUser">{{ filterBtnName }}</el-button>
  86. <el-button class="filter-item" type="" @click="handleFilterClear">{{ $t('common.reset') }}</el-button>
  87. <!-- <el-button class="down-button" type="text"><i class="el-icon-arrow-down" /></el-button> -->
  88. </div>
  89. <div v-show="filterSelected.length > 0" class="filter-selected">
  90. <el-tag
  91. v-for="(item,key) in filterSelected"
  92. :key="key"
  93. class="selected-tag"
  94. closable
  95. @close="handleCloseTag(key)"
  96. >{{ item.filterTypeName }} {{ item.filterSymbolName }} {{ item.filterName }}
  97. </el-tag>
  98. </div>
  99. <el-dialog :title="$t('filter.memberSelect')" :visible.sync="filterUserDialogShow" width="80%">
  100. <el-table
  101. v-loading="loading"
  102. :data="tableData"
  103. stripe
  104. style="width: 100%;"
  105. @selection-change="handleSelectionChange"
  106. >
  107. <el-table-column type="selection" width="55" />
  108. <el-table-column :label="$t('filter.memberNumber')">
  109. <template slot-scope="scope">
  110. {{ scope.row.USER_NAME }}
  111. </template>
  112. </el-table-column>
  113. <el-table-column :label="$t('filter.name')">
  114. <template slot-scope="scope">
  115. {{ scope.row.REAL_NAME }}
  116. </template>
  117. </el-table-column>
  118. <el-table-column :label="$t('filter.idNumber')" width="180">
  119. <template slot-scope="scope">
  120. {{ scope.row.ID_CARD }}
  121. </template>
  122. </el-table-column>
  123. <el-table-column :label="$t('filter.phoneNumber')">
  124. <template slot-scope="scope">
  125. {{ scope.row.MOBILE }}
  126. </template>
  127. </el-table-column>
  128. <el-table-column :label="$t('filter.memberLevel')">
  129. <template slot-scope="scope">
  130. {{ scope.row.DEC_LV ? filterCustomType.decLevel.values[scope.row.DEC_LV]['LEVEL_NAME'] : '' }}
  131. </template>
  132. </el-table-column>
  133. <el-table-column :label="$t('filter.level')">
  134. <template slot-scope="scope">
  135. {{ scope.row.EMP_LV ? filterCustomType.empLevel.values[scope.row.EMP_LV]['LEVEL_NAME'] : '' }}
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <div class="white-box-footer">
  140. <el-button type="primary" size="small" :disabled="multipleSelectionUserId == undefined || multipleSelectionUserId.length <= 0?true:false" @click="handleSelectValue(false)">{{ $t('filter.confirmSelect') }}</el-button>
  141. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  142. </div>
  143. </el-dialog>
  144. </div>
  145. </template>
  146. <script>
  147. import { filterUser } from '@/api/filter'
  148. import baseInfo from '@/utils/baseInfo'
  149. import store from '@/utils/vuexStore'
  150. import Pagination from './Pagination'
  151. import filterHelper from '@/utils/filterHelper'
  152. export default {
  153. name: 'FilterUser',
  154. components: { Pagination },
  155. props: {
  156. filterTypes: {
  157. type: Object,
  158. default() {
  159. return {
  160. 'USER_NAME': { isUserTable: true, name: this.$t('filter.memberNumber') },
  161. 'REAL_NAME': { isUserTable: true, name: this.$t('filter.memberName') },
  162. 'ID_CARD': { isUserTable: true, name: this.$t('filter.ID') },
  163. 'MOBILE': { isUserTable: true, name: this.$t('filter.phoneNumber') },
  164. 'CREATED_AT': { isUserTable: true, name: this.$t('filter.addAt'), other: 'date' }
  165. }
  166. }
  167. },
  168. filterBtnName: {
  169. type: String,
  170. default() {
  171. return this.$t('filter.memberSelect')
  172. }
  173. }
  174. },
  175. data() {
  176. return {
  177. loading: false,
  178. filterUserDialogShow: false,
  179. tableData: [],
  180. currentPage: 1,
  181. totalPages: 1,
  182. totalCount: 1,
  183. pageSize: 20,
  184. // filterCustomType: {
  185. // decLevel: {
  186. // placeholder: this.$t('filter.pleaseSelectDecLevel'),
  187. // labelField: 'LEVEL_NAME',
  188. // valueField: 'ID',
  189. // values: baseInfo.decLevels()
  190. // },
  191. // empLevel: {
  192. // placeholder: this.$t('filter.pleaseSelectEmpLevel'),
  193. // labelField: 'LEVEL_NAME',
  194. // valueField: 'ID',
  195. // values: baseInfo.empLevels()
  196. // },
  197. // decRole: {
  198. // placeholder: '请选择报单中心级别',
  199. // labelField: 'ROLE_NAME',
  200. // valueField: 'ID',
  201. // values: baseInfo.decRoles()
  202. // },
  203. // subCompany: {
  204. // placeholder: '请选择分公司',
  205. // labelField: 'COM_NAME',
  206. // valueField: 'ID',
  207. // values: baseInfo.subCompanies()
  208. // },
  209. // status: {
  210. // placeholder: '请选择会员状态',
  211. // labelField: 'label',
  212. // valueField: 'value',
  213. // values: baseInfo.allStatus()
  214. // },
  215. // dealTypes: {
  216. // placeholder: '请选择交易类型',
  217. // labelField: 'TYPE_NAME',
  218. // valueField: 'ID',
  219. // values: baseInfo.dealTypes()
  220. // },
  221. // systems: {
  222. // placeholder: '请选择体系',
  223. // labelField: 'SYSTEM_NAME',
  224. // valueField: 'ID',
  225. // values: baseInfo.systems()
  226. // },
  227. // sex: {
  228. // placeholder: '请选择性别',
  229. // labelField: 'label',
  230. // valueField: 'value',
  231. // values: {
  232. // '男': { label: '男', value: '男' },
  233. // '女': { label: '女', value: '女' }
  234. // }
  235. // },
  236. // yesOrNo: {
  237. // placeholder: '请选择是否',
  238. // labelField: 'label',
  239. // valueField: 'value',
  240. // values: {
  241. // 1: { label: '是', value: 1 },
  242. // 0: { label: '否', value: 0 }
  243. // }
  244. // },
  245. // banks: {
  246. // placeholder: '请选择开户行',
  247. // labelField: 'BANK_NAME',
  248. // valueField: 'BANK_CODE',
  249. // values: baseInfo.allOpenBank()
  250. // },
  251. // nations: {
  252. // placeholder: '请选择民族',
  253. // labelField: 'name',
  254. // valueField: 'id',
  255. // values: baseInfo.allNation()
  256. // },
  257. // location: {
  258. // placeholder: '请选择市场',
  259. // labelField: 'label',
  260. // valueField: 'value',
  261. // values: {
  262. // 1: { label: '一市场', value: 1 },
  263. // 2: { label: '二市场', value: 2 },
  264. // 3: { label: '三市场', value: 3 },
  265. // 4: { label: '四市场', value: 4 },
  266. // 5: { label: '五市场', value: 5 }
  267. // }
  268. // }
  269. // },
  270. filterModel: {
  271. userId: ''
  272. },
  273. allFilterTypes: this.filterTypes,
  274. filterType: '',
  275. filterSymbol: '',
  276. // filterSymbols: {
  277. // '=': this.$t('filter.eq'),
  278. // 'like': this.$t('filter.like'),
  279. // '<>': this.$t('filter.noeq'),
  280. // 'notLike': this.$t('filter.nolike'),
  281. // '>': this.$t('filter.moreThan'),
  282. // '>=': this.$t('filter.moreThanEq'),
  283. // '<': this.$t('filter.less'),
  284. // '<=': this.$t('filter.lessThan')
  285. // },
  286. filterRelation: 'and',
  287. // filterRelations: {
  288. // 'and': this.$t('filter.and'),
  289. // 'or': this.$t('filter.or')
  290. // },
  291. filterValue: '',
  292. filterName: '',
  293. filterSelected: [],
  294. selectData: [],
  295. multipleSelection: [],
  296. multipleSelectionUserId: [],
  297. regionData: store.state.regionInfo.regionData,
  298. filterAreaValue: [],
  299. filterRequest: {}
  300. }
  301. },
  302. computed: {
  303. filterCustomType() {
  304. return {
  305. decLevel: {
  306. placeholder: this.$t('filter.pleaseSelectDecLevel'),
  307. labelField: 'LEVEL_NAME',
  308. valueField: 'ID',
  309. values: baseInfo.decLevels()
  310. },
  311. empLevel: {
  312. placeholder: this.$t('filter.pleaseSelectEmpLevel'),
  313. labelField: 'LEVEL_NAME',
  314. valueField: 'ID',
  315. values: baseInfo.empLevels()
  316. },
  317. decRole: {
  318. placeholder: '请选择报单中心级别',
  319. labelField: 'ROLE_NAME',
  320. valueField: 'ID',
  321. values: baseInfo.decRoles()
  322. },
  323. subCompany: {
  324. placeholder: '请选择分公司',
  325. labelField: 'COM_NAME',
  326. valueField: 'ID',
  327. values: baseInfo.subCompanies()
  328. },
  329. status: {
  330. placeholder: '请选择会员状态',
  331. labelField: 'label',
  332. valueField: 'value',
  333. values: baseInfo.allStatus()
  334. },
  335. dealTypes: {
  336. placeholder: '请选择交易类型',
  337. labelField: 'TYPE_NAME',
  338. valueField: 'ID',
  339. values: baseInfo.dealTypes()
  340. },
  341. systems: {
  342. placeholder: '请选择体系',
  343. labelField: 'SYSTEM_NAME',
  344. valueField: 'ID',
  345. values: baseInfo.systems()
  346. },
  347. sex: {
  348. placeholder: '请选择性别',
  349. labelField: 'label',
  350. valueField: 'value',
  351. values: {
  352. '男': { label: '男', value: '男' },
  353. '女': { label: '女', value: '女' }
  354. }
  355. },
  356. yesOrNo: {
  357. placeholder: '请选择是否',
  358. labelField: 'label',
  359. valueField: 'value',
  360. values: {
  361. 1: { label: '是', value: 1 },
  362. 0: { label: '否', value: 0 }
  363. }
  364. },
  365. banks: {
  366. placeholder: '请选择开户行',
  367. labelField: 'BANK_NAME',
  368. valueField: 'BANK_CODE',
  369. values: baseInfo.allOpenBank()
  370. },
  371. nations: {
  372. placeholder: '请选择民族',
  373. labelField: 'name',
  374. valueField: 'id',
  375. values: baseInfo.allNation()
  376. },
  377. location: {
  378. placeholder: '请选择市场',
  379. labelField: 'label',
  380. valueField: 'value',
  381. values: {
  382. 1: { label: '一市场', value: 1 },
  383. 2: { label: '二市场', value: 2 },
  384. 3: { label: '三市场', value: 3 },
  385. 4: { label: '四市场', value: 4 },
  386. 5: { label: '五市场', value: 5 }
  387. }
  388. }
  389. }
  390. },
  391. filterSymbols() {
  392. return {
  393. '=': this.$t('filter.eq'),
  394. 'like': this.$t('filter.like'),
  395. '<>': this.$t('filter.noeq'),
  396. 'notLike': this.$t('filter.nolike'),
  397. '>': this.$t('filter.moreThan'),
  398. '>=': this.$t('filter.moreThanEq'),
  399. '<': this.$t('filter.less'),
  400. '<=': this.$t('filter.lessThan')
  401. }
  402. },
  403. filterRelations() {
  404. return {
  405. 'and': this.$t('filter.and'),
  406. 'or': this.$t('filter.or')
  407. }
  408. }
  409. },
  410. watch: {
  411. filterTypes(newVal) {
  412. this.allFilterTypes = this.filterTypes
  413. }
  414. },
  415. methods: {
  416. handleFilterTypeChange() {
  417. this.filterValue = ''
  418. },
  419. handleSelectionChange(val) {
  420. this.multipleSelection = val
  421. this.multipleSelectionUserId = []
  422. for (const i in this.multipleSelection) {
  423. this.multipleSelectionUserId.push(this.multipleSelection[i].ID)
  424. }
  425. },
  426. handleCurrentChange(page) {
  427. this.getData(this.filterRequest, page, this.pageSize)
  428. },
  429. handleSizeChange(pageSize) {
  430. this.getData(this.filterRequest, this.currentPage, pageSize)
  431. },
  432. remoteMethod(query) {
  433. if (query !== '') {
  434. this.loading = true
  435. filterUser({ kw: query }).then(response => {
  436. this.selectData = response
  437. this.loading = false
  438. }).catch(err => {
  439. this.loading = false
  440. })
  441. }
  442. },
  443. handleOptionPlus() {
  444. if (this.filterType === '' || this.filterSymbol === '' || (this.filterValue === '' && this.filterAreaValue === [])) {
  445. this.$message({
  446. message: this.$t('filter.selectContentNotice'),
  447. type: 'warning'
  448. })
  449. return false
  450. }
  451. let valueName = this.filterValue
  452. if (this.filterType !== '' && this.allFilterTypes[this.filterType].hasOwnProperty('other')) {
  453. // 获取下拉筛选时的选中项
  454. if (this.allFilterTypes[this.filterType].other === 'select') {
  455. let nameObj = []
  456. const _this = this
  457. if (!Array.isArray(this.allFilterTypes[this.filterType].selectData)) {
  458. nameObj[0] = this.allFilterTypes[this.filterType].selectData[_this.filterValue]
  459. } else {
  460. nameObj = (this.allFilterTypes[this.filterType].selectData).filter(function(item, index, array) {
  461. return item.id === _this.filterValue
  462. })
  463. }
  464. valueName = nameObj[0] ? nameObj[0].name : null
  465. } else if (this.allFilterTypes[this.filterType].other === 'area') {
  466. if (this.filterSymbol !== '=') {
  467. this.$message({
  468. message: this.$t('filter.areaSelectNotice'),
  469. type: 'warning'
  470. })
  471. return false
  472. }
  473. this.filterValue = this.filterAreaValue.join(',')
  474. valueName = ''
  475. for (const i in this.regionData) {
  476. if (this.regionData[i].value === this.filterAreaValue[0]) {
  477. valueName += this.regionData[i].label + ','
  478. for (const j in this.regionData[i].children) {
  479. if (this.regionData[i].children[j].value === this.filterAreaValue[1]) {
  480. valueName += this.regionData[i].children[j].label + ','
  481. for (const h in this.regionData[i].children[j].children) {
  482. if (this.regionData[i].children[j].children[h].value === this.filterAreaValue[2]) {
  483. valueName += this.regionData[i].children[j].children[h].label
  484. break
  485. }
  486. }
  487. break
  488. }
  489. }
  490. break
  491. }
  492. }
  493. } else if (this.filterCustomType.hasOwnProperty(this.allFilterTypes[this.filterType].other)) {
  494. const allCustomData = this.filterCustomType[this.allFilterTypes[this.filterType].other].values
  495. const customField = this.filterCustomType[this.allFilterTypes[this.filterType].other].labelField
  496. valueName = allCustomData[this.filterValue][customField]
  497. }
  498. }
  499. // 如果是筛选会员编号,则把会员编号转成小写
  500. // if(this.filterType === 'USER_NAME'){
  501. // this.filterValue = this.filterValue.toLowerCase()
  502. // }
  503. this.filterSelected.push({
  504. filterType: this.filterType,
  505. filterTypeName: this.allFilterTypes[this.filterType].name,
  506. filterSymbol: this.filterSymbol,
  507. filterSymbolName: this.filterSymbols[this.filterSymbol],
  508. filterValue: this.filterValue,
  509. filterRelation: this.filterRelation,
  510. filterRelationName: this.filterRelations[this.filterRelation],
  511. filterName: valueName,
  512. filterOther: this.filterType !== '' && this.allFilterTypes[this.filterType].hasOwnProperty('other') ? this.allFilterTypes[this.filterType].other : null,
  513. isUserTable: this.allFilterTypes[this.filterType].isUserTable
  514. })
  515. },
  516. handleCloseTag(tag) {
  517. this.filterSelected.splice(tag, 1)
  518. },
  519. handleFilterUser() {
  520. console.log('===>>>', this.filterSelected.length, '<<===')
  521. if (this.filterSelected.length > 0) {
  522. this.loading = true
  523. this.filterRequest = {}
  524. for (const i in this.filterSelected) {
  525. if (this.filterSelected[i].isUserTable) {
  526. let reqFilterValue = `${this.filterSelected[i].filterSymbol},${this.filterSelected[i].filterValue}`
  527. if (this.filterSelected[i].hasOwnProperty('filterOther')) {
  528. reqFilterValue += `,${this.filterSelected[i].filterOther}`
  529. }
  530. const filterType = this.filterSelected[i].filterType
  531. if (this.filterRequest[filterType]) {
  532. this.$set(this.filterRequest, filterType, (this.filterRequest[filterType] + '|' + reqFilterValue))
  533. } else {
  534. this.$set(this.filterRequest, filterType, reqFilterValue)
  535. }
  536. }
  537. }
  538. if (Object.keys(this.filterRequest).length === 0) {
  539. this.handleSelectValue(true)
  540. } else {
  541. this.getData(this.filterRequest, this.currentPage)
  542. }
  543. }
  544. },
  545. getData(request, page = null, pageSize = null) {
  546. request.page = page
  547. request.pageSize = pageSize
  548. filterUser(this.listQuery).then(response => {
  549. this.filterUserDialogShow = true
  550. })
  551. },
  552. handleSelectValue(isAll = false) {
  553. const otherFilterTypes = []
  554. for (const i in this.filterSelected) {
  555. if (!this.filterSelected[i].isUserTable) {
  556. otherFilterTypes.push(this.filterSelected[i])
  557. }
  558. }
  559. let userIds = this.multipleSelectionUserId
  560. if (isAll) {
  561. userIds = 'all'
  562. }
  563. this.$emit('select-value', {
  564. userIds: userIds,
  565. otherFilterTypes: otherFilterTypes
  566. })
  567. this.filterUserDialogShow = false
  568. },
  569. handleFilterClear() {
  570. Object.assign(this.$data, this.$options.data())
  571. this.allFilterTypes = this.filterTypes
  572. // 清空地址栏
  573. filterHelper.clearFilterOption(this)
  574. this.$emit('select-value', { userIds: 'all', otherFilterTypes: [] })
  575. }
  576. }
  577. }
  578. </script>
  579. <style scoped>
  580. .filter-option:after {
  581. content: '';
  582. clear: both;
  583. display: table;
  584. }
  585. .filter-item {
  586. float: left;
  587. margin-left: 10px;
  588. }
  589. .filter-value {
  590. width: 200px;
  591. }
  592. .filter-relation {
  593. width: 100px;
  594. display: none;
  595. }
  596. .down-button {
  597. float: right;
  598. }
  599. .filter-selected {
  600. clear: both;
  601. margin: 10px;
  602. padding: 5px;
  603. border: 1px solid #ebeef5;
  604. }
  605. .selected-tag {
  606. margin-left: 10px;
  607. }
  608. /deep/ .el-input__inner {
  609. width:203px;
  610. }
  611. </style>