template-page-1.vue 18 KB

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