template-page-1.vue 18 KB

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