index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="add">
  6. <el-button type="primary" size="mini" @click="add">添加</el-button>
  7. </el-col>
  8. <el-col :span="24" class="list">
  9. <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @set="toSet" @edit="toEdit" @delete="toDelete"></data-table>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </template>
  15. <script>
  16. import dataTable from '@common/src/components/frame/filter-page-table.vue';
  17. import { mapState, createNamespacedHelpers } from 'vuex';
  18. const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
  19. export default {
  20. metaInfo() {
  21. return { title: this.$route.meta.title };
  22. },
  23. name: 'index',
  24. props: {},
  25. components: {
  26. dataTable,
  27. },
  28. data: function() {
  29. return {
  30. opera: [
  31. {
  32. label: '设置问卷',
  33. method: 'set',
  34. },
  35. {
  36. label: '编辑',
  37. method: 'edit',
  38. },
  39. {
  40. label: '删除',
  41. method: 'delete',
  42. },
  43. ],
  44. fields: [
  45. { label: '名称', prop: 'title' },
  46. { label: '信息简介', prop: 'brief' },
  47. { label: '创建时间', prop: 'create_time' },
  48. ],
  49. list: [],
  50. total: 0,
  51. };
  52. },
  53. async created() {
  54. await this.search();
  55. },
  56. methods: {
  57. ...questionnaire(['query', 'fetch', 'create', 'update', 'delete']),
  58. // 查询列表
  59. async search({ skip = 0, limit = 10, ...info } = {}) {
  60. let res = await this.query({ skip, limit, ...info });
  61. if (this.$checkRes(res)) {
  62. this.$set(this, `list`, res.data);
  63. this.$set(this, `total`, res.total);
  64. }
  65. },
  66. // 设置问卷
  67. toSet({ data }) {
  68. this.$router.push({ path: '/question/setQuestion', query: { id: data.id } });
  69. },
  70. // 添加
  71. add() {
  72. this.$router.push({ path: '/question/detail' });
  73. },
  74. // 修改
  75. toEdit({ data }) {
  76. this.$router.push({ path: '/question/detail', query: { id: data.id } });
  77. },
  78. // 删除
  79. async toDelete({ data }) {
  80. let res = await this.delete(data.id);
  81. if (this.$checkRes(res)) {
  82. this.$message({
  83. message: '信息修改成功',
  84. type: 'success',
  85. });
  86. this.search();
  87. }
  88. },
  89. },
  90. computed: {
  91. ...mapState(['user']),
  92. },
  93. watch: {},
  94. };
  95. </script>
  96. <style lang="less" scoped>
  97. .main {
  98. .add {
  99. text-align: right;
  100. margin: 0 0 10px 0;
  101. }
  102. }
  103. </style>