template-page-1.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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. 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 || arr[i].isRole === undefined) || arr[i].length == 0) {
  370. arr.splice(i, 1)
  371. i--
  372. }
  373. }
  374. return arr
  375. },
  376. // 获取下拉对应数据
  377. getCodeGather() {
  378. let codes = this.frontCodes.filter(key => (this.codeGather[key] ? false : true))
  379. if (codes && codes.length) {
  380. var codeGather = {}
  381. Promise.all(
  382. codes.map(code => {
  383. if (selectData[code]) {
  384. return selectData[code]()
  385. }
  386. return dictListDict({ code: code })
  387. })
  388. ).then(resAll => {
  389. codes.map((code, index) => {
  390. var arr = resAll[index].data.map(item => {
  391. return { value: item.dictCode, label: item.dictValue }
  392. })
  393. codeGather[code] = arr
  394. })
  395. this.codeGather = { ...this.codeGather, ...codeGather }
  396. })
  397. }
  398. },
  399. // 获取列表数据函数
  400. async getTableData(data) {
  401. if (!this.getList) {
  402. return
  403. }
  404. try {
  405. this.parameter = {
  406. pageNum: data.page,
  407. pageSize: data.size,
  408. orderBy: data.orderBy,
  409. params: data.querylist,
  410. moduleId: this.moduleId
  411. }
  412. var res = await this.getList(this.parameter)
  413. if (res.code == 200) {
  414. if (!this.showTable) {
  415. this.$nextTick(() => {
  416. this.showTable = true
  417. })
  418. }
  419. // 全局过滤特殊列表
  420. /**------------------------------------------------------------------------------------------------------- */
  421. var listcp = [...res.fieldBeans]
  422. if (!~['100093', '600023', '', null, undefined].indexOf(this.$store.state?.user?.userInfo?.customerNumber)) {
  423. for (var i = 0; i < listcp.length; i++) {
  424. if (~['是否同步到格匠采购入库单', '同步格匠失败原因'].indexOf(listcp[i].label)) {
  425. listcp.splice(i, 1)
  426. i--
  427. }
  428. }
  429. }
  430. res.fieldBeans = listcp
  431. /**------------------------------------------------------------------------------------------------------- */
  432. if (this.fieldBeansHook) {
  433. res.fieldBeans = this.fieldBeansHook(res.fieldBeans) || res.fieldBeans
  434. }
  435. for (let item of res.fieldBeans) {
  436. if (item.jname === 'createTime') {
  437. this.setDefaultPlan(`${item.tbName ? item.tbName + '.' : ''}${item.colName}`)
  438. }
  439. if (item.pk) {
  440. this.$nextTick(() => {
  441. this.pk = item.colName
  442. })
  443. }
  444. if (item.frontCode && !~this.frontCodes.indexOf(item.frontCode)) {
  445. this.frontCodes.push(item.frontCode)
  446. }
  447. if (this.cstomClumn && item.label === 'cstomClumn') {
  448. this.cstomClumn(item.jname, res.data.records, res.fieldBeans, this.parameter)
  449. }
  450. }
  451. this.getCodeGather()
  452. return res
  453. }
  454. } catch (error) {
  455. console.log(error)
  456. }
  457. },
  458. // 监听列表显示状态与排序变化
  459. columnListChange(columnList) {
  460. zfireSave(
  461. this.$refs.zjpage.columnList.map((item, index) => {
  462. var data = {
  463. ...item.exportField,
  464. sortNum: index,
  465. isCopy: item.isCopy,
  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. // 导出
  515. export() {
  516. this.columnList = this.$refs.zjpage.columnList
  517. },
  518. exportDetermine(data) {
  519. if (!this.exportList) {
  520. return
  521. }
  522. const loading = this.$loading({
  523. lock: true,
  524. text: 'Loading',
  525. spinner: 'el-icon-loading',
  526. background: 'rgba(0, 0, 0, 0.7)'
  527. })
  528. this.evens[0][0].loading = true
  529. this.exportList(
  530. {
  531. ...this.parameter,
  532. pageSize: -1,
  533. exportFields: data
  534. },
  535. `${this.moduleName}.xlsx`
  536. )
  537. .then(res => {
  538. this.$message({
  539. message: '导出成功',
  540. type: 'success'
  541. })
  542. this.columnList = []
  543. this.evens[0][0].loading = false
  544. loading.close()
  545. })
  546. .catch(err => {
  547. this.$message.error('导出失败')
  548. this.columnList = []
  549. this.evens[0][0].loading = false
  550. loading.close()
  551. })
  552. },
  553. refreshList(bool) {
  554. if (bool === true) {
  555. this.showTable = false
  556. this.$refs.zjpage.refresh()
  557. } else {
  558. this.$refs.zjpage.refresh()
  559. }
  560. }
  561. }
  562. }
  563. </script>
  564. <style lang="scss" scoped>
  565. .template-page-1 {
  566. width: 100%;
  567. height: 100%;
  568. position: relative;
  569. box-sizing: border-box;
  570. min-width: 860px;
  571. overflow: auto;
  572. }
  573. .zj-page-template {
  574. position: relative;
  575. z-index: 0;
  576. }
  577. @font-face {
  578. font-family: 'aliyun_iconfont';
  579. src: url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff2') format('woff2'),
  580. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.woff') format('woff'),
  581. url('~@/components/template/font/font_2075393_0cjq4n8ykvds.ttf') format('truetype');
  582. }
  583. ::v-deep .el-table__cell {
  584. padding: 0 !important;
  585. }
  586. ::v-deep .el-table--mini td,
  587. ::v-deep .el-table--mini th {
  588. padding: 0 !important;
  589. }
  590. ::v-deep .el-table__column-filter-trigger {
  591. .el-icon-arrow-down {
  592. font-family: aliyun_iconfont !important;
  593. font-size: 13px;
  594. line-height: 34px;
  595. font-style: normal;
  596. font-weight: 400;
  597. font-variant: normal;
  598. text-transform: none;
  599. vertical-align: baseline;
  600. display: inline-block;
  601. -webkit-font-smoothing: antialiased;
  602. transform: translate(-2px, 1px);
  603. color: #c0c4cc;
  604. width: 20px;
  605. text-align: center;
  606. }
  607. .el-icon-arrow-down:before {
  608. content: '\e64c' !important;
  609. }
  610. }
  611. ::v-deep .zj-buttons-group {
  612. .el-upload-list {
  613. display: none !important;
  614. }
  615. }
  616. ::v-deep .operation-btns {
  617. width: 100%;
  618. height: 35px;
  619. display: flex;
  620. flex-direction: row;
  621. align-items: center;
  622. & > *:not(:last-child) {
  623. margin-right: 5px;
  624. }
  625. .el-button {
  626. margin-left: 0 !important;
  627. }
  628. }
  629. ::v-deep .is-disabled {
  630. .el-textarea__inner,
  631. .el-input__inner,
  632. .el-radio__label,
  633. .el-radio__input {
  634. background-color: #fff !important;
  635. color: #606266 !important;
  636. // border: none !important;
  637. }
  638. }
  639. ::v-deep .el-checkbox.is-bordered.is-checked,
  640. ::v-deep .el-radio.is-bordered.is-checked {
  641. border-color: #409eff !important;
  642. }
  643. ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner,
  644. ::v-deep .el-radio__input.is-checked .el-radio__inner {
  645. border-color: #409eff !important;
  646. background: #409eff !important;
  647. }
  648. ::v-deep .el-checkbox.is-bordered {
  649. margin-left: 0 !important;
  650. margin-right: 10px !important;
  651. }
  652. </style>