counterEdit.vue 9.3 KB
Newer Older
xd's avatar
xd committed
1 2
<template>
  <div class="container">
leiqingsong's avatar
leiqingsong committed
3
    <div class="flex-start top">
xd's avatar
xd committed
4 5
      <div class="flex-start">
        <van-cell-group class="gn">
xd's avatar
xd committed
6
          <van-cell title="专柜LOGO" class="logo" >
xd's avatar
xd committed
7
            <template slot="default">
leiqingsong's avatar
leiqingsong committed
8 9 10 11 12 13 14 15
              <van-uploader
                v-model="logoList"
                :max-count="1"
                class="input"
                :after-read="afterRead"
                :before-read="beforeRead"
                @delete="deleteLogo"
              >
xd's avatar
xd committed
16 17
                <div>
                  <van-icon name="photo" size="20" />
xd's avatar
xd committed
18 19 20 21 22 23 24 25 26 27 28
                </div>
              </van-uploader>
            </template>
          </van-cell>
          <van-cell title="专柜名称">
            <template slot="default">
              <van-field v-model="addForm.name" placeholder="输入名称" class="input" />
            </template>
          </van-cell>
          <van-cell title="专柜地址">
            <template slot="default">
xd's avatar
xd committed
29
              <van-field v-model="addForm.location" placeholder="输入地址"  class="input" />
xd's avatar
xd committed
30 31
            </template>
          </van-cell>
xd's avatar
xd committed
32 33
          <van-cell title="电话">
            <template slot="default">
xd's avatar
xd committed
34
              <van-field v-model="addForm.phone" placeholder="输入电话" class="input" />
xd's avatar
xd committed
35 36
            </template>
          </van-cell>
xd's avatar
xd committed
37 38 39
          <div class="border">
            <div class="des">摘要信息</div>
            <van-field
xd's avatar
xd committed
40
              v-model="addForm.summaryTitle"
xd's avatar
xd committed
41 42 43 44 45 46 47 48 49 50
              rows="4"
              autosize
              type="textarea"
              placeholder="请输入摘要信息"
              show-word-limit
              maxlength="30"
            />
          </div>
        </van-cell-group>
      </div>
leiqingsong's avatar
leiqingsong committed
51
      <div class="flex-start fwb">
xd's avatar
xd committed
52
        <div class="txt">轮播图</div>
leiqingsong's avatar
leiqingsong committed
53 54 55 56 57 58 59
        <van-uploader
          v-model="bannerList"
          :max-count="4"
          class="pic"
          :before-read="beforeRead"
          :after-read="afterAddBanner"
          @delete="deleteBanner"
60
          multiple="true"
leiqingsong's avatar
leiqingsong committed
61 62 63 64 65 66 67
        />
        <quill-editor
          v-model="addForm.summary"
          ref="myQuillEditor"
          :options="editorOption"
          @change="onEditorChange($event)"
        ></quill-editor>
xd's avatar
xd committed
68 69 70
      </div>
    </div>

xd's avatar
xd committed
71
    <div class="creat" @click="handleSave">保存信息</div>
xd's avatar
xd committed
72 73 74 75
  </div>
</template>

<script>
leiqingsong's avatar
leiqingsong committed
76 77 78 79 80 81 82 83 84
import { quillEditor, Quill } from "vue-quill-editor";
import { container, ImageExtend, QuillWatch } from "quill-image-extend-module";
import { editStore, getStoreDetail } from "@/api/sidebar/voucher";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
Quill.register("modules/ImageExtend", ImageExtend);
import axios from "axios";
import { log } from "util";
xd's avatar
xd committed
85 86 87 88 89 90 91 92 93 94 95 96 97
const toolbarOptions = [
  [{ size: ["small", false, "large", "huge"] }], // 字体大小
  ["image"] // 图片
];

export default {
  components: {
    quillEditor
  },

  data() {
    return {
      addForm: {
xd's avatar
xd committed
98 99
        logo: '',
        summaryTitle: '',
xd's avatar
xd committed
100
        name: '',
xd's avatar
xd committed
101
        location: '',
xd's avatar
xd committed
102 103
        summary: '',
        phone: ''
xd's avatar
xd committed
104
      },
leiqingsong's avatar
leiqingsong committed
105
      oyStallCode: "",
xd's avatar
xd committed
106
      list: [],
xd's avatar
xd committed
107 108
      bannerList: [],
      title: "",
xd's avatar
xd committed
109
      logoList: [],
xd's avatar
xd committed
110 111 112 113 114 115 116 117
      // 富文本框参数设置
      editorOption: {
        modules: {
          ImageExtend: {
            name: "file", // 图片参数名
            // size: 3,
            action: "http://139.155.48.151:8084/admin/auth/util/saveImg",
            response: res => {
xd's avatar
xd committed
118 119
              console.log(res.data.imgPath,'富文本');
              
leiqingsong's avatar
leiqingsong committed
120
              return res.data.imgPath;
xd's avatar
xd committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
            },
            headers: xhr => {
              // xhr.setRequestHeader('Content-Type','multipart/form-data')
            } // 可选参数 设置请求头部
          },
          toolbar: {
            // 如果不上传图片到服务器,此处不必配置
            container: toolbarOptions, // container为工具栏,此次引入了全部工具栏,也可自行配置
            placeholder: "请输入正文",
            handlers: {
              image: function() {
                // 劫持原来的图片点击按钮事件
                QuillWatch.emit(this.quill.id);
              }
            }
          }
        }
      }
    };
  },
xd's avatar
xd committed
141
  mounted() {
leiqingsong's avatar
leiqingsong committed
142 143
    this.addForm.oyStallCode = sessionStorage.getItem("oyStallCode");
    console.log(this.addForm.oyStallCode, "编辑专柜信息oyStallCode");
xd's avatar
xd committed
144
    this.getDetail()
xd's avatar
xd committed
145
  },
xd's avatar
xd committed
146
  methods: {
xd's avatar
xd committed
147 148
    getDetail() {
      let params = {
xd's avatar
xd committed
149
        oyStallCode: this.addForm.oyStallCode     
xd's avatar
xd committed
150 151
      }
      getStoreDetail(params).then(res => {
leiqingsong's avatar
leiqingsong committed
152 153 154 155 156 157
        if (res.data.stallInfo != null) {
          console.log(res, "详情");
          this.list = res.data.carousel;
          let obj = {};
          obj.url = res.data.stallInfo.logo;
          this.logoList.push(obj);
xd's avatar
xd committed
158
          res.data.carousel.forEach(item => {
leiqingsong's avatar
leiqingsong committed
159 160 161 162 163
            let obj2 = {};
            obj2.url = item;
            this.bannerList.push(obj2);
          });
          this.addForm = res.data.stallInfo;
xd's avatar
xd committed
164
        }
leiqingsong's avatar
leiqingsong committed
165
      });
xd's avatar
xd committed
166
    },
xd's avatar
xd committed
167
    change(val) {
leiqingsong's avatar
leiqingsong committed
168
      console.log(val);
xd's avatar
xd committed
169 170
    },
    onEditorChange({ editor, html, text }) {
leiqingsong's avatar
leiqingsong committed
171
      this.$emit("input", this.addForm.summary);
xd's avatar
xd committed
172
    },
leiqingsong's avatar
leiqingsong committed
173
    beforeRead(file) {
174 175 176 177 178 179 180 181 182 183 184 185 186 187
      if(file.type) {
        if (file.type !== "image/jpeg" && file.type !== "image/png") {
          this.$toast("只允许上传jpg/png格式的图片!")
          return false;
        }
      }else {
        console.log(222);
        file.forEach( item => {
          if (item.type !== "image/jpeg" && item.type !== "image/png") {
           this.$toast("只允许上传jpg/png格式的图片!")
          }         
        })
        // console.log(file,'file');     
        // console.log(file.type,'file.type');
leiqingsong's avatar
leiqingsong committed
188
      }
189 190 191 192
     
      
      //上传之前校验
      
leiqingsong's avatar
leiqingsong committed
193
      return true;
xd's avatar
xd committed
194
    },
leiqingsong's avatar
leiqingsong committed
195
    async afterRead(file) {
xd's avatar
xd committed
196
      // this.addForm.logo = await this.getImgUrl(file.file)//使用上传的方法。file.file
leiqingsong's avatar
leiqingsong committed
197 198
      this.addForm.logo = await this.getImgUrl(file.file);
      console.log(this.addForm.logo, "this.addForm.logo");
xd's avatar
xd committed
199
    },
xd's avatar
xd committed
200
    async getImgUrl(file) {
201 202 203 204 205 206
      
      
      let params = new FormData()
      params.append("file", file)
      let url = "http://139.155.48.151:8084/admin/auth/util/saveImg"
      const img = await axios.post(url, params)
leiqingsong's avatar
leiqingsong committed
207 208 209
      let urls = img.data.data.imgPath;
      console.log(urls, "urls");
      return urls;
xd's avatar
xd committed
210 211
    },
    async afterAddBanner(file) {
212 213 214 215 216 217 218 219 220 221
      if(file.file) {
        let img = await this.getImgUrl(file.file);
        this.list.push(img);
      }else {
        file.forEach(async item => {
          let imgs = await this.getImgUrl(item.file)
          this.list.push(imgs);
          console.log(this.list,'list1')
        })      
      }
xd's avatar
xd committed
222
    },
leiqingsong's avatar
leiqingsong committed
223 224
    deleteBanner(file, index) {
      this.list.splice(index.index, 1);
xd's avatar
xd committed
225
    },
leiqingsong's avatar
leiqingsong committed
226 227
    deleteLogo(file) {
      this.addForm.logo = "";
xd's avatar
xd committed
228
    },
xd's avatar
xd committed
229
    handleSave() {
xd's avatar
xd committed
230
      const carousel = this.list.join(';')  
xd's avatar
xd committed
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
      // this.addForm.oyStallCode = 1
      delete this.addForm.id  
       if(!this.addForm.logo){
          this.$toast("请上传logo")
          return false
        }
        if(!this.addForm.name){
          this.$toast("请输入专柜名称")
          return false
        }   
        if(!this.addForm.location){
          this.$toast("请输入专柜地址")
          return false
        }    
        if(!this.addForm.phone){
          this.$toast("请输入电话号码")
          return false
        } 
        if(!this.addForm.summaryTitle){
          this.$toast("请输入摘要信息")
          return false
        } 
        if(!this.addForm.summary){
          this.$toast("请输入正文")
          return false
        } 
257 258 259 260 261 262 263
        console.log(Object.assign(this.addForm,{ carousel }),'11');
        
       editStore(Object.assign(this.addForm,{ carousel })).then( res => {
         if(res.result == 'success') {
           this.$router.go(-1)
         }    
       })     
xd's avatar
xd committed
264 265
    }
  }
leiqingsong's avatar
leiqingsong committed
266
};
xd's avatar
xd committed
267 268 269 270
</script>
<style >
</style>
<style scoped>
xd's avatar
xd committed
271 272 273
.logo >>> .van-cell__value {
  padding: 10px 0 0 0;
}
xd's avatar
xd committed
274 275 276 277 278 279 280 281
.pic {
  border-bottom: 2px solid #ebedf0;
}
.pic >>> .van-uploader__wrapper {
  justify-content: center;
}
.txt {
  font-size: 18px;
leiqingsong's avatar
leiqingsong committed
282
  color: rgba(45, 71, 106, 1);
xd's avatar
xd committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
  font-weight: bold;
  margin: 6px 16px 4px;
}
.top {
  background: #f8f8f8;
}
.fwb {
  margin-top: 10px;
}
.container {
  min-height: 100%;
  height: auto;
  background: #f8f8f8;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  align-items: center;
}
.content {
  background: #fff;
  height: auto;
}
.creat {
  margin: 20px 0;
  width: 343px;
  height: 40px;
  line-height: 40px;
  background: rgba(117, 178, 253, 1);
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  color: rgba(255, 255, 255, 1);
  text-align: center;
  bottom: 0;
}

.des {
  font-size: 14px;
  font-weight: bold;
  color: rgba(45, 71, 106, 1);
  margin-bottom: 12px;
}
.detail {
  background-color: #fff;
  padding: 12px 16px 0 16px;
}
.border {
  padding: 15px;
}
.border >>> .van-field__control {
  text-align: left !important;
  background-color: #f8f8f8;
}
.border >>> .van-cell {
  padding: 0;
}
.van-cell__value,
.van-cell__value--alone {
  text-align: right;
}
.input {
  padding: 0;
}
.gn >>> .van-field__control {
  text-align: right;
}
.gn >>> .van-cell__title {
  font-size: 14px;
  font-weight: bold;
  color: rgba(45, 71, 106, 1);
}
.gn {
  width: 100%;
  padding-bottom: 12px;
}
.input >>> .van-uploader__input-wrapper {
  width: 100%;
}
</style>