swfw.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div id="swfw">
  3. <list-page v-bind="$attrs" :total="total" v-if="!id" @toSearch="search" :pageSize="pageSize">
  4. <component :is="model" :list="list"></component>
  5. </list-page>
  6. <template v-else>
  7. <dmodel :data="detail" v-if="detail">
  8. <el-button size="mini" type="primary" @click="$router.push({ path: './list', query: { index: $route.query.index } })"> 返回</el-button>
  9. </dmodel>
  10. </template>
  11. </div>
  12. </template>
  13. <script>
  14. const _ = require('lodash');
  15. import listPage from '@c/list/list-page.vue';
  16. import { mapState, createNamespacedHelpers } from 'vuex';
  17. const { mapActions: product } = createNamespacedHelpers('product');
  18. export default {
  19. name: 'swfw',
  20. props: ['listModel'],
  21. components: {
  22. listPage,
  23. model5: () => import('../list-model/model-5.vue'),
  24. dmodel: () => import('../detail-model/model-5.vue'),
  25. },
  26. data: function () {
  27. return {
  28. // 列表
  29. list: [],
  30. total: 0,
  31. pageSize: 7,
  32. // 详情
  33. detail: {},
  34. };
  35. },
  36. created() {
  37. this.search();
  38. },
  39. methods: {
  40. ...product(['query', 'fetch']),
  41. async search({ skip = 0, limit = this.pageSize, ...info } = {}) {
  42. let res = await this.query({ skip, limit, type: 2, ...info });
  43. if (this.$checkRes(res)) {
  44. this.$set(this, `list`, res.data);
  45. this.$set(this, `total`, res.total);
  46. }
  47. },
  48. // 查询详情
  49. async searchInfo() {
  50. let res = await this.fetch(this.id);
  51. if (this.$checkRes(res)) {
  52. this.$set(this, `detail`, res.data);
  53. }
  54. },
  55. },
  56. computed: {
  57. ...mapState(['user']),
  58. model() {
  59. const moduleNumber = this.listModel || 0;
  60. return `model${moduleNumber}`;
  61. },
  62. id() {
  63. return this.$route.query.id;
  64. },
  65. },
  66. metaInfo() {
  67. return { title: this.$route.meta.title };
  68. },
  69. watch: {
  70. id: {
  71. handler(ne) {
  72. if (ne) this.searchInfo();
  73. },
  74. immediate: true,
  75. },
  76. },
  77. };
  78. </script>
  79. <style lang="less" scoped></style>