zxl
2025-05-23 5d5b0f7ab0f34019e11901ddcd59cd8b51ea9ff9
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<template>
  <!-- 预览保存 -->
  <div class="model-title">
    <div>店铺装修</div>
    <div class="btns">
      <Button
        @click="clickBtn(item)"
        size="small"
        v-for="(item, index) in way"
        :key="index"
        :type="item.selected ? 'primary' : ''"
      >{{ item.title }}</Button>
    </div>
    <div class="model-title-view-btn">
      <!-- TODO 后期会补全 目前版本暂无 -->
      <!-- <Poptip placement="bottom" width="100">
        <Button size="default" @click="creatQrCode">预览模板</Button>
        <div slot="content" class="default-view-content">
          <div>临时预览</div>
          <div ref="qrCodeUrl"></div>
        </div>
      </Poptip>-->
      <Button size="default" type="default" v-if="hasCache" @click="clearCache">清空本地缓存</Button>
      <Button size="default" type="primary" @click="handleSpinShow">保存模板</Button>
 
      <Modal
        title="保存中"
        v-model="saveDialog"
        :closable="true"
        :mask-closable="false"
        :footer-hide="true"
      >
        <div v-if="progress">
          <div class="model-item">
            模板名称
            <Input style="width: 200px" v-model="submitWay.name"/>
          </div>
          <div class="model-item">
            是否立即发布
            <i-switch v-model="submitWay.pageShow">
              <span slot="open">开</span>
              <span slot="close">关</span>
            </i-switch>
          </div>
          <div class="model-item">
            将当前装修内容写入到本地缓存中,下次进入页面时可继续使用
            <Button type="small" @click="witeLocalStore">写入</Button>
          </div>
 
          <Button type="primary" @click="save()">保存</Button>
        </div>
        <Progress v-else :percent="num" status="active"/>
      </Modal>
    </div>
  </div>
</template>
<script>
import * as API_Other from "@/api/other.js";
 
export default {
  props: ["pagetype"],
  data() {
    return {
      hasCache:false, // 是否有缓存
      progress: true, // 展示进度
      num: 20, // 提交进度
      saveDialog: false, // 加载状态
      way: [
        // 装修tab栏切换
        {
          title: "首页",
          name: "index",
          selected: true,
        },
        {
          title: "全屏广告",
          name: "advertising",
          selected: false,
        },
        {
          title: "弹窗广告",
          name: "ALERT",
          selected: false,
        },
      ],
 
      submitWay: {
        // 表单信息
        pageShow: this.$route.query.type || false,
        name: this.$route.query.name || "模板名称",
        pageClientType: "H5"
      }
    };
  },
  watch: {
    pagetype: {
      handler(val) {
        this.way.length = 0;
        if (val == "INDEX") {
          this.way.push({ title: "首页", name: "index", selected: true });
        } else if (val == "SPECIAL") {
          this.way.push({ title: "专题", name: "special", selected: true });
        } else if (val == "ALERT") {
          this.way.push({ title: "开屏广告", name: "alert", selected: true });
        }else if (val == "OPEN_SCREEN_ANIMATION") {
          this.way.push({ title: "app开屏页面", name: "OPEN_SCREEN_ANIMATION", selected: true });
        }
      },
      immediate: true,
    },
  },
  mounted() {
    this.hasCache = this.getStore('managerMobilePageCache') ? true : false;
  },
  methods: {
    clearCache(){
      this.setStore('managerMobilePageCache','');
      this.$Message.success('清空成功')
    },
    // 将楼层装修的内容写入到本地缓存中
    witeLocalStore(){
      this.setStore('managerMobilePageCache', this.$store.state.styleStore)
      this.$Message.success('写入成功')
    },
 
    clickBtn(val) {
      this.way.forEach((item, index) => {
        item.selected = false;
      });
      val.selected = true;
      this.$emit("selected", val.name);
    },
 
    /**
     * 加载,并保存模板
     */
    handleSpinShow() {
      this.saveDialog = true;
    },
 
    // 填写是否发布,模板名称之后保存
    save() {
       if (
        this.$store.state.styleStore == void 0 &&
        (this.$route.query.pagetype && this.$route.query.pagetype != 'ALERT' &&  this.$route.query.pagetype != 'OPEN_SCREEN_ANIMATION')
      ) {
        this.$Message.error("请装修楼层");
        return false;
      }
 
      this.submitWay?.pageShow === true
        ? (this.submitWay.pageShow = "OPEN")
        : (this.submitWay.pageShow = "CLOSE");
 
      this.submitWay.pageData = JSON.stringify(this.$store.state.styleStore);
      this.submitWay.pageType = "INDEX";
      this.submitWay.pageType =  this.$route.query.pagetype ||  "INDEX";
      // this.submitWay.pageType = this.pagetype;
 
      if (this.$route.query.pagetype == 'ALERT' || this.$route.query.pagetype == 'OPEN_SCREEN_ANIMATION') {
        this.update(this.submitWay);
      } else {
        this.$route.query.id ? this.updateHome() : this.submit(this.submitWay);
      }
 
      // this.$route.query.id ? this.update() : this.submit(this.submitWay);
    },
 
    // 更新
    updateHome() {
      this.progress = false;
      API_Other.updateHome(this.$route.query.id, {
        pageData: JSON.stringify(this.$store.state.styleStore),
        name: this.submitWay.name,
        pageShow: this.submitWay.pageShow,
        pageType: this.submitWay.pageType,
        pageClientType: "H5",
      })
        .then(res => {
          this.num = 50;
          if (res.success) {
            this.num = 80;
            /**制作保存成功动画¸ */
            setTimeout(() => {
              this.saveDialog = false;
              this.$Message.success("修改成功");
              this.goBack();
            }, 1000);
          } else {
            this.saveDialog = false;
            this.$Message.error("修改失败,请稍后重试");
          }
          console.log(res);
        })
        .catch(error => {});
    },
 
 
    // 更新
    update(submitWay) {
      console.log(this.$store.state.openStyleStore[0], "123123123");
      if (this.$store.state.openStyleStore == void 0) {
        this.$Message.error("请装修楼层!");
        return false;
      }
      this.progress = false;
 
      let id = this.$route.query.id;
      const pagetype = this.$route.query.pagetype;
      console.log(this.$store.state.openStyleStore, submitWay);
      const pageType = {
        INDEX: "INDEX",
        ALERT: "OPEN_SCREEN_PAGE",
        OPEN_SCREEN_ANIMATION: "OPEN_SCREEN_ANIMATION",
      }[pagetype ? pagetype : "INDEX"];
 
      if (pagetype) {
        submitWay.pageData = JSON.stringify(
          this.$store.state.openStyleStore[0]
        );
        submitWay.pageType = pageType;
        id = this.$store.state.openStoreId;
      }
 
      API_Other.updateHome(id, submitWay)
        .then((res) => {
          this.num = 50;
          if (res.success) {
            this.num = 80;
            /**制作保存成功动画¸ */
            setTimeout(() => {
              this.saveDialog = false;
              this.$Message.success("修改成功");
              this.goBack();
            }, 1000);
          } else {
            this.saveDialog = false;
            this.$Message.error("修改失败,请稍后重试");
          }
          console.log(res);
        })
        .catch((error) => {});
    },
 
 
 
    // 返回查询数据页面
    goBack() {
      this.$router.go(-1);
    },
 
    // 保存
    submit(submitWay) {
      this.progress = false;
      API_Other.setHomeSetup(submitWay)
        .then(res => {
          this.num = 50;
          if (res.success) {
            this.num = 80;
            /**制作保存成功动画¸ */
            setTimeout(() => {
              this.saveDialog = false;
              this.$Message.success("保存成功");
              this.goBack();
            }, 1000);
          } else {
            this.progress = true;
            this.saveDialog = false;
            this.$Message.error("保存失败,请稍后重试");
          }
          console.log(res);
        })
        .catch(error => {});
    }
  }
};
</script>
<style scoped lang="scss">
.model-item {
  width: 100%;
  padding: 10px 0;
  display: flex;
  align-items: center;
  > * {
    margin: 0 8px;
  }
}
.model-title {
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #333;
  font-size: 14px;
  > .model-title-view-btn {
    > * {
      margin: 0 10px;
    }
  }
}
.btns {
  * {
    margin: 0 4px;
  }
}
</style>