template-page-1.vue 19 KB

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