doum
2025-12-10 559f6fcd685d2144e931d2c4e56cbe38c2308d70
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
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
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    v-loading="isUploading"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" label-width="130px" label-suffix=":" :rules="rules" inline>
      <el-form-item label="探店标题" prop="name">
        <el-input v-model="form.name" placeholder="请输入探店标题" v-trim/>
      </el-form-item>
      <el-form-item label="探店分类" prop="labelId">
        <el-select
          v-model="form.labelId"
          placeholder="请选择探店分类"
          filterable
          clearable
        >
          <el-option v-for="item in labels" :key="item.id" :value="item.id" :label="item.name" />
        </el-select>
        <!-- <el-input v-model="form.labelId" placeholder="请输入选择" v-trim/> -->
      </el-form-item>
      <el-form-item label="探店封面图" prop="imgurlfull">
        <UploadAvatarImage
          :file="{ 'imgurlfull': form.imgurlfull, 'imgurl': form.imgurl }"
          @uploadSuccess="uploadAvatarSuccess"
          @uploadEnd="isUploading=false"
          @uploadBegin="isUploading = true"
        />
      </el-form-item>
      <el-form-item label="关联店铺" prop="shopId">
        <el-select
          v-model="form.shopId"
          placeholder="请输入店铺名称,再选择"
          filterable
          remote
          reserve-keyword
          :remote-method="remoteMethod"
          :loading="searchLoading"
        >
          <el-option
            v-for="item in shops"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <!-- contentType 0图片 1视频 -->
      <el-form-item label="探店类型" prop="contentType">
        <el-select
          v-model="form.contentType"
          placeholder="请选择探店类型"
          @change="form.fileList=[]"
        >
          <el-option :key="0" value="0" label="图片" />
          <el-option :key="1" value="1" label="视频" />
        </el-select>
      </el-form-item>
      <el-form-item v-if="form.contentType==0" label="探店图片" prop="fileList">
        <UploadImage
          :fileList="form.fileList"
          @beginUpload="isUploading=true"
          @endUpload="isUploading=false"/>
      </el-form-item>
      <el-form-item  v-if="form.contentType==1" label="探店视频" prop="fileList">
        <div class="editPage__video">
          <div class="img__con">
            <el-upload
              class="video-uploader"
              :action="uploadVideoUrl"
              :data="uploadVideoData"
              :show-file-list="false"
              :on-success="handleVideoSuccess"
              :on-error="uploadError"
              :before-upload="beforeVideoUpload"
              :on-progress="uploadVideoProcess"
              accept=".mp4"
            >
              <video width="100%" height="100%" v-if="form.fileList.length" controls="controls" :key="menuKey">
                <source :src="form.fileList[0].fullFileurl" type="video/mp4" />
              </video>
              <i v-else v-show="videoFlag != true" class="el-icon-plus avatar-uploader-icon"></i>
              <el-progress
                v-if="videoFlag == true"
                type="line"
                :percentage="videoUploadPercent"
                style="margin-top: 30px"
              ></el-progress>
              <div v-if="form.videoUrlPath" class="delete">
                <i
                  class="el-icon-delete icon"
                  @click.stop="deleteDeviceConfigAddVideo"
                />
              </div>
            </el-upload>
            <p style="font-size: 14px;">
              说明: 视频格式为mp4格式,视频大小不超过2G
            </p>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="详情" prop="content">
        <RichEditor :content="{ content : form.content}"  @edit="form.content=$event" />
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import RichEditor from '@/components/common/RichEditor'
import UploadImage from '@/components/common/UploadImage'
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
import { fetchList as shopList } from '@/api/business/shop' 
 
export default {
  name: 'OperaActivityWindow',
  extends: BaseOpera,
  components: { GlobalWindow, RichEditor, UploadImage, UploadAvatarImage },
  data () {
    let fileListRlue = (rule, value, callback) => {
      if (!this.form.starttime) {
        callback()
      } else {
        callback()
      }
    }
    return {
      uploadVideoUrl: process.env.VUE_APP_API_PREFIX + '/public/upload',
      uploadVideoData: {
        busiName: 32,
        folder: 'upload',
        type: ''
      },
      
      isUploading: false,
      searchLoading: false,
      menuKey: 1,
      videoFlag: false, // 进度条相关的
      videoUploadPercent: 0, // 进度条相关的
      shops: [],
      // 表单数据
      form: {
        id: null,
        name: '',
        labelId: '',
        contentType: '0', //0图片 1视频
        imgurlfull: null,
        imgurl: null,
        shopId: '',
        content: '',
        fileList: [], // 探店图片
        type: 2 //探店
      },
      labels: [
        { name: 'a', id: 1 },
        { name: 'b', id: 2 },
        { name: 'c', id: 3 },
      ],
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入探店标题', tigger: 'blur' }
        ],
        labelId: [
          { required: true, message: '请选择探店分类', tigger: 'change' }
        ],
        imgurlfull: [
          { required: true, message: '请上传探店主图', tigger: 'change' }
        ],
        fileList: [
          { required: true, validator: fileListRlue, tigger: 'change' }
        ],
      }
    }
  },
  created () {
    this.config({
      api: '/business/activity',
      'field.id': 'id'
    })
  },
  methods: {
     // 上传图片
     uploadAvatarSuccess(file) {
      this.form.imgurl = file.imgurl;
      this.form.imgurlfull = file.imgurlfull;
    },
    
    remoteMethod(query) {
      if (query !== '') {
        this.searchLoading = true
        shopList({
          capacity: 999,
          model: {
            name: query
          }
        })
          .then(res => {
            this.shops = res.records
          })
          .finally(() => {
            this.searchLoading = false
          })
      }
    },
    // 视频上传
    // 上传前
    beforeVideoUpload (file) {
      // this.loadTips = '视频上传中...'
      this.uploading = true
      //   file.type === "image/jpg" ||
      //   file.type === "image/png";
      const isMp4 = file.type === 'video/mp4'
      // 限制文件最大不能超过 300M
      const isLt2M = file.size / 1024 / 1024 / 1024 < 2
 
      if (!isMp4) {
        this.$message.error('视频只能是mp4格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传视频大小不能超过2G')
      }
      return isMp4 && isLt2M
    },
    // 上传成功的函数
    handleVideoSuccess (res, file) {
      this.uploading = false
      // 进度条恢复到初始状态
      this.videoFlag = false
      this.videoUploadPercent = 0
      ++this.menuKey
      this.form.fileList = [
        {
          fileUrl: res.data.imgaddr,
          fullFileUrl: res.data.url
        }
      ]
    },
    // 删除已上传视频
    deleteDeviceConfigAddVideo () {
      this.form.fileList = []
    },
    // 进度条
    uploadVideoProcess (event, file, fileList) {
      this.videoFlag = true
      this.videoUploadPercent = parseInt(file.percentage)
    },
  },
}
</script>
 
<style lang="scss" scoped>
@import "@/assets/style/alertstyle.scss";
::v-deep .el-form-item__content {
  flex: 0.6;
}
$image-width: 100px;
.avatar-uploader {
  width: $image-width;
  height: $image-width;
}
.video-uploader {
  width: $image-width;
  height: $image-width;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  cursor: pointer;
  border: 1px dashed #ccc;
  border-radius: 8px;
  transition: all 0.3s;
  margin-right: 20px;
  &:hover {
    border-color: lightblue;
    .uploader-icon {
      color: lightblue;
    }
  }
  ::v-deep .el-upload {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    .file {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      background-size: contain;
      background-position: center;
      background-repeat: no-repeat;
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .delete {
      background-color: rgba(0, 0, 0, 0.5);
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      display: none;
      align-items: center;
      justify-content: center;
      .icon {
        color: #fff;
      }
    }
    &:hover {
      .delete {
        display: flex;
      }
    }
  }
}
::v-deep .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  width: $image-width;
  height: $image-width;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: $image-width;
  height: $image-width;
  line-height: $image-width;
  text-align: center;
}
.avatar {
  width: $image-width;
  height: $image-width;
  display: block;
}
</style>