quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
<template>
  <!--
        作者:wangxw
        时间:2019-05-05
        描述:分类模板
    -->
  <div class="d-s-s pb50">
    <!--分类不同样式展示-->
    <div class="model-container">
      <div class="img-box p10" :style="'backgroundColor:'+formData.backgroundColor+';'">
        <div class="d-a-c">
          <div v-for="(item,index) in formData.list" :key="index" class="d-c d-c-c" @mouseenter="mouseenter"
            @mouseleave="mouseleave" v-if="item.is_show">
            <div v-if="formData.type != 2">
              <img class="nav_img" :src="item.iconPath" alt="">
            </div>
            <div v-if="formData.type != 1" :style="'color:'+formData.textColor+' ;'">{{item.text}}</div>
          </div>
        </div>
      </div>
    </div>
    <!--图片展示参数-->
    <div class="param-container flex-1">
      <div class="common-form"><span>展示设置</span></div>
      <el-form size="small" :model="formData" label-width="100px">
        <div :key="index" v-for="(navBar, index) in formData.list">
          <el-form-item :label="navBar.text+':'">
            <div class="param-img-item">
              <div class="d-a-c">
                <div class="icon">未选中:
                  <img v-img-url="navBar.iconPath" alt="" @click="onEditorSelectImage(navBar, 'iconPath')">
                </div>
                <div class="icon"> 已选中:
                  <img v-img-url="navBar.selectedIconPath" alt="" @click="onEditorSelectImage(navBar, 'selectedIconPath')">
                </div>
              </div>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>
 
    <!--提交-->
    <div class="common-button-wrapper">
      <el-button size="small" type="primary" @click="Submit()">保存</el-button>
    </div>
    <!--上传图片-->
    <Upload v-if="isupload" :isupload="isupload" :config="{ total: 3 }" @returnImgs="returnImgsFunc"></Upload>
  </div>
</template>
 
<script>
  import PageApi from '@/api/page.js';
  import Upload from '@/components/file/Upload';
  export default {
    data() {
      return {
        /*是否上传图片*/
        isupload: false,
        /*表单数据对象*/
        formData: {
          /* 导航类型*/
          type: 0,
          /* 背景颜色*/
          backgroundColor: "",
          textColor: '',
          textHoverColor: '',
          /* 悬浮 */
          bulge: false,
          list: [
            // {
            // text:'',
            // iconPath:'',
            // is_show:true,
            // selectedIconPath:'',
            // link:{
            // wap_url:''
            // }
            // }
          ]
        },
        is_linkset: false,
        index: 0,
      };
    },
    components: {
      Upload
    },
    created() {
 
      this.getData();
 
    },
    methods: {
 
      /*获取数据*/
      getData() {
        let self = this;
        PageApi.getNav({}, true).then(res => {
          // let data = JSON.parse(res.data.data.data);
          // console.log(data)
          self.formData = res.data.data.data;
        }).catch(error => {
          self.loading = false;
        });
      },
 
      /*提交*/
      Submit() {
        let self = this;
        self.loading = true;
        let Params = self.formData;
        if (Params.list.length <= 0 || !Params.list) {
          Params = {}
        }
        PageApi.postNav({
            data: Params
          }, true)
          .then(data => {
            self.loading = false;
            self.$message({
              message: '恭喜你,修改成功',
              type: 'success'
            });
            self.getData();
          })
          .catch(error => {
            self.loading = false;
          });
      },
      /*选择链接*/
      changeLink(index) {
        this.is_linkset = true;
        this.index = index;
      },
 
      /*获取链接并关闭弹窗*/
      closeLinkset(e) {
        this.is_linkset = false;
        this.formData.list[this.index].link.wap_url = '/' + e.url;
        this.formData.list[this.index].text = e.name;
      },
      onEditorDeleleData: function(index) {
        let self = this;
        // if (self.formData.list.length <= 1) {
        //   self.$message({
        //     message: '至少保留一个',
        //     type: 'error'
        //   });
        //   return false;
        // }
        self.formData.list.splice(index, 1);
      },
      onEditorSelectImage: function(index, imgUrl) {
        this.isupload = true;
        this.imgModel = {
          index: index,
          imgUrl: imgUrl
        };
      },
      /*上传图片*/
      returnImgsFunc(e) {
        if (e != null) {
          this.imgModel.index[this.imgModel.imgUrl] = e[0]['file_path'];
        }
        this.isupload = false;
      },
      onEditorResetColor: function(holder, attribute, color) {
        holder[attribute] = color;
      },
      onEditorAddData: function() {
        let self = this;
        // 新增data数据
        if (self.formData.list) {
          if (self.formData.list.length >= 5) {
            self.$message({
              message: '最多添加5个',
              type: 'error'
            });
            return false;
          } else {
            let newDataItem = {
              iconPath: '',
              text: '',
              is_show: true,
              selectedIconPath: '',
              link: {
                wap_url: ''
              }
            };
            self.formData.list.push(newDataItem);
          }
        } else {
          let newDataItem = {
            iconPath: '',
            text: '',
            is_show: true,
            selectedIconPath: '',
            link: {
              wap_url: ''
            }
          };
          let list = [{ ...newDataItem
          }];
          self.formData = {
            type: 0,
            backgroundColor: "",
            textColor: '',
            textHoverColor: '',
            bulge: false,
            list: []
          }
          self.formData.list = list;
        }
 
      },
      mouseenter(e) {
        e.target.childNodes[2].style.color = this.formData.textHoverColor;
      },
      mouseleave(e) {
        e.target.childNodes[2].style.color = this.formData.textColor;
      }
    }
  };
</script>
 
<style scoped="scoped">
  .model-container {
    width: 300px;
    height: calc(100vh - 150px);
    margin-right: 30px;
  }
 
  .model-container img {
    width: 100%;
  }
 
  .model-container .img-box {
    box-shadow: 0 0 16px 0 rgba(0, 0, 0, .1);
  }
 
  .param-container {
    padding: 20px;
    /* height: calc(100vh - 150px); */
    border: 1px solid #cccccc;
  }
 
  .icon img {
    width: 50px;
    height: 50px;
  }
 
  .nav_img {
    width: 30px !important;
    height: 30px;
  }
 
  .delete-box {
    z-index: 99;
  }
 
  .param-img-item {
    border: 1px solid #CCCCCC;
    margin-bottom: 10px;
    padding: 30px 15px;
  }
</style>