index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <c-search :is_search="true" :fields="fields" @search="btSearch"> </c-search>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <c-button @toAdd="toAdd"></c-button>
  10. </el-col>
  11. <el-col :span="24" class="thr">
  12. <data-table :fields="fields" :opera="opera" @query="search" :data="list" :total="total" @edit="toEdit" @del="toDel"> </data-table>
  13. </el-col>
  14. </el-col>
  15. </el-row>
  16. </div>
  17. </template>
  18. <script>
  19. import { mapState, createNamespacedHelpers } from 'vuex';
  20. const { mapActions } = createNamespacedHelpers('cases');
  21. const { mapActions: dictdata } = createNamespacedHelpers('dictdata');
  22. export default {
  23. name: 'index',
  24. props: {},
  25. components: {},
  26. data: function () {
  27. return {
  28. // 查询
  29. searchInfo: {},
  30. fields: [
  31. { label: '序号', options: { type: 'index' } },
  32. { label: '名称', model: 'title', isSearch: true },
  33. { label: '来源', model: 'origin', isSearch: true },
  34. { label: '发布时间', model: 'create_time' },
  35. {
  36. label: '是否启用',
  37. model: 'is_use',
  38. format: (i) => {
  39. let data = this.isuseList.find((r) => r.value == i);
  40. if (data) return data.label;
  41. else return '暂无';
  42. },
  43. },
  44. ],
  45. opera: [
  46. { label: '修改', method: 'edit' },
  47. { label: '删除', method: 'del', confirm: true, type: 'danger' },
  48. ],
  49. list: [],
  50. total: 0,
  51. // 字典
  52. // 是否启用
  53. isuseList: [],
  54. };
  55. },
  56. async created() {
  57. await this.searchOther();
  58. await this.search();
  59. },
  60. methods: {
  61. ...mapActions(['query', 'delete']),
  62. ...dictdata({ dQuery: 'query' }),
  63. async search({ skip = 0, limit = this.limit, ...info } = {}) {
  64. let res = await this.query({ skip, limit, ...info, ...this.searchInfo });
  65. if (this.$checkRes(res)) {
  66. this.$set(this, `list`, res.data);
  67. this.$set(this, `total`, res.total);
  68. }
  69. },
  70. btSearch(query) {
  71. this.$set(this, `searchInfo`, query);
  72. this.search();
  73. },
  74. // 新增
  75. toAdd() {
  76. this.$router.push({ path: '/web/cases/add' });
  77. },
  78. // 修改
  79. toEdit({ data }) {
  80. this.$router.push({ path: '/web/cases/add', query: { id: data._id } });
  81. },
  82. async toDel({ data }) {
  83. let res = await this.delete(data._id);
  84. if (this.$checkRes(res, '删除信息成功', res.errmsg)) this.search();
  85. },
  86. // 字典表
  87. async searchOther() {
  88. let res;
  89. // 是否启用
  90. res = await this.dQuery({ type: 'is_use' });
  91. if (this.$checkRes(res)) {
  92. this.$set(this, `isuseList`, res.data);
  93. }
  94. },
  95. },
  96. computed: {
  97. ...mapState(['user']),
  98. },
  99. metaInfo() {
  100. return { title: this.$route.meta.title };
  101. },
  102. watch: {
  103. test: {
  104. deep: true,
  105. immediate: true,
  106. handler(val) {},
  107. },
  108. },
  109. };
  110. </script>
  111. <style lang="less" scoped></style>