zxl
2 小时以前 b1c9a5d056e85fe8b0ee6e92f10e6e2c5495b356
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<template>
  <div class="wrapper">
 
    <Card class="content">
      <Button type="primary" @click="handleAdd()">添加页面</Button>
      <div class="list">
        <Spin size="large" fix v-if="loading"></Spin>
        <div class="item item-title" >
          <div>页面名称</div>
          <div class="item-config">
            <div>状态</div>
            <div>操作</div>
          </div>
        </div>
 
        <div class="item" v-for="(item, index) in list" :key="index">
          <div>{{ item.name || "暂无模板昵称" }}</div>
          <div class="item-config">
            <i-switch v-model="item.pageShow" @on-change="changeSwitch(item)">
              <span slot="open">开</span>
              <span slot="close">关</span>
            </i-switch>
            <Button type="info" placement="right" @click="handleEdit(item)" size="small">修改</Button>
            <Poptip confirm title="删除此模板?" @on-ok="handleDel(item)" >
              <Button type="error" size="small">删除</Button>
            </Poptip>
          </div>
        </div>
        <div class="no-more" v-if="list.length ==0">暂无更多模板</div>
      </div>
      <Page :total="total" size="small" @on-change="(val) => {params.pageNumber = val; } " :current="params.pageNumber" :page-size="params.pageSize" show-sizer  :page-size-opts="[10, 20, 50]" @on-page-size-change="changePageSize"/>
 
    </Card>
 
  </div>
 
</template>
<script>
import * as API_Other from "@/api/other.js";
export default {
  // components: {region},
  data() {
    return {
      selectedIndex: 0, // 装修那个页面的下标
      columns: [ // 表头
        {
          title: "页面名称",
          key: "name",
        },
        {
          title: "状态",
        },
        {
          title: "操作",
          key: "action",
        },
      ],
 
      loading: false, // 加载状态
 
      params: { // 请求参数
        pageNumber: 1,
        pageSize: 10,
        sort: "createTime",
        order: "desc",
        pageType: "STORE",
        pageClientType: "H5",
      },
      total: 0, // 页面数量
      list: [], // 总数据
    };
  },
  watch: {
    params: {
      handler(val) {
        // this.pageNumber++;
        this.init();
      },
      deep: true,
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    // 切换tab
    clickType(val,index) {
      this.params.pageNumber = 1
      this.selectedIndex = index
      this.params.pageType = val;
    },
    // 是否发布
    changeSwitch(item) {
      this.loading = true;
      API_Other.releasePageHome(item.id).then((res) => {
        if (res.result) {
          this.loading = false;
          this.$Message.success("发布成功");
          this.init();
        }
 
        this.init();
 
        this.loading = false;
      });
    },
    // 初始化数据
    init() {
      this.loading = true;
      API_Other.getHomeList(this.params).then((res) => {
        if (!res.result) return false;
        this.loading = false;
        res.result.records.forEach((item) => {
          if (item.pageShow == "OPEN") {
            item.pageShow = true;
          } else {
            item.pageShow = false;
          }
        });
        this.list = res.result.records;
        this.total = res.result.total;
      });
    },
    // 装修楼层
    handleEdit(val) {
      this.$router.push({
        path: "/floorList/main",
        query: { id: val.id, name: val.name, type: val.pageShow },
      });
    },
    // 添加模板
    handleAdd() {
      this.$router.push({
        path: "/floorList/main",
      });
    },
     // 分页 改变页数
     changePageSize(v) {
      this.params.pageNumber = 1;
      this.params.pageSize = v;
      this.init();
    },
    // 删除模板
    handleDel(val) {
      this.loading = true;
      API_Other.removePageHome(val.id).then((res) => {
        if (res.result) {
          this.loading = false;
          this.init();
          this.$Message.success("删除成功");
        }
 
        this.loading = false;
      });
    },
  },
};
</script>
<style scoped lang="scss">
.category-item {
  cursor: pointer;
  padding: 4px;
}
.active {
  background: #ededed;
}
.item-title {
  background: #d7e7f5!important;
  height: 54px;
}
.no-more {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.wrapper {
  background: #fff;
  padding: 20px;
  display: flex;
}
.category {
  flex: 2;
}
.content {
  flex: 8;
}
* {
  margin: 5px;
}
.list {
  min-height: 600px;
  position: relative;
}
.item:nth-of-type(2) {
  margin: 0 5px;
}
.item {
  width: 100% !important;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  > .item-config {
    width: 180px;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
}
.item:nth-of-type(2n+1) {
  background: #f5f7fa;
}
</style>