template-page-1.vue 19 KB

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