multi-select.vue 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. <template>
  2. <div>
  3. <div style="display: flex;align-items: center;">
  4. <InputPop ref="input" :value="selectedValue" :class="tableFlag?'input-class':''"
  5. :clearable="true" :magnifierFlag="true" readonly @on-clear="clearAll" @on-focus="magnifierClick(true)"
  6. @on-keydown="handleInputKeydown"/>
  7. <!-- <div class="close-class" v-if="!readonly && selectedValue && selectedValue.length > 0">-->
  8. <!-- <Icon slot="prefix" type="ios-close-circle" @click.stop="clearAll"/>-->
  9. <!-- </div>-->
  10. <div class="search-class">
  11. <Icon slot="prefix" type="md-search" @click.stop="magnifierClick(false)"/>
  12. </div>
  13. </div>
  14. <DkModal
  15. width="800"
  16. ref="modal_search"
  17. v-model="showModal"
  18. @modalOk="ok"
  19. @modalCancel="cancel"
  20. @on-visible-change="onVisibleChange"
  21. class-name="multi-class"
  22. :title="dkFormItem?vm.$t('choose') + dkFormItem.label: vm.$t('chooseData')">
  23. <BaseIndexButtonGroup #left>
  24. <BaseIndexButton ref="search" name="search" @click="getDataTable"></BaseIndexButton>
  25. <BaseIndexButton :finalFlag="true" ref="clear" name="clear"
  26. @click="clear"></BaseIndexButton>
  27. </BaseIndexButtonGroup>
  28. <!-- <SearchCond id="search-cond-div" width="780px" v-if="searchCond && searchCond.length > 0" ref="searchCond"-->
  29. <!-- v-model="searchCond" :setFlag="false" :searchContent="searchCond" :col-count="4"></SearchCond>-->
  30. <SearchCond id="search-cond-div" class="search-cond-class" width="700" v-if="searchContent && searchContent.length > 0" ref="searchCond"
  31. v-model="searchCond" :setFlag="false" :searchContent="searchContent" :col-count="colCount"></SearchCond>
  32. <DkTabs ref="tabs" :options="tabsOptions" @on-click="tabsClick" @on-clear="clearSelected"></DkTabs>
  33. <DkTable v-show="tabIndex === 0" :primaryKey="selectKey" :clear-check-flag="false" ref="table-select" :id="'table-'+$options.name"
  34. name="table" :data="tableData"
  35. :checkMethodFlag=true
  36. :page-flag="pageFlag"
  37. :page-total="pageInfo.total"
  38. :current-page="pageInfo.currentPage"
  39. :link-click-checked="true"
  40. :refreshSelect="false"
  41. :show-setting-flag="false"
  42. :pageSize="pageInfo.pageSize"
  43. :page-size-opts="pageSizeOpts?pageSizeOpts:$config.pageSizeOptsMag"
  44. @select-change="selectChange"
  45. @pageChange="pageSizeChange">
  46. <!-- :title="vm.$t(item.field)" -->
  47. <DkTableColumn v-for="(item,index) in columns" :key="index" :field="item.field" :type="item.type"
  48. :width="item.width"
  49. :title="vm.$t(item.title?item.title: item.field)"
  50. :resize-flag="index === columns.length - 1"
  51. :switch-disabled="item.disabled"
  52. @on-switch-change="onSwitchChange"></DkTableColumn>
  53. </DkTable>
  54. <!--已选列表-->
  55. <DkTable v-show="tabIndex === 1" :pageFlag="false" :pageTotalFlag="false" :primaryKey="selectKey"
  56. :id="'table-'+$options.name" ref="table-selected" :data="batchRowsPage" :operateFlag="true"
  57. :refreshSelect="false" :multiple="false" :show-setting-flag="false" :choose-flag="false"
  58. @delRow="delItem">
  59. <DkTableColumn v-for="(item,index) in columns" :key="index" :field="item.field" :type="item.type"
  60. :title="vm.$t(item.title?item.title: item.field)" :width="item.width"
  61. :resize-flag="index === columns.length - 1"></DkTableColumn>
  62. </DkTable>
  63. <div v-show="false">
  64. <DkButton type="primary" ref="confirm" @click="ok">{{ vm.$t('confirm') }}</DkButton>
  65. <DkButton ref="close" @click="cancel">{{ vm.$t('close') }}</DkButton>
  66. </div>
  67. </DkModal>
  68. </div>
  69. </template>
  70. <script>
  71. import {button as buttonList} from '@/locale/lang/zh-CN'
  72. import {request} from "@/api/base";
  73. export default {
  74. name: 'multi-select',
  75. inject: {
  76. prop: {
  77. type: String,
  78. default: null
  79. },
  80. dkFormItem: {
  81. type: Object,
  82. default: null
  83. }
  84. },
  85. props: {
  86. value: {
  87. type: Array,
  88. default: null
  89. },
  90. //默认值
  91. defaultValue: {
  92. type: [Number, String],
  93. default: null
  94. },
  95. //主业务列名
  96. mainField: {
  97. type: String,
  98. default: null,
  99. },
  100. // 放大镜类型
  101. type: {
  102. type: String,
  103. default: null
  104. },
  105. // 最末级节点
  106. leafFlag: {
  107. type: Boolean,
  108. default: false
  109. },
  110. // 单据
  111. docCode: {
  112. type: String,
  113. default: ''
  114. },
  115. // 属性类型
  116. attributeType: {
  117. type: String,
  118. default: ''
  119. },
  120. //提示信息
  121. placeholder: {
  122. type: String,
  123. default: ''
  124. },
  125. // 比例的字段
  126. rateField: {
  127. type: String,
  128. default: '',
  129. },
  130. // 订单ID
  131. orderId: {
  132. type: Number,
  133. default: 0
  134. },
  135. //是否只读
  136. readonly: {
  137. type: Boolean,
  138. default: false
  139. },
  140. // 外部传入的查询条件
  141. otherCondition: {
  142. type: Object,
  143. default: null
  144. },
  145. // 是否是新建部门时使用
  146. organizationFlag: {
  147. type: Boolean,
  148. default: false
  149. },
  150. // 是否从表格中调用的
  151. tableFlag: {
  152. type: Boolean,
  153. default: false
  154. },
  155. // 选中是否自动设置主业务列为默认
  156. checkAutoSetMainField:{
  157. type: Boolean,
  158. default: true
  159. },
  160. // 主业务列显示文本
  161. mainFieldText:{
  162. type: String,
  163. default: '【主】'
  164. },
  165. // 主业务列默认id
  166. mainFieldId: {
  167. type: Number,
  168. default: undefined
  169. },
  170. // 页条数
  171. pageSize:{
  172. type:Number,
  173. default:null
  174. },
  175. // 是否开启分页
  176. pageFlag:{
  177. type:Boolean,
  178. default:false
  179. }
  180. },
  181. data() {
  182. const vm = window.vm
  183. let self = this
  184. return {
  185. vm: vm,
  186. colCount: 4,
  187. modalWidth: 600,
  188. // 选择的显示的数据
  189. selectedValue: '',
  190. documentKeyDownContent: Object,
  191. model: null,
  192. options: [],
  193. tableData: [],
  194. showModal: false,
  195. batchRowsPage: [],
  196. batchKeysPage: [],
  197. batchRowsPageSocial: [],
  198. batchKeysPageSocial: [],
  199. // 数据源的service
  200. service: {},
  201. // 详细的查询方法
  202. methodsNameDetail: '',
  203. //列设置
  204. columns: [],
  205. selectFlag: 'selectFlag',// 选择列的列名
  206. // 选择的key
  207. selectKey: '',
  208. // 选择的label
  209. selectLabel: '',
  210. // 查询条件
  211. searchCond: {},
  212. searchContent: [],
  213. searchTable: {},
  214. // 最大的条数
  215. maxTagCount: 1,
  216. placeholderData: '',
  217. clearFlag: false, // 是否点击清空按钮
  218. tabIndex: 0,
  219. tabsOptions: [
  220. {label: '选择列表', name: 'name1', index: 0},
  221. {label: '已选列表', name: 'name2', index: 1, clear: true},
  222. ],
  223. pageInfo: {
  224. total: 0,
  225. pageSize: self.pageSize?self.pageSize: this.$config.pageSize,
  226. currentPage: 1
  227. },
  228. pageSizeOpts:null,
  229. }
  230. },
  231. watch: {
  232. /**
  233. * @desc : 监听放大镜是否打开,如果关闭,需要把keydown还原回去
  234. * @author : 周兴
  235. * @date : 2022/5/13 10:12
  236. */
  237. showModal(n, o) {
  238. if (!n) {
  239. document.onkeydown = this.documentKeyDownContent
  240. } else {
  241. this.addKeyBoardEvent() // 增加快捷键
  242. }
  243. },
  244. placeholder(n, o) {
  245. this.placeholderData = n
  246. },
  247. defaultValue(n, o) {
  248. //赋默认值
  249. this.setDefaultValue();
  250. },
  251. value(n, o) {
  252. if (!n || n.length == 0) {
  253. this.selectedValue = null;
  254. }
  255. },
  256. batchRowsPage(n, o) {
  257. //监听选择的数据,改变页签的数量
  258. if (n && n.length) {
  259. this.tabsOptions[1].label = '已选列表【' + n.length + '】';
  260. } else {
  261. this.tabsOptions[1].label = '已选列表';
  262. }
  263. },
  264. orderId(n, o) {
  265. // 如果Id改变,需要重新查询数据库
  266. // this.getDataTable();
  267. }
  268. },
  269. methods: {
  270. /**
  271. * @desc : 切换tab
  272. * @author : 周兴
  273. * @date : 2022/5/28 16:38
  274. */
  275. tabsClick(e, option) {
  276. this.tabIndex = option.index;
  277. },
  278. /**
  279. * @desc : 删除已选
  280. * @author : 周兴
  281. * @date : 2022/5/31 15:04
  282. */
  283. clearSelected() {
  284. this.clearAll();
  285. },
  286. /**
  287. * @desc : 翻页
  288. * @author : 周兴
  289. * @date : 2023/12/20 16:54
  290. */
  291. pageSizeChange(pageInfo){
  292. this.getDataTable(pageInfo.currentPage);
  293. },
  294. /**
  295. * @desc : 删除已选
  296. * @author : 周兴
  297. * @date : 2022/9/26 16:39
  298. */
  299. delItem(rowIndex) {
  300. let row = this.batchRowsPage[rowIndex]
  301. // 如果存在就删除
  302. if (row) {
  303. let key = row[this.selectKey];
  304. this.batchRowsPage = this.batchRowsPage.filter(it => it[this.selectKey] !== row[this.selectKey])
  305. this.batchKeysPage = this.batchKeysPage.filter(it => it !== row[this.selectKey])
  306. let tRow = this.tableData.filter(it => it[this.selectKey] === key);
  307. // 删除掉去掉的勾选
  308. if (tRow && tRow.length > 0) {
  309. // 删除掉去掉的勾选
  310. this.$refs['table-select'].setUnCheckedRow(tRow[0]);
  311. } else {
  312. // 删除掉去掉的勾选
  313. if (this.batchKeysPage) {
  314. this.batchKeysPage.splice(this.batchKeysPage.indexOf(key), 1)
  315. let filterRows = this.$refs['table-select'].batchRows.filter(it => it[this.selectKey] == key)
  316. if (filterRows && filterRows.length > 0) {
  317. this.$refs['table-select'].batchRows.splice(this.$refs['table-select'].batchRows.indexOf(filterRows[0]), 1)
  318. }
  319. this.$refs['table-select'].batchKeys = this.batchKeysPage;
  320. }
  321. }
  322. }
  323. },
  324. /**
  325. * @desc : 点回车打开放大镜
  326. * @author : 周兴
  327. * @date : 2022/12/14 11:32
  328. */
  329. handleInputKeydown(e) {
  330. if (e.key === 'Enter') {
  331. this.magnifierClick();
  332. }
  333. },
  334. /**
  335. * @desc : 监控checkbox值
  336. * @date : 2022/5/27 11:36
  337. * @author : 寇珊珊
  338. */
  339. selectChange(batchRows, row, checked) {
  340. //获取当前选中的checkbox
  341. let batchKeys = this.$refs['table-select'].batchKeys;
  342. this.batchKeysPage = [...batchKeys]
  343. if (this.rateField) {
  344. //定义每行数据中的百分比
  345. let allocationRatio = (100 / batchKeys.length).toFixed(2)
  346. //定义一个每个选中后的百分比相加的变量,用来给最后一个元素赋值
  347. let allocationRatioTotal = 0
  348. if (batchKeys && batchKeys.length > 0) {
  349. let rows = this.tableData.filter(it => batchKeys.includes(it[this.selectKey]));
  350. if (rows && rows.length > 0) {
  351. //数据取余2为0
  352. if (100 % rows.length == 0) {
  353. //循环将计算好的百分比放入数据中
  354. for (let i in rows) {
  355. this.$set(rows[i], this.rateField, parseFloat(allocationRatio))
  356. }
  357. } else { //数据取余2不为0
  358. //获取最后选中checkbox数组中最后一个元素
  359. let endList = rows.splice(-1)
  360. for (let i = 0; i < rows.length; i++) {
  361. allocationRatioTotal = allocationRatioTotal + parseFloat(allocationRatio)
  362. this.$set(rows[i], this.rateField, allocationRatio)
  363. }
  364. this.$set(endList[0], this.rateField, 100 - allocationRatioTotal)
  365. }
  366. }
  367. }
  368. }
  369. //根据勾选状态进行控制主业务标识列的状态
  370. this.setMain(row, checked);
  371. this.$nextTick(() => {
  372. this.batchRowsPage = this.tableData.filter(it => this.batchKeysPage.includes(it[this.selectKey])).map(m => m);
  373. })
  374. },
  375. /**
  376. * @desc : 设置主业务信息
  377. * @author : 周兴
  378. * @date : 2022/6/13 9:24
  379. */
  380. setMain(row, checked) {
  381. if (!this.mainField) return;
  382. //选中状态
  383. if (checked) {
  384. let filterRows = this.tableData.filter(it => it[this.mainField])
  385. if ((!filterRows || filterRows.length === 0)&&this.checkAutoSetMainField) {
  386. this.$set(row, this.mainField, true);
  387. }
  388. } else {
  389. //当前这行如果是true,就要把其他行的主业务标识置为true,从上往下
  390. if (this.rateField) {
  391. this.$set(row, this.rateField, 100);
  392. }
  393. if (row[this.mainField]) {
  394. this.$set(row, this.mainField, false);
  395. let batchKeys = this.$refs['table-select'].batchKeys;
  396. for (let i in this.tableData) {
  397. if (row.id != this.tableData[i].id && batchKeys.includes(this.tableData[i][this.selectKey])) {
  398. this.$set(this.tableData[i], this.mainField, true);
  399. break;
  400. }
  401. }
  402. }
  403. }
  404. },
  405. /**
  406. * @desc : 开关开启后处理
  407. * @author : 周兴
  408. * @date : 2022/6/13 10:34
  409. */
  410. onSwitchChange(e) {
  411. let batchKeys = this.$refs['table-select'].batchKeys;
  412. if (e.checked) {
  413. // 如果选中,需要增加前面的checkbox的勾选,并且去掉其他的主业务的勾选
  414. for (let i in this.tableData) {
  415. if (e.id !== this.tableData[i].id) {
  416. this.$set(this.tableData[i], this.mainField, false);
  417. }
  418. }
  419. // 如果没有勾选上,才会进行勾选
  420. if (!batchKeys.includes(e[this.selectKey])) {
  421. this.$refs['table-select'].setCheckedRow(e)
  422. }
  423. } else {
  424. // 如果去掉勾选,需要勾选下一个
  425. for (let i in this.tableData) {
  426. if (e.id != this.tableData[i].id && batchKeys.includes(this.tableData[i][this.selectKey])) {
  427. this.$set(this.tableData[i], this.mainField, true);
  428. break;
  429. }
  430. }
  431. }
  432. },
  433. /**
  434. * @desc : 键盘事件
  435. * @author : 周兴
  436. * @date : 2022/4/15 20:38
  437. */
  438. handleKeydown(e) {
  439. if (e.key === 'Enter') {
  440. this.magnifierClick()
  441. }
  442. },
  443. /**
  444. * @desc : 清空事件
  445. * @author : 周兴
  446. * @date : 2022/3/4 8:19
  447. */
  448. clear() {
  449. this.searchList = {}
  450. this.searchTable = {}
  451. },
  452. /**
  453. * @desc : 获取表格数据
  454. * @author : 沈博
  455. * @date : 2022/3/7 16:59
  456. */
  457. getDataTable(currentPage = 1) {
  458. let param = {...this.$refs['table-select'].pageInfo}
  459. param.docCode = this.docCode
  460. // 如果是最末级节点需要传递到后台
  461. param.leafFlag = this.leafFlag
  462. // 不分页 todo
  463. if(this.pageFlag){
  464. param.pageSize = this.pageSize?this.pageSize: this.$config.maxPageSize;
  465. param.currentPage = currentPage
  466. }
  467. param.ftyId = this.$store.state.user.ftyId
  468. // 拼接外部传入的其他参数otherCondition
  469. if (this.otherCondition) {
  470. param = Object.assign(param, this.otherCondition)
  471. }
  472. this.excute(this.service, this.service[this.methodsNameDetail], Object.assign(param, this.searchTable)).then(res => {
  473. if (res.code === 200) {
  474. this.batchKeysPage = []
  475. this.batchRowsPage = []
  476. let arr = []
  477. if (res.data && res.data.list) {
  478. arr = res.data.list;
  479. }
  480. if (!arr && res.data) {
  481. arr = res.data;
  482. }
  483. this.tableData = arr;
  484. if (param.currentPage == 1) {
  485. this.pageInfo.total = res.data.total
  486. this.pageInfo.currentPage = 1;
  487. }
  488. // console.log('value', this.value)
  489. // 根据传入的数据进行数据处理
  490. if (this.value && this.value.length > 0) {
  491. let filterRows = []
  492. let firstRow = null;
  493. // 如果value传递的不是数组,那么需要处理成数组
  494. this.value.forEach(it => {
  495. filterRows = arr.filter(row => row[this.selectKey] === it[this.selectKey] ||row[this.selectKey] === it )
  496. if (filterRows && filterRows.length > 0) {
  497. //给第一个行赋值 为了滚动定位 TODO
  498. // if(!firstRow){
  499. // firstRow = filterRows[0];
  500. // }
  501. if (this.rateField) {
  502. filterRows[0][this.rateField] = it[this.rateField]
  503. }
  504. filterRows[0][this.mainField] = it[this.mainField];
  505. if( it[this.selectLabel]){
  506. it[this.selectLabel] = filterRows[0][this.selectLabel];
  507. }
  508. //设置勾选
  509. this.setCheckRow(it, filterRows[0]);
  510. //如果传入值只是id的数组,并且传入了主业务id,将此id的行选中
  511. if(this.mainFieldId&&filterRows[0][this.selectKey]===this.mainFieldId){
  512. this.$set(filterRows[0], this.mainField, true);
  513. }
  514. }
  515. })
  516. // console.log('first',firstRow,this.value)
  517. //滚动到对应的行
  518. // this.$refs['table-select'].$refs['table'].scrollTo(0,500);
  519. //设置显示的名称
  520. this.setDisplayText();
  521. } else {
  522. // 没有点清空就根据传入的orderId进行查询
  523. if (!this.clearFlag) {
  524. // 要先处理下数据,兼容编辑
  525. if (this.orderId && this.orderId > 0) {
  526. this.tableData.forEach(row => {
  527. // 设置勾选
  528. if (row[this.selectFlag]) {
  529. this.setCheckRow(row, row);
  530. }
  531. })
  532. //设置显示的名称
  533. this.setDisplayText();
  534. }
  535. }
  536. }
  537. } else {
  538. this.$Message.warning(res.message)
  539. }
  540. })
  541. },
  542. /**
  543. * @desc : 设置勾选
  544. * @author : 周兴
  545. * @date : 2022/6/21 16:16
  546. */
  547. setCheckRow(it, row) {
  548. //传入值只有id的情况
  549. if(typeof it !== 'object'){
  550. if (!this.batchKeysPage.includes(it)) {
  551. this.batchKeysPage.push(it);
  552. this.batchRowsPage.push(row)
  553. this.$refs['table-select'].batchKeys = this.batchKeysPage;
  554. this.$refs['table-select'].batchRows = [...this.batchRowsPage];
  555. }
  556. this.$refs['table-select'].setCheckboxRow(row);
  557. }else{
  558. //传入行的情况
  559. if (!this.batchKeysPage.includes(it[this.selectKey])) {
  560. this.batchKeysPage.push(it[this.selectKey]);
  561. this.batchRowsPage.push(row)
  562. this.$refs['table-select'].batchKeys = this.batchKeysPage;
  563. this.$refs['table-select'].batchRows = [...this.batchRowsPage];
  564. }
  565. this.$refs['table-select'].setCheckboxRow(row);
  566. }
  567. // console.log('it',it,row,this.batchKeysPage,this.batchRowsPage)
  568. },
  569. /**
  570. * @desc : 放大镜点击事件
  571. * @author : 沈博
  572. * @date : 2022/3/7 14:21
  573. */
  574. magnifierClick(type) {
  575. if (this.readonly) {
  576. return;
  577. }
  578. // 如果focus,并且数据为空才会弹出选择框
  579. if (type && this.selectedValue) {
  580. return;
  581. }
  582. //打开从第一页开始
  583. // this.$refs['table-select'].pageInfo.currentPage = 1
  584. this.showModal = true
  585. if (this.model) {
  586. this.$refs['table-select'].batchKeys = [this.model]
  587. this.batchKeysPage = [this.model]
  588. }else if(this.value && this.value.length > 0){
  589. let batchKeys = this.value.map(it=>it[this.selectKey])
  590. if(this.$refs['table-select']){
  591. this.$refs['table-select'].batchKeys = batchKeys
  592. this.batchKeysPage = batchKeys
  593. // 查询已选数据
  594. this.getDataTableSelected();
  595. }
  596. }
  597. },
  598. /**
  599. * @desc : 清空数据
  600. * @author : 周兴
  601. * @date : 2022/3/17 17:29
  602. */
  603. clearAll() {
  604. this.clearFlag = true;
  605. this.showClear = false
  606. this.selectedValue = ''
  607. this.$refs['table-select']?.clearBatchKeys() //清空选择
  608. this.batchKeysPage = null
  609. this.batchRowsPage = null;
  610. this.$emit('ok', {rows: [], display: null});
  611. },
  612. /**
  613. * @desc : modal变化事件
  614. * @author : 沈博
  615. * @date : 2022/3/7 14:28
  616. */
  617. onVisibleChange(val) {
  618. if (val) {
  619. // this.getDataTable()
  620. } else {
  621. this.searchTable = {} // 关闭选择画面需要清空条件
  622. }
  623. },
  624. /**
  625. * @desc : 通过已选的id获取数据
  626. * @author : 周兴
  627. * @date : 2022/11/22 16:48
  628. */
  629. getDataTableSelected() {
  630. let batchKeys = this.$refs['table-select'].batchKeys;
  631. if (batchKeys && batchKeys.length > 0) {
  632. let param = {};
  633. param.currentPage = 1;
  634. param.pageSize = 10000;
  635. param.idList = batchKeys;
  636. param.userId = this.$store.state.user.id
  637. param.ftyId = this.$store.state.user.ftyId
  638. // 拼接外部传入的其他参数otherCondition
  639. if (this.otherCondition) {
  640. param = Object.assign(param, this.otherCondition)
  641. }
  642. this.excute(this.service, this.service[this.methodsNameDetail], param).then(res => {
  643. if (res.code === 200) {
  644. this.batchRowsPage = []
  645. if (res.data && res.data.list) {
  646. res.data.list.forEach(it => {
  647. this.batchRowsPage.push(it)
  648. })
  649. this.$refs['table-select'].batchRows = this.batchRowsPage;
  650. }
  651. }
  652. });
  653. }
  654. },
  655. /**
  656. * @desc : 校验是否选择
  657. * @author : 沈博
  658. * @date : 2022/3/7 15:44
  659. */
  660. checkBatch() {
  661. if (this.batchKeysPage.length <= 0) {
  662. this.$Message.warning('请先选择数据')
  663. return false
  664. }
  665. return true
  666. },
  667. /**
  668. * @desc : 恢复数据
  669. * @author : 周兴
  670. * @date : 2022/9/1 12:03
  671. */
  672. restore() {
  673. this.batchRowsPage = JSON.parse(JSON.stringify(this.batchRowsPageSocial))
  674. this.batchKeysPage = JSON.parse(JSON.stringify(this.batchKeysPageSocial))
  675. //设置显示的名称
  676. this.setDisplayText();
  677. },
  678. /**
  679. * @desc : 确定点击事件
  680. * @author : 沈博
  681. * @date : 2022/3/7 15:43
  682. */
  683. ok() {
  684. this.batchKeysPageSocial = JSON.parse(JSON.stringify(this.batchKeysPage))
  685. this.batchKeysPage = this.$refs['table-select'].batchKeys
  686. this.batchRowsPageSocial = JSON.parse(JSON.stringify(this.batchRowsPage))
  687. // 不用用batchRows,switch的数据不会变
  688. this.batchRowsPage = this.$refs['table-select'].getCheckRows();
  689. if (this.checkBatch()) {
  690. //主业务部门必须是门店
  691. // if (this.type === this.$config.MagnifierType.organization &&
  692. // this.batchRowsPage.some(s => s.ownerFlag && !s.flgStore)) {
  693. // this.$Message.warning(this.$t('W_052'))
  694. // return
  695. // }
  696. this.showModal = false
  697. let isShowOkEventFlag = true;
  698. //设置显示的名称
  699. this.setDisplayText(isShowOkEventFlag);
  700. //光标切回select组件
  701. this.$refs['input'].$refs.input.focus = true
  702. this.clearFlag = false;
  703. this.$emit('ok', {rows: this.batchRowsPage, display: this.selectedValue})
  704. // 清空查询条件
  705. this.$refs['searchCond']?.clearCondition();
  706. // 清空表格
  707. this.tableData = []
  708. }
  709. },
  710. /**
  711. * @desc : 设置显示的名称
  712. * @author : 周兴
  713. * @date : 2022/6/14 8:17
  714. */
  715. setDisplayText(isShowOkEventFlag) {
  716. //判断已选数据是否有
  717. if (this.batchRowsPage && this.batchRowsPage.length > 0) {
  718. // 把选择的数据显示出来,主的显示在第一位
  719. let display = ''
  720. let list = this.batchRowsPage.filter(it => it[this.mainField])
  721. // if (list && list.length > 0) {
  722. // display = list[0][this.selectLabel] + this.mainFieldText
  723. // }
  724. // 从业务数据
  725. let subList = this.batchRowsPage.filter(it => !it[this.mainField])
  726. if(this.checkAutoSetMainField){
  727. if (subList && subList.length > 0) {
  728. display = list[0][this.selectLabel] + this.mainFieldText
  729. display += ' | ';
  730. subList.forEach(it => {
  731. display += it[this.selectLabel] + ' | '
  732. })
  733. display = display.substring(0, display.length - 2)
  734. } else {
  735. display = list[0][this.selectLabel]
  736. }
  737. }else{
  738. display=list.length>0?list[0][this.selectLabel] + this.mainFieldText + ' | ':''
  739. subList.forEach(it => {
  740. display += it[this.selectLabel] + ' | '
  741. })
  742. display = display.substring(0, display.length - 2)
  743. }
  744. this.selectedValue = display;
  745. } else {
  746. this.selectedValue = null;
  747. }
  748. if (!isShowOkEventFlag) {
  749. this.$emit('ok', {rows: this.batchRowsPage, display: this.selectedValue})
  750. }
  751. },
  752. /**
  753. * @desc : 关闭点击事件
  754. * @author : 沈博
  755. * @date : 2022/3/7 15:43
  756. */
  757. cancel() {
  758. // 清空查询条件
  759. this.$refs['searchCond']?.clearCondition();
  760. // 清空表格
  761. this.tableData = []
  762. this.showModal = false
  763. },
  764. /**
  765. * @desc : 监听全局键盘按钮按下的事件
  766. * @author : 周兴
  767. * @date : 2022/3/4 16:57
  768. */
  769. addKeyBoardEvent() {
  770. let code = 0
  771. let self = this
  772. this.documentKeyDownContent = document.onkeydown
  773. document.onkeydown = function (e) {
  774. const evn = e || event
  775. const key = evn.keyCode || evn.which || evn.charCode
  776. // alt:code = 18
  777. if (key === 18) {
  778. code = 18
  779. }
  780. let btList = []
  781. for (let itKey in buttonList) {
  782. if (!buttonList[itKey].includes('(')) {
  783. continue
  784. }
  785. btList.push({
  786. name: itKey,
  787. hotKey: buttonList[itKey].substring(buttonList[itKey].length - 2, buttonList[itKey].length - 1)
  788. })
  789. }
  790. //只有modal弹出才能可见
  791. if (self.$refs.modal_search && self.$refs.modal_search.showModal) {
  792. // Q:code = 81 查询
  793. btList.forEach(forIt => {
  794. if (code === 18 && forIt.hotKey.toLowerCase() === e.key.toLowerCase()) {
  795. e.returnValue = false
  796. if (self.$refs[forIt.name]) {
  797. self.$refs[forIt.name].$el.click()
  798. }
  799. }
  800. })
  801. }
  802. }
  803. // 监听全局键盘按钮松开的事件
  804. document.onkeyup = function (e) {
  805. const evn = e || event
  806. const key = evn.keyCode || evn.which || evn.charCode
  807. if (key === 18) {
  808. code = 0
  809. }
  810. }
  811. },
  812. /**
  813. * @desc : 设置显示值
  814. * @author : 周兴
  815. * @date : 2022/6/15 15:48
  816. */
  817. setDefaultValue() {
  818. if (this.defaultValue) {
  819. this.selectedValue = this.defaultValue
  820. }
  821. },
  822. /**
  823. * @desc : 根据类型给属性赋值
  824. * @author : 周兴
  825. * @date : 2022/3/16 18:12
  826. */
  827. setMagnifierProperty() {
  828. let self = this
  829. // 员工
  830. if (self.type === self.$config.MagnifierType.user) {
  831. self.service = this.$service.commonService
  832. self.methodsNameDetail = 'selectMultiStaff'
  833. self.searchCond = ['userCode', 'userName']
  834. self.selectKey = 'staffId'
  835. self.selectLabel = 'userName'
  836. self.columns = [
  837. {field: this.rateField, width: '150'},
  838. {field: 'userCode', width: '200'},
  839. {field: 'userName', width: '200'},
  840. {field: 'organizationName', width: '200'},
  841. {field: 'ownerFlag', width: '40', type: 'switch', disabled: false},
  842. ]
  843. }
  844. // 产品
  845. else if (self.type === this.$config.MagnifierType.product) {
  846. self.service = this.$service.commonService
  847. self.methodsNameDetail = 'getModelProductByPage'
  848. // 查询条件
  849. self.searchContent = [
  850. {
  851. valueFormat: {code: 'modelCode'},
  852. },
  853. {
  854. valueFormat: {code: 'modelName'},
  855. },
  856. ]
  857. self.modalWidth = 600
  858. self.colCount = 2
  859. self.selectKey = 'modelId'
  860. self.selectLabel = 'modelName'
  861. self.columns = [
  862. {field: 'codeName', width: '150',title:self.$t('pdtModel')},
  863. {field: 'categoryName', width: '150'},
  864. {field: 'ownerFlag', width: '100', type: 'switch', disabled: false},
  865. {field: 'remarks', width: 'auto'},
  866. ]
  867. }
  868. // 部门
  869. else if (self.type === self.$config.MagnifierType.organization) {
  870. self.service = this.$service.commonService
  871. self.methodsNameDetail = 'selectMultiOrg'
  872. self.searchCond = ['orgName', 'orgCode']
  873. self.selectKey = 'orgId'
  874. self.selectLabel = 'orgName'
  875. self.columns = [
  876. {field: this.rateField, width: '150'},
  877. {field: 'orgName', width: '200'},
  878. {field: 'orgCode', width: '200'},
  879. {field: 'ownerFlag', width: '40', type: 'switch', disabled: false},
  880. ]
  881. }
  882. // 结算方式
  883. else if (self.type === self.$config.MagnifierType.settlementType) {
  884. self.service = this.$service.commonService
  885. self.methodsNameDetail = 'selectSettlementTypeByOrgId'
  886. self.selectKey = 'typeId'
  887. self.selectLabel = 'typeName'
  888. self.columns = [
  889. {field: 'typeName', width: 'auto'},
  890. {field: 'settlementTypesFlgDefault', width: '40', type: 'switch', disabled: false},
  891. ]
  892. }
  893. // 仓库
  894. /*else if (self.type === self.$config.MagnifierType.warehouse) {
  895. self.service = this.$service.commonService
  896. self.methodsNameDetail = 'getWarehouse'
  897. self.searchCond = ['warehouseName']
  898. self.selectKey = 'whId'
  899. self.selectLabel = 'warehouseName'
  900. self.columns = [
  901. {field: 'warehouseName', minWidth: 'auto'},
  902. {field: 'warehouseFlgDefault', width: '40', type: 'switch', disabled: false},
  903. ]
  904. }*/
  905. // 仓库
  906. else if (self.type === self.$config.MagnifierType.warehouse) {
  907. self.service = this.$service.commonService
  908. self.methodsNameDetail = 'getWarehouseByPage' //详细函数名称,目前对应后台的查询接口名称
  909. self.searchCond = [
  910. {itemCode: 'whName'}, //查询条件
  911. {itemCode: 'whCode'},
  912. ]
  913. self.selectKey = 'whId' //主键
  914. self.selectLabel = 'whName' //显示的列
  915. self.modalWidth = 700
  916. self.colCount = 2
  917. self.columns = [
  918. {field: 'whName', width: '100'}, //查询出来的字段以及宽度
  919. {field: 'whCode', width: '100'},
  920. {field: 'mmCode', width: '100'},
  921. {field: 'directorName', width: '100'},
  922. {field: 'contactsName', width: '100'},
  923. {field: 'contactNo', width: '100'},
  924. {field: 'cpName', width: '100'},
  925. {field: 'remarks', width: '100'},
  926. {field: 'flgDefault', title: "flgDefaultWh", width: '100', type: 'switch', disabled: false},
  927. ]
  928. }
  929. //资金账号
  930. else if (self.type === self.$config.MagnifierType.capitalAccount) {
  931. self.service = this.$service.commonService
  932. self.methodsName = 'getCapitalAccount'
  933. self.methodsNameDetail = 'getCapitalAccountByPage'
  934. self.searchCond = [
  935. {itemCode: 'capitalName'},
  936. {itemCode: 'capitalType'},
  937. ]
  938. self.selectKey = 'capitalId'
  939. self.selectLabel = 'capitalName'
  940. self.modalWidth = 700
  941. self.colCount = 2
  942. self.columns = [
  943. {field: 'capitalName', width: '100'},
  944. {field: 'mmCode', width: '100'},
  945. {field: 'capitalType', width: '100'},
  946. {field: 'cpName', width: '100'},
  947. {field: 'openingCompany', width: '100'},
  948. {field: 'openingBank', width: '100'},
  949. {field: 'bankAccount', width: '100'},
  950. {field: 'remarks', width: '100'},
  951. {field: 'flgDefault', title: 'flgDefaultCa', width: '100', type: 'switch', disabled: false},
  952. ]
  953. }
  954. //可判定分级
  955. else if (self.type === self.$config.MagnifierType.judgeGrade) {
  956. self.service = this.$service.productGradeService
  957. self.methodsNameDetail = 'selectByCond'
  958. self.selectKey = 'gradeId'
  959. self.selectLabel = 'gradeName'
  960. self.columns = [
  961. {field: 'gradeName', width: '100'},
  962. {field: 'defGradeId', title: 'defGradeId', width: '100', type: 'switch', disabled: false},
  963. ]
  964. }
  965. }
  966. },
  967. created() {
  968. this.setMagnifierProperty() // 根据类型给属性赋值
  969. if (!this.placeholderData) {
  970. this.placeholderData = vm.$t('inputWords', {'search-name': vm.$t(this.prop)})
  971. }
  972. //赋默认值
  973. this.setDefaultValue();
  974. },
  975. mounted() {
  976. // this.getDataTable()
  977. }
  978. }
  979. </script>
  980. <style scoped>
  981. /deep/ .ivu-modal-body {
  982. padding: 0 10px 10px 10px;
  983. background: #eaedf7 !important;
  984. }
  985. /deep/ .btn-div {
  986. position: relative;
  987. }
  988. /deep/ .btn-div + div {
  989. height: 0 !important;
  990. }
  991. /deep/ .ivu-select-arrow {
  992. display: none;
  993. }
  994. /deep/ .ivu-icon-ios-arrow-down {
  995. display: none !important;
  996. }
  997. /deep/ .ivu-input {
  998. padding-right: 20px !important;
  999. }
  1000. .input-class {
  1001. height: 30px;
  1002. line-height: 30px;
  1003. }
  1004. </style>