FilterUser.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. watch: {
  303. filterTypes(newVal) {
  304. this.allFilterTypes = this.filterTypes
  305. }
  306. },
  307. methods: {
  308. handleFilterTypeChange() {
  309. this.filterValue = ''
  310. },
  311. handleSelectionChange(val) {
  312. this.multipleSelection = val
  313. this.multipleSelectionUserId = []
  314. for (const i in this.multipleSelection) {
  315. this.multipleSelectionUserId.push(this.multipleSelection[i].ID)
  316. }
  317. },
  318. handleCurrentChange(page) {
  319. this.getData(this.filterRequest, page, this.pageSize)
  320. },
  321. handleSizeChange(pageSize) {
  322. this.getData(this.filterRequest, this.currentPage, pageSize)
  323. },
  324. remoteMethod(query) {
  325. if (query !== '') {
  326. this.loading = true
  327. filterUser({ kw: query }).then(response => {
  328. this.selectData = response
  329. this.loading = false
  330. }).catch(err => {
  331. this.loading = false
  332. })
  333. }
  334. },
  335. handleOptionPlus() {
  336. if (this.filterType === '' || this.filterSymbol === '' || (this.filterValue === '' && this.filterAreaValue === [])) {
  337. this.$message({
  338. message: this.$t('filter.selectContentNotice'),
  339. type: 'warning'
  340. })
  341. return false
  342. }
  343. let valueName = this.filterValue
  344. if (this.filterType !== '' && this.allFilterTypes[this.filterType].hasOwnProperty('other')) {
  345. // 获取下拉筛选时的选中项
  346. if (this.allFilterTypes[this.filterType].other === 'select') {
  347. let nameObj = []
  348. const _this = this
  349. if (!Array.isArray(this.allFilterTypes[this.filterType].selectData)) {
  350. nameObj[0] = this.allFilterTypes[this.filterType].selectData[_this.filterValue]
  351. } else {
  352. nameObj = (this.allFilterTypes[this.filterType].selectData).filter(function(item, index, array) {
  353. return item.id === _this.filterValue
  354. })
  355. }
  356. valueName = nameObj[0] ? nameObj[0].name : null
  357. } else if (this.allFilterTypes[this.filterType].other === 'area') {
  358. if (this.filterSymbol !== '=') {
  359. this.$message({
  360. message: this.$t('filter.areaSelectNotice'),
  361. type: 'warning'
  362. })
  363. return false
  364. }
  365. this.filterValue = this.filterAreaValue.join(',')
  366. valueName = ''
  367. for (const i in this.regionData) {
  368. if (this.regionData[i].value === this.filterAreaValue[0]) {
  369. valueName += this.regionData[i].label + ','
  370. for (const j in this.regionData[i].children) {
  371. if (this.regionData[i].children[j].value === this.filterAreaValue[1]) {
  372. valueName += this.regionData[i].children[j].label + ','
  373. for (const h in this.regionData[i].children[j].children) {
  374. if (this.regionData[i].children[j].children[h].value === this.filterAreaValue[2]) {
  375. valueName += this.regionData[i].children[j].children[h].label
  376. break
  377. }
  378. }
  379. break
  380. }
  381. }
  382. break
  383. }
  384. }
  385. } else if (this.filterCustomType.hasOwnProperty(this.allFilterTypes[this.filterType].other)) {
  386. const allCustomData = this.filterCustomType[this.allFilterTypes[this.filterType].other].values
  387. const customField = this.filterCustomType[this.allFilterTypes[this.filterType].other].labelField
  388. valueName = allCustomData[this.filterValue][customField]
  389. }
  390. }
  391. // 如果是筛选会员编号,则把会员编号转成小写
  392. // if(this.filterType === 'USER_NAME'){
  393. // this.filterValue = this.filterValue.toLowerCase()
  394. // }
  395. this.filterSelected.push({
  396. filterType: this.filterType,
  397. filterTypeName: this.allFilterTypes[this.filterType].name,
  398. filterSymbol: this.filterSymbol,
  399. filterSymbolName: this.filterSymbols[this.filterSymbol],
  400. filterValue: this.filterValue,
  401. filterRelation: this.filterRelation,
  402. filterRelationName: this.filterRelations[this.filterRelation],
  403. filterName: valueName,
  404. filterOther: this.filterType !== '' && this.allFilterTypes[this.filterType].hasOwnProperty('other') ? this.allFilterTypes[this.filterType].other : null,
  405. isUserTable: this.allFilterTypes[this.filterType].isUserTable
  406. })
  407. },
  408. handleCloseTag(tag) {
  409. this.filterSelected.splice(tag, 1)
  410. },
  411. handleFilterUser() {
  412. console.log('===>>>', this.filterSelected.length, '<<===')
  413. if (this.filterSelected.length > 0) {
  414. this.loading = true
  415. this.filterRequest = {}
  416. for (const i in this.filterSelected) {
  417. if (this.filterSelected[i].isUserTable) {
  418. let reqFilterValue = `${this.filterSelected[i].filterSymbol},${this.filterSelected[i].filterValue}`
  419. if (this.filterSelected[i].hasOwnProperty('filterOther')) {
  420. reqFilterValue += `,${this.filterSelected[i].filterOther}`
  421. }
  422. const filterType = this.filterSelected[i].filterType
  423. if (this.filterRequest[filterType]) {
  424. this.$set(this.filterRequest, filterType, (this.filterRequest[filterType] + '|' + reqFilterValue))
  425. } else {
  426. this.$set(this.filterRequest, filterType, reqFilterValue)
  427. }
  428. }
  429. }
  430. if (Object.keys(this.filterRequest).length === 0) {
  431. this.handleSelectValue(true)
  432. } else {
  433. this.getData(this.filterRequest, this.currentPage)
  434. }
  435. }
  436. },
  437. getData(request, page = null, pageSize = null) {
  438. request.page = page
  439. request.pageSize = pageSize
  440. filterUser(this.listQuery).then(response => {
  441. this.filterUserDialogShow = true
  442. })
  443. },
  444. handleSelectValue(isAll = false) {
  445. const otherFilterTypes = []
  446. for (const i in this.filterSelected) {
  447. if (!this.filterSelected[i].isUserTable) {
  448. otherFilterTypes.push(this.filterSelected[i])
  449. }
  450. }
  451. let userIds = this.multipleSelectionUserId
  452. if (isAll) {
  453. userIds = 'all'
  454. }
  455. this.$emit('select-value', {
  456. userIds: userIds,
  457. otherFilterTypes: otherFilterTypes
  458. })
  459. this.filterUserDialogShow = false
  460. },
  461. handleFilterClear() {
  462. Object.assign(this.$data, this.$options.data())
  463. this.allFilterTypes = this.filterTypes
  464. // 清空地址栏
  465. filterHelper.clearFilterOption(this)
  466. this.$emit('select-value', { userIds: 'all', otherFilterTypes: [] })
  467. }
  468. }
  469. }
  470. </script>
  471. <style scoped>
  472. .filter-option:after {
  473. content: '';
  474. clear: both;
  475. display: table;
  476. }
  477. .filter-item {
  478. float: left;
  479. margin-left: 10px;
  480. }
  481. .filter-value {
  482. width: 200px;
  483. }
  484. .filter-relation {
  485. width: 100px;
  486. display: none;
  487. }
  488. .down-button {
  489. float: right;
  490. }
  491. .filter-selected {
  492. clear: both;
  493. margin: 10px;
  494. padding: 5px;
  495. border: 1px solid #ebeef5;
  496. }
  497. .selected-tag {
  498. margin-left: 10px;
  499. }
  500. </style>