template-page-1.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <template>
  2. <div class="template-page-1">
  3. <zj-page-template
  4. ref="zjpage"
  5. tableMinHeight="300px"
  6. :getTableData="getTableData"
  7. :columnParsing="columnParsing"
  8. :reduction="reduction"
  9. :showTable="showTable"
  10. :codeGather="codeGather"
  11. :loading="loading"
  12. :lowerLine="true"
  13. :onSavePlan="onSavePlan"
  14. :onClosePlain="onClosePlain"
  15. :defaultSearchData="defaultSearchData"
  16. :replaceOrNotMap="replaceOrNotMap"
  17. :optionsEvensGroup="selBtn([...optionsEvensGroup, evens])"
  18. :operation="operation"
  19. :operationColumnWidth="operationColumnWidth"
  20. :plan="[...defaultPlan, ...timePlan, ...paramList, ...morePlan]"
  21. :tableEvents="{ ...defaultTableEvents, ...tableEvents }"
  22. :tableAttributes="{ ...defaultTableAttributes, ...tableAttributes }"
  23. :ellipsis="ellipsis"
  24. :pageSizes="pageSizes"
  25. @columnWidthChange="columnWidthChange"
  26. @columnListChange="columnListChange"
  27. :screeningAnalysis="screeningAnalysis"
  28. :filterMethod="filterMethod"
  29. :sortMethod="sortMethod"
  30. :moreParameters="moreParameters"
  31. >
  32. <template slot="more-search">
  33. <slot name="moreSearch"></slot>
  34. </template>
  35. </zj-page-template>
  36. <sel-export-column-list :columnList="columnList" @determine="exportDetermine" @cancel="columnList = []" />
  37. <slot />
  38. <el-dialog title="定义方案名" :visible.sync="dialogVisible" width="380px" :before-close="handleClose">
  39. <el-input size="mini" maxlength="8" show-word-limit v-model="inputText" placeholder="请输入名称"></el-input>
  40. <span slot="footer" class="dialog-footer">
  41. <el-button size="mini" @click="handleClose">取 消</el-button>
  42. <el-button size="mini" type="primary" @click="onSavePlanqd">确 定</el-button>
  43. </span>
  44. </el-dialog>
  45. </div>
  46. </template>
  47. <script>
  48. import { zfireSave, zfireDel } from '@/api/fieldMan.js'
  49. import { dictListDict } from '@/api/dataDictionary.js'
  50. import { zfireParamList, zfireParamSave, zfireParamDelete } from '@/api/zfireParam.js'
  51. import SelExportColumnList from './sel-export-column-list.vue'
  52. import selectData from './selectData.js'
  53. import operation_mixin from '@/components/template/operation_mixin.js'
  54. export default {
  55. components: {
  56. SelExportColumnList
  57. },
  58. mixins: [operation_mixin],
  59. props: {
  60. ellipsis: {
  61. type: Boolean,
  62. default: true
  63. },
  64. moreParameters: {
  65. type: Array,
  66. default: () => []
  67. },
  68. loading: {
  69. type: Boolean,
  70. default: false
  71. },
  72. // 事件组合
  73. optionsEvensGroup: {
  74. type: Array,
  75. default: () => []
  76. },
  77. // 表格属性
  78. tableAttributes: {
  79. type: Object,
  80. default: () => ({})
  81. },
  82. // 表格事件
  83. tableEvents: {
  84. type: Object,
  85. default: () => ({})
  86. },
  87. // 表格列解析渲染数据更改
  88. columnParsing: {
  89. type: Function
  90. },
  91. // 获取列表的方法
  92. getList: {
  93. type: Function
  94. },
  95. // 导出的方法
  96. exportList: {
  97. type: Function
  98. },
  99. // 更多方案
  100. morePlan: {
  101. type: Array,
  102. default: () => []
  103. },
  104. // 操作按钮
  105. operation: {
  106. type: Function
  107. },
  108. // 获取操作记录的主键字段
  109. operationRecordkey: {
  110. type: String,
  111. default: ''
  112. },
  113. // 操作按钮单元格宽度
  114. operationColumnWidth: {
  115. type: Number,
  116. default: 140
  117. },
  118. // 自定义列
  119. cstomClumn: {
  120. type: Function
  121. },
  122. // 结构数据钩子
  123. fieldBeansHook: {
  124. type: Function
  125. },
  126. // 菜单名称
  127. customModuleName: {
  128. type: String,
  129. default: ''
  130. },
  131. defaultSearchData: {
  132. type: Array,
  133. default: () => []
  134. },
  135. replaceOrNotMap: {
  136. type: Boolean,
  137. default: false
  138. },
  139. setModuleId: {
  140. type: [String, Number],
  141. default: null
  142. },
  143. screeningAnalysis: {
  144. type: Function,
  145. default: (jname, val) => {
  146. return val
  147. }
  148. },
  149. filterMethod: {
  150. type: Function,
  151. default: (value, row, column) => {
  152. return row[column['property']] === value
  153. }
  154. },
  155. sortMethod: {
  156. type: Function,
  157. default: undefined
  158. },
  159. pageSizes: {
  160. type: Array,
  161. default: () => [15, 30, 50, 100, 150, 200]
  162. },
  163. expCode: {
  164. type: String,
  165. default: 'exp'
  166. },
  167. // 数据钩子
  168. recordsHook: {
  169. type: Function
  170. }
  171. },
  172. data() {
  173. return {
  174. dialogVisible: false,
  175. // 搜索的参数
  176. parameter: {},
  177. // 表格属性
  178. defaultTableAttributes: {},
  179. // 表格事件
  180. defaultTableEvents: {},
  181. // 记录初始的id
  182. columnsIds: {},
  183. // 导出弹窗
  184. columnList: [],
  185. showTable: false,
  186. codeGather: {},
  187. frontCodes: [],
  188. planItem: null,
  189. inputText: '',
  190. defaultPlan: [
  191. {
  192. name: '默认方案',
  193. paramCallback: () => {
  194. return []
  195. }
  196. }
  197. ],
  198. paramList: [],
  199. timePlan: [],
  200. pk: ''
  201. }
  202. },
  203. computed: {
  204. userid() {
  205. return this.$store.getters.userid
  206. },
  207. moduleId() {
  208. return this.setModuleId || this.$route.meta.moduleId
  209. },
  210. moduleName() {
  211. return this.customModuleName || this.$route.meta.title
  212. },
  213. evens() {
  214. return this.exportList
  215. ? [
  216. [
  217. this.optionsEvensAuth(this.expCode, {
  218. click: this.export
  219. })
  220. ]
  221. ]
  222. : []
  223. }
  224. },
  225. mounted() {
  226. this.getZfireParamList()
  227. },
  228. methods: {
  229. insertionData(...p) {
  230. this.$refs.zjpage.insertionData(...p)
  231. },
  232. deleteRowData(...p) {
  233. this.$refs.zjpage.deleteRowData(...p)
  234. },
  235. tableForm() {
  236. return this.$refs.zjpage.$refs.tableForm
  237. },
  238. getTimeDay(num = 0) {
  239. var day2 = new Date()
  240. if (num > 0) {
  241. day2.setTime(day2.getTime() + 24 * 60 * 60 * 1000 * Math.abs(num))
  242. } else if (num < 0) {
  243. day2.setTime(day2.getTime() - 24 * 60 * 60 * 1000 * Math.abs(num))
  244. } else {
  245. day2.setTime(day2.getTime())
  246. }
  247. return (
  248. day2.getFullYear() +
  249. '-' +
  250. (day2.getMonth() + 1 < 10 ? `0${day2.getMonth() + 1}` : day2.getMonth() + 1) +
  251. '-' +
  252. (day2.getDate() < 10 ? `0${day2.getDate()}` : day2.getDate())
  253. )
  254. },
  255. setDefaultPlan(createTimeKey) {
  256. this.$nextTick(() => {
  257. if (createTimeKey) {
  258. var day = this.getTimeDay()
  259. var day1 = this.getTimeDay(-1)
  260. this.timePlan = [
  261. {
  262. name: '今日',
  263. paramCallback: () => {
  264. return [
  265. { param: createTimeKey, compare: '>=', value: `${day} 00:00:00` },
  266. { param: createTimeKey, compare: '<=', value: `${day} 23:59:59` }
  267. ]
  268. }
  269. },
  270. {
  271. name: '昨日',
  272. paramCallback: () => {
  273. return [
  274. { param: createTimeKey, compare: '>=', value: `${day1} 00:00:00` },
  275. { param: createTimeKey, compare: '<=', value: `${day1} 23:59:59` }
  276. ]
  277. }
  278. }
  279. ]
  280. }
  281. })
  282. },
  283. // 关闭方案命名弹窗
  284. handleClose() {
  285. this.planItem = null
  286. this.inputText = ''
  287. this.dialogVisible = false
  288. },
  289. // 获取方案记录
  290. getZfireParamList() {
  291. zfireParamList({
  292. moduleId: this.moduleId
  293. }).then(res => {
  294. this.paramList = res.data.map(item => {
  295. return {
  296. name: item.name,
  297. id: item.id,
  298. closable: true,
  299. paramCallback: () => {
  300. return item.items.map(dav => {
  301. if (dav.value[0] == '[' && dav.value[dav.value.length - 1] == ']') {
  302. return {
  303. param: dav.param,
  304. compare: dav.compare,
  305. value: dav.value.substring(1, dav.value.length - 1).split(',')
  306. }
  307. }
  308. return { param: dav.param, compare: dav.compare, value: dav.value }
  309. })
  310. }
  311. }
  312. })
  313. })
  314. },
  315. // 点击获取保存方案数据
  316. onSavePlan(p) {
  317. if (this.paramList.length >= 10) {
  318. this.$message.error('自定义方案最多支持保留10个')
  319. return
  320. }
  321. if (p.length) {
  322. this.planItem = p
  323. this.dialogVisible = true
  324. } else {
  325. this.$message.error('请先设置搜索条件')
  326. }
  327. },
  328. // 确定保存方案
  329. onSavePlanqd() {
  330. if (this.inputText) {
  331. zfireParamSave({
  332. moduleId: this.moduleId,
  333. name: this.inputText,
  334. items: this.planItem
  335. }).then(res => {
  336. this.handleClose()
  337. this.getZfireParamList()
  338. })
  339. } else {
  340. this.$message.error('请先填写方案名称')
  341. }
  342. },
  343. // 删除方案
  344. onClosePlain(p) {
  345. if (p.id) {
  346. this.$confirm('删除此方案, 是否继续?', '提示', {
  347. confirmButtonText: '确定',
  348. cancelButtonText: '取消',
  349. type: 'warning'
  350. })
  351. .then(() => {
  352. zfireParamDelete({ id: p.id }).then(res => {
  353. this.$message({
  354. message: '删除成功',
  355. type: 'success'
  356. })
  357. this.getZfireParamList()
  358. })
  359. })
  360. .catch(() => {})
  361. }
  362. },
  363. // 过滤按钮集合
  364. selBtn(arr) {
  365. for (var i = 0; i < arr.length; i++) {
  366. if (Array.isArray(arr[i])) {
  367. this.selBtn(arr[i])
  368. }
  369. if (!(arr[i].isRole === undefined ? true : this.carryOutIsRole(arr[i].isRole)) || arr[i].length == 0) {
  370. arr.splice(i, 1)
  371. i--
  372. }
  373. }
  374. return arr
  375. },
  376. carryOutIsRole(isRole) {
  377. if (typeof isRole === 'function') {
  378. return isRole()
  379. }
  380. return isRole
  381. },
  382. // 获取下拉对应数据
  383. getCodeGather() {
  384. let codes = this.frontCodes.filter(key => (this.codeGather[key] ? false : true))
  385. if (codes && codes.length) {
  386. var codeGather = {}
  387. Promise.all(
  388. codes.map(code => {
  389. if (selectData[code]) {
  390. return selectData[code]()
  391. }
  392. return dictListDict({ dictType: code })
  393. })
  394. ).then(resAll => {
  395. codes.map((code, index) => {
  396. var arr = resAll[index].data.map(item => {
  397. return { value: item.dictCode, label: item.dictValue }
  398. })
  399. codeGather[code] = arr
  400. })
  401. this.codeGather = { ...this.codeGather, ...codeGather }
  402. })
  403. }
  404. },
  405. // 获取列表数据函数
  406. async getTableData(data) {
  407. if (!this.getList) {
  408. return
  409. }
  410. try {
  411. var { querylist, page, size, ...data_ } = data
  412. this.parameter = {
  413. ...data_,
  414. pageNum: page,
  415. pageSize: size,
  416. params: querylist,
  417. moduleId: this.moduleId
  418. }
  419. var res = await this.getList(this.parameter)
  420. // alert('接收到数据断点')
  421. if (res.code == 200) {
  422. if (this.recordsHook) {
  423. res.data.records = this.recordsHook([...(res?.data?.records || [])]) || res?.data?.records || []
  424. }
  425. if (this.fieldBeansHook) {
  426. res.fieldBeans = this.fieldBeansHook(res.fieldBeans) || res.fieldBeans
  427. }
  428. for (let item of res.fieldBeans) {
  429. if (item.jname === 'createTime') {
  430. this.setDefaultPlan(`${item.tbName ? item.tbName + '.' : ''}${item.colName}`)
  431. }
  432. if (item.pk) {
  433. this.$nextTick(() => {
  434. this.pk = item.colName
  435. })
  436. }
  437. if (item.frontCode && !~this.frontCodes.indexOf(item.frontCode)) {
  438. this.frontCodes.push(item.frontCode)
  439. }
  440. if (item.label === 'cstomClumn' && this.cstomClumn) {
  441. this.cstomClumn(item.jname, res.data.records, res.fieldBeans, this.parameter)
  442. }
  443. }
  444. this.getCodeGather()
  445. return res
  446. }
  447. } catch (error) {
  448. console.log(error)
  449. } finally {
  450. if (!this.showTable) {
  451. this.$nextTick(() => {
  452. this.showTable = true
  453. })
  454. }
  455. }
  456. },
  457. // 监听列表显示状态与排序变化
  458. columnListChange(columnList) {
  459. zfireSave(
  460. this.$refs.zjpage.columnList.map((item, index) => {
  461. var data = {
  462. ...item.exportField,
  463. sortNum: Number(item.sortNum),
  464. isCopy: item.isCopy,
  465. tiling: item.tiling,
  466. isTotal: item.isTotal,
  467. isShow: !item.hidden,
  468. moduleId: this.moduleId,
  469. adminUserId: this.userid
  470. }
  471. return data
  472. }),
  473. this.moduleId
  474. )
  475. .then(res => {})
  476. .catch(err => {
  477. this.$message.error('保存失败')
  478. })
  479. },
  480. // 监听列宽度变化
  481. columnWidthChange({ newWidth, oldWidth, column }) {
  482. zfireSave(
  483. this.$refs.zjpage.columnList.map((item, index) => {
  484. if (item.exportField.jname === column.property) {
  485. item.exportField.width = newWidth
  486. }
  487. return {
  488. ...item.exportField,
  489. sortNum: index,
  490. isCopy: item.isCopy,
  491. isTotal: item.isTotal,
  492. isShow: !item.hidden,
  493. moduleId: this.moduleId,
  494. adminUserId: this.userid
  495. }
  496. }),
  497. this.moduleId
  498. )
  499. .then(res => {})
  500. .catch(err => {
  501. this.$message.error('保存失败')
  502. })
  503. },
  504. // 表格恢复初始默认状态
  505. reduction() {
  506. zfireDel({}, this.userid, this.moduleId)
  507. .then(res => {
  508. this.refreshList(true)
  509. })
  510. .catch(err => {
  511. this.$message.error('操作失败')
  512. })
  513. },
  514. getParams() {
  515. var querylist_ = this.$refs.zjpage.$refs.dynamicCondition.jiexi(
  516. JSON.parse(JSON.stringify(this.$refs.zjpage.$refs.dynamicCondition.queryData))
  517. )
  518. return this.$refs.zjpage.parameterAnalysis({ querylist: querylist_ })
  519. },
  520. // 导出
  521. export() {
  522. this.columnList = this.$refs.zjpage.columnList.filter(item => !item.hidden)
  523. },
  524. async exportDetermine(data) {
  525. if (!this.exportList) {
  526. return
  527. }
  528. const loading = this.$loading({
  529. lock: true,
  530. text: '正在导出',
  531. spinner: 'el-icon-loading',
  532. background: 'rgba(0, 0, 0, 0.7)'
  533. })
  534. var { querylist, ...p } = this.getParams()
  535. var pms = {
  536. ...this.parameter,
  537. ...p,
  538. pageSize: 1,
  539. params: querylist.map(item => {
  540. item.param = item.param.replace(/>=/g, '')
  541. item.param = item.param.replace(/<=/g, '')
  542. if (
  543. // item.compare === '=' &&
  544. typeof item.value === 'string' &&
  545. (~item.value.indexOf(',') || ~item.value.indexOf(','))
  546. ) {
  547. // 去除换行
  548. var str = item.value.replace(/\\n/g, '')
  549. // 去除空格
  550. str = str.replace(/[\t\r\f\n\s]*/g, '')
  551. // 转中文逗号
  552. str = str.replace(/,/g, ',')
  553. // 切割为数组
  554. item.value = str.split(',')
  555. }
  556. return item
  557. })
  558. }
  559. var newPms = {}
  560. var res = await this.getList(pms, data => {
  561. newPms = data
  562. })
  563. // alert('接收到数据断点')
  564. if (res.code == 200) {
  565. if (res?.data?.records?.length) {
  566. this.exportList(
  567. {
  568. ...pms,
  569. ...newPms,
  570. pageSize: -1,
  571. exportFields: data
  572. },
  573. `${this.moduleName}.xlsx`
  574. )
  575. .then(res => {
  576. this.$message({
  577. message: '导出成功',
  578. type: 'success'
  579. })
  580. this.columnList = []
  581. loading.close()
  582. })
  583. .catch(err => {
  584. this.$message.error('导出失败')
  585. this.columnList = []
  586. loading.close()
  587. })
  588. } else {
  589. this.$message.error('导出条件没有查到任何符合条件的数据,请调整查询条件再导出。')
  590. this.columnList = []
  591. loading.close()
  592. }
  593. } else {
  594. this.columnList = []
  595. loading.close()
  596. }
  597. },
  598. refreshList() {
  599. this.$refs.zjpage.refresh()
  600. }
  601. }
  602. }
  603. </script>
  604. <style lang="scss" scoped>
  605. .template-page-1 {
  606. width: 100%;
  607. height: 100%;
  608. position: relative;
  609. box-sizing: border-box;
  610. overflow: auto;
  611. }
  612. .zj-page-template {
  613. position: relative;
  614. z-index: 0;
  615. }
  616. @font-face {
  617. font-family: 'aliyun_iconfont';
  618. src: url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff2') format('woff2'),
  619. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff') format('woff'),
  620. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.ttf') format('truetype');
  621. }
  622. ::v-deep .el-table__cell {
  623. padding: 0 !important;
  624. }
  625. ::v-deep .el-table--mini td,
  626. ::v-deep .el-table--mini th {
  627. padding: 0 !important;
  628. }
  629. ::v-deep .el-table__column-filter-trigger {
  630. .el-icon-arrow-down {
  631. font-family: aliyun_iconfont !important;
  632. font-size: 13px;
  633. line-height: 34px;
  634. font-style: normal;
  635. font-weight: 400;
  636. font-variant: normal;
  637. text-transform: none;
  638. vertical-align: baseline;
  639. display: inline-block;
  640. -webkit-font-smoothing: antialiased;
  641. transform: translate(-2px, 1px);
  642. color: #c0c4cc;
  643. width: 20px;
  644. text-align: center;
  645. }
  646. .el-icon-arrow-down:before {
  647. content: '\e64c' !important;
  648. }
  649. }
  650. ::v-deep .zj-buttons-group {
  651. .el-upload-list {
  652. display: none !important;
  653. }
  654. }
  655. ::v-deep .operation-btns {
  656. width: 100%;
  657. height: 35px;
  658. display: flex;
  659. flex-direction: row;
  660. align-items: center;
  661. & > *:not(:last-child) {
  662. margin-right: 5px;
  663. }
  664. .el-button {
  665. margin-left: 0 !important;
  666. }
  667. }
  668. ::v-deep .is-disabled {
  669. .el-textarea__inner,
  670. .el-input__inner,
  671. .el-radio__label,
  672. .el-radio__input {
  673. background-color: rgba(228, 231, 237, 0.35) !important;
  674. color: #606266 !important;
  675. }
  676. }
  677. ::v-deep .el-checkbox.is-bordered.is-checked,
  678. ::v-deep .el-radio.is-bordered.is-checked {
  679. border-color: #409eff !important;
  680. }
  681. ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner,
  682. ::v-deep .el-radio__input.is-checked .el-radio__inner {
  683. border-color: #409eff !important;
  684. background: #409eff !important;
  685. }
  686. ::v-deep .el-checkbox.is-bordered {
  687. margin-left: 0 !important;
  688. margin-right: 10px !important;
  689. }
  690. ::v-deep .teshudeshangchuananniu {
  691. color: #fff !important;
  692. }
  693. ::v-deep .el-table__row {
  694. .is-right {
  695. .text-view {
  696. text-align: right !important;
  697. display: flex;
  698. justify-content: flex-end !important;
  699. flex-wrap: wrap;
  700. }
  701. }
  702. .is-left {
  703. .text-view {
  704. text-align: left !important;
  705. justify-content: flex-start !important;
  706. flex-wrap: wrap;
  707. }
  708. }
  709. }
  710. </style>