index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <el-button type="primary" size="mini" @click="toAdd()">添加</el-button>
  7. </el-col>
  8. <el-col :span="24">
  9. <data-table @query="search" :fields="fields" :opera="opera" :data="list" :total="total" @download="toDownload" @edit="toEdit" @del="toDel">
  10. </data-table>
  11. </el-col>
  12. </el-col>
  13. </el-row>
  14. <el-dialog title="证书资料" center width="30%" :close-on-click-modal="false" :visible.sync="certShow" destroy-on-close @closed="certClose">
  15. <form-1 :form="form" @onSubmit="onSubmit" :userList="userList" :applyList="applyList"></form-1>
  16. </el-dialog>
  17. </div>
  18. </template>
  19. <script>
  20. import form1 from './parts/form-1.vue';
  21. import dataTable from '@common/src/components/frame/filter-page-table.vue';
  22. import { mapState, createNamespacedHelpers } from 'vuex';
  23. const { mapActions } = createNamespacedHelpers('achieve_cert');
  24. const { mapActions: achieveApply } = createNamespacedHelpers('achieveApply');
  25. const { mapActions: personal } = createNamespacedHelpers('personal');
  26. export default {
  27. name: 'index',
  28. props: {},
  29. components: { dataTable, form1 },
  30. data: function() {
  31. return {
  32. list: [],
  33. total: 0,
  34. opera: [
  35. { label: '证书下载', method: 'download' },
  36. { label: '修改', method: 'edit' },
  37. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  38. ],
  39. fields: [
  40. { label: '成果名称', prop: 'apply_name', filter: true },
  41. { label: '申请人', prop: 'user_name', filter: true },
  42. { label: '证书资料', prop: 'file.name' },
  43. { label: '创建时间', prop: 'create_time' },
  44. ],
  45. // 成果
  46. applyList: [],
  47. // 用戶
  48. userList: [],
  49. // 证书资料
  50. certShow: false,
  51. form: {},
  52. };
  53. },
  54. async created() {
  55. await this.searchOther();
  56. await this.search();
  57. },
  58. methods: {
  59. ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
  60. ...personal({ personalQuery: 'query' }),
  61. ...achieveApply({ applyQuery: 'query' }),
  62. async search({ skip = 0, limit = 10, ...info } = {}) {
  63. let res = await this.query({ skip, limit, ...info });
  64. if (this.$checkRes(res)) {
  65. this.$set(this, `list`, res.data);
  66. this.$set(this, `total`, res.total);
  67. }
  68. },
  69. // 下载资料
  70. toDownload({ data }) {
  71. window.open(data.file.url);
  72. },
  73. // 添加
  74. toAdd() {
  75. this.certShow = true;
  76. },
  77. // 修改
  78. async toEdit({ data }) {
  79. let res = await this.fetch(data.id);
  80. if (this.$checkRes(res)) {
  81. this.$set(this, `form`, res.data);
  82. this.certShow = true;
  83. }
  84. },
  85. // 删除
  86. async toDel({ data }) {
  87. let res = await this.delete(data.id);
  88. if (this.$checkRes(res)) if (this.$checkRes(res, '保存成功', '保存失败')) this.search();
  89. },
  90. // 提交
  91. async onSubmit({ data }) {
  92. let res;
  93. if (data.id) await this.update(data);
  94. else await this.create(data);
  95. if (this.$checkRes(res, '保存成功', '保存失败')) this.certClose();
  96. },
  97. // 关闭
  98. certClose() {
  99. this.form = {};
  100. this.certShow = false;
  101. this.search();
  102. },
  103. // 查询其他信息
  104. async searchOther() {
  105. let res = await this.applyQuery();
  106. if (this.$checkRes(res)) {
  107. this.$set(this, `applyList`, res.data);
  108. }
  109. // 用户
  110. res = await this.personalQuery({ code: this.user.code });
  111. if (this.$checkRes(res)) {
  112. this.$set(this, `userList`, res.data);
  113. }
  114. },
  115. },
  116. computed: {
  117. ...mapState(['user']),
  118. },
  119. metaInfo() {
  120. return { title: this.$route.meta.title };
  121. },
  122. watch: {
  123. test: {
  124. deep: true,
  125. immediate: true,
  126. handler(val) {},
  127. },
  128. },
  129. };
  130. </script>
  131. <style lang="less" scoped>
  132. .main {
  133. .one {
  134. text-align: right;
  135. }
  136. }
  137. </style>