commitTab.vue 13.7 KB
Newer Older
乐宝呗666's avatar
乐宝呗666 committed
1 2
<template>
  <div class="commit-page-content">
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    <van-form @submit="onSubmit">
      <div class="field-title">
        <span>基本信息</span>
      </div>
      <div class="input-box">
        <van-field
          class="field-form-item"
          readonly
          clickable
          name="boardName"
          input-align="right"
          :value="form.boardName"
          label="展板名称"
          placeholder="请选择展板"
          :right-icon="showBoard ? 'arrow-up' : 'arrow-down'"
          @click="showBoard = true"
          :rules="[{ required: true }]"
乐宝呗666's avatar
乐宝呗666 committed
20
        />
21 22 23 24 25 26 27 28 29 30 31 32 33 34
        <van-popup v-model="showBoard" position="bottom">
          <van-picker
            show-toolbar
            :columns="boardNameList"
            @confirm="onConfirmBoard"
            @cancel="showBoard = false"
          />
        </van-popup>
        <van-field
          label="账户名"
          v-model="form.username"
          placeholder="请输入账户名称"
          readonly
          input-align="right"
乐宝呗666's avatar
乐宝呗666 committed
35
        />
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        <van-cell
          class="calendar-icon"
          title="学习时间"
          :value="form.studyTime || ''"
          @click="onDisplay"
          :icon="form.studyTime || cellIcon"
        />
        <van-popup v-model="show" position="bottom">
          <van-datetime-picker
            v-model="currentDate"
            type="datetime"
            title="选择学习时间"
            :formatter="formatter"
            @confirm="onConfirm"
            @cancel="onClose"
          />
        </van-popup>
        <van-field
          label="观影人数"
          v-model="form.num"
          placeholder="请输入观影人数"
          input-align="right"
乐宝呗666's avatar
乐宝呗666 committed
58
          :rules="[{ pattern: /^[1-9]\d*$/, message: '请输入正确内容' }]"
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        />
        <van-field
          label="管理员账号"
          v-model="form.name"
          placeholder="请输入管理员账号"
          input-align="right"
          :rules="[{ required: true }]"
        />
        <van-field
          type="password"
          label="管理员密码"
          v-model="form.password"
          placeholder="请输入管理员密码"
          input-align="right"
          :rules="[{ required: true }]"
        />
      </div>
      <div class="field-title">
        <span>上传视频</span>
乐宝呗666's avatar
乐宝呗666 committed
78
      </div>
79 80 81 82 83 84 85
      <div class="field-content">
        <div class="upload-content">
          <div class="uplaod-video" style="min-height: 60px">
            <van-uploader
              :max-count="3"
              v-model="fileList"
              accept="video/*"
乐宝呗666's avatar
乐宝呗666 committed
86
              :before-read="beforeVideo"
87 88 89 90 91 92 93 94 95 96
              :after-read="uploadVideo"
              :before-delete="deleteVideo"
              multiple
            >
              <div class="avatar-plus">
                <span>+</span>
              </div>
            </van-uploader>
          </div>
          <div class="tips">
97
            <img src="@/assets/images/applets/tip.png" alt />
98 99
            <span>
              最多支持上传
乐宝呗666's avatar
乐宝呗666 committed
100
              <b>3</b> 段视频,每段时长 <b>30s</b>
101 102
            </span>
          </div>
乐宝呗666's avatar
乐宝呗666 committed
103
        </div>
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
      </div>
      <div class="field-title">
        <span>上传照片</span>
      </div>
      <div class="field-content">
        <div class="upload-content">
          <div class="uplaod-video" style="min-height: 60px">
            <van-uploader
              :max-count="6"
              accept="image/png, image/jpeg"
              v-model="imgFileList"
              multiple
              :after-read="uploadImg"
              :before-delete="deleteImg"
            >
              <div class="avatar-plus">
                <span>+</span>
              </div>
            </van-uploader>
          </div>
          <div class="tips">
125
            <img src="@/assets/images/applets/tip.png" alt />
126 127 128 129 130
            <span>
              最多支持上传
              <b>6</b> 张照片
            </span>
          </div>
乐宝呗666's avatar
乐宝呗666 committed
131 132
        </div>
      </div>
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
      <div class="field-title">
        <span>有话对党说</span>
      </div>
      <div class="field-content">
        <van-field
          class="field-textarea"
          type="textarea"
          v-model="form.content"
          maxlength="500"
          show-word-limit
        />
      </div>
      <div class="commit-page-button">
        <van-button type="default" native-type="submit">提交</van-button>
      </div>
    </van-form>
乐宝呗666's avatar
乐宝呗666 committed
149 150 151 152 153 154 155
  </div>
</template>

<script>
export default {
  data() {
    return {
乐宝呗666's avatar
乐宝呗666 committed
156
      form: {
乐宝呗666's avatar
乐宝呗666 committed
157 158
        username: JSON.parse(sessionStorage.getItem("userInfo")).orgName,
        organId: JSON.parse(sessionStorage.getItem("userInfo")).orgId,
159 160
        images: [], // 文件地址
        videos: [], // 文件地址
乐宝呗666's avatar
乐宝呗666 committed
161 162 163 164 165
      },
      currentDate: new Date(),
      boardList: [],
      boardNameList: [],
      showBoard: false,
166
      cellIcon: require("@/assets/images/applets/date.png"),
乐宝呗666's avatar
乐宝呗666 committed
167
      show: false,
168 169 170 171
      fileList: [], // 预览
      imgFileList: [],// 预览
      videoIds:[], // 文件ID
      imageIds:[] // 文件ID
乐宝呗666's avatar
乐宝呗666 committed
172 173
    };
  },
乐宝呗666's avatar
乐宝呗666 committed
174 175 176
  mounted() {
    this.getBoardList();
  },
乐宝呗666's avatar
乐宝呗666 committed
177
  methods: {
乐宝呗666's avatar
乐宝呗666 committed
178 179 180 181 182
    // 获取所属单位
    getBoardList() {
      let vm = this;
      vm.$https({
        url: "exhibitionBoard/getList",
乐宝呗666's avatar
乐宝呗666 committed
183
        method: "post",
乐宝呗666's avatar
乐宝呗666 committed
184 185 186 187 188 189 190 191 192 193 194 195
        authType: this.backToken,
      })
        .then((res) => {
          if (res.data.resultCode === "200") {
            vm.boardList = res.data.data;
            vm.boardNameList = res.data.data.map((item) => item.name);
          }
        })
        .catch(function (err) {
          console.log(err);
        });
    },
乐宝呗666's avatar
乐宝呗666 committed
196
    // 下拉框确认按钮
乐宝呗666's avatar
乐宝呗666 committed
197 198 199 200 201
    onConfirmBoard(value, index) {
      this.form.boardName = value;
      this.form.boardId = this.boardList[index].id;
      this.showBoard = false;
    },
乐宝呗666's avatar
乐宝呗666 committed
202 203
    beforeVideo(file) {
      this.timeOutVideo = false
204 205 206 207 208 209 210 211 212 213
      if(Array.isArray(file)){
        file.forEach(item=>{
          this.createVideo(item)
        })
      }else{
        this.createVideo(file)
      }
      return true
    },
    createVideo(file){
乐宝呗666's avatar
乐宝呗666 committed
214 215 216 217 218
      let _URL = window.URL || window.webkitURL;
      let videoUrl = _URL.createObjectURL(file);
      let audioElement = new Audio(videoUrl);
      audioElement.addEventListener("loadedmetadata", () => {
        let duration = audioElement.duration; //时长为秒,小数,182.36
219
        console.log(duration)
乐宝呗666's avatar
乐宝呗666 committed
220
        if (duration > 31) {
乐宝呗666's avatar
乐宝呗666 committed
221
          this.timeOutVideo = true
222
          this.fileList = []
乐宝呗666's avatar
乐宝呗666 committed
223
          this.$toast.fail("上传视频时长不能超过30秒");
乐宝呗666's avatar
乐宝呗666 committed
224 225 226
          return false;
        }
      }); 
乐宝呗666's avatar
乐宝呗666 committed
227 228 229 230 231 232 233 234 235 236 237 238
    },
    // 打开日历
    onDisplay() {
      this.show = true;
    },
    // 关闭日历
    onClose() {
      this.show = false;
    },
    // 确认日历
    onConfirm(event) {
      this.show = false;
乐宝呗666's avatar
乐宝呗666 committed
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
      this.form.studyTime = this.timeStamp2String(event);
    },
    // 格式转化
    timeStamp2String(time) {
      var datetime = new Date();
      datetime.setTime(time);
      var year = datetime.getFullYear();
      var month =
        datetime.getMonth() + 1 < 10
          ? "0" + (datetime.getMonth() + 1)
          : datetime.getMonth() + 1;
      var date =
        datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
      var hour =
        datetime.getHours() < 10
          ? "0" + datetime.getHours()
          : datetime.getHours();
      var minute =
        datetime.getMinutes() < 10
          ? "0" + datetime.getMinutes()
          : datetime.getMinutes();
      var second =
        datetime.getSeconds() < 10
          ? "0" + datetime.getSeconds()
          : datetime.getSeconds();
      return (
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
乐宝呗666's avatar
乐宝呗666 committed
277
    },
乐宝呗666's avatar
乐宝呗666 committed
278 279 280 281 282 283 284 285 286 287 288 289
    formatter(type, value) {
      if (type === "year") {
        return `${value}年`;
      } else if (type === "month") {
        return `${value}月`;
      } else if (type === "day") {
        return `${value}日`;
      } else if (type === "hour") {
        return `${value}时`;
      }
      return `${value}分`;
    },
290
    // 删除图片
291
    async deleteImg(file,detail){
292
      this.form.images.splice(detail.index,1)
293 294 295
      const id = this.imageIds[detail.index]
      this.imageIds.splice(detail.index,1)
      await this.deleteInterface(id)
296
    },
297
    // 上传图片
乐宝呗666's avatar
乐宝呗666 committed
298
    uploadImg(file) {
299
      let param = new FormData();
300 301
      if(Array.isArray(file)){
        file.forEach(item=>{
302
          param.append("file", item.file)
303 304
        })
      }else{
305
        param.append("file", file.file)
306
      }
307
      this.uploadImgInterface(param)
308
    },
309 310
    // 上传图片接口
    uploadImgInterface(param){
乐宝呗666's avatar
乐宝呗666 committed
311 312 313
      let vm = this;
      vm.$https(
        {
314
          url: "file/datum/upload",
乐宝呗666's avatar
乐宝呗666 committed
315 316 317 318 319 320
          method: "post",
          authType: this.backToken,
        },
        param
      )
        .then((res) => {
乐宝呗666's avatar
乐宝呗666 committed
321
          if(res.data.resultCode==='200'){
322 323 324 325
            res.data.data.fileList.forEach(item=>{
              this.form.images.push(item.fileUrl);
              this.imageIds.push(item.id);
            })
乐宝呗666's avatar
乐宝呗666 committed
326 327 328
          }else{
            this.$toast(res.data.message)
          }
乐宝呗666's avatar
乐宝呗666 committed
329 330 331 332 333
        })
        .catch(function (err) {
          console.log(err);
        });
    },
334
    // 删除视频
335
    async deleteVideo(file,detail){
336
      this.form.videos.splice(detail.index,1)
337 338 339
      const id = this.videoIds[detail.index]
      this.videoIds.splice(detail.index,1)
      await this.deleteInterface(id)
340
    },
乐宝呗666's avatar
乐宝呗666 committed
341
    // 上传视频
乐宝呗666's avatar
乐宝呗666 committed
342
    uploadVideo(file) {
343
      let param = new FormData();
344 345
      if(Array.isArray(file)){
        file.forEach(item=>{
346
          param.append("file", item.file)
347 348
        })
      }else{
349
        param.append("file", file.file)
350
      }
351
      this.uploadVideoInterface(param)
352
    },
353 354
    // 上传视频接口
    uploadVideoInterface(param){
乐宝呗666's avatar
乐宝呗666 committed
355 356 357 358 359 360 361 362 363 364
      let vm = this;
      vm.$https(
        {
          url: "file/video/upload",
          method: "post",
          authType: this.backToken,
        },
        param
      )
        .then((res) => {
乐宝呗666's avatar
乐宝呗666 committed
365
          if(res.data.resultCode==='200'){
乐宝呗666's avatar
乐宝呗666 committed
366 367 368 369 370 371 372
            if(!this.timeOutVideo){
              res.data.data.fileList.forEach(item=>{
                this.form.videos.push(item.fileUrl);
                this.videoIds.push(item.id);
              })
            }
            
乐宝呗666's avatar
乐宝呗666 committed
373 374 375 376
          }else{
            this.$toast(res.data.message)
          }
          
乐宝呗666's avatar
乐宝呗666 committed
377 378 379 380
        })
        .catch(function (err) {
          console.log(err);
        });
乐宝呗666's avatar
乐宝呗666 committed
381
    },
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
    // 删除接口
    deleteInterface(id){
        this.$https(
        {
          url: "file/delete/"+id,
          method: "delete",
          authType: this.backToken,
        })
        .then((res) => {
          if(res.data.resultCode==='200'){
            return true
          }else{
            this.$toast(res.data.message)
            return false
          }
        })
        .catch(function (err) {
          console.log(err);
        });
    },
402
    
乐宝呗666's avatar
乐宝呗666 committed
403 404
    // 提交数据
    onSubmit() {
乐宝呗666's avatar
乐宝呗666 committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
      let vm = this;
      let param = {};
      for (let key in this.form) {
        if (this.form[key]) {
          param[key] = this.form[key];
        }
      }
      param.images = [...param.images, ...param.videos];
      param.images = param.images.join(",");
      delete param.videos;
      console.log(param);
      vm.$https(
        {
          url: "interaction/add",
          method: "post",
          authType: this.backToken,
        },
        vm.$qs.stringify(param)
      )
        .then((res) => {
          if (res.data.resultCode === "200") {
乐宝呗666's avatar
乐宝呗666 committed
426
            this.$router.replace({path:"/success",query:{txt:'提交成功',url:'/commit'}})
乐宝呗666's avatar
乐宝呗666 committed
427
          } else {
乐宝呗666's avatar
乐宝呗666 committed
428
            this.$toast(res.data.message)
乐宝呗666's avatar
乐宝呗666 committed
429 430 431
          }
        })
        .catch(function (err) {
乐宝呗666's avatar
乐宝呗666 committed
432
          console.log(err)
乐宝呗666's avatar
乐宝呗666 committed
433 434 435
        });
    },
  },
乐宝呗666's avatar
乐宝呗666 committed
436 437 438 439 440
};
</script>

<style lang="scss" scoped>
.commit-page-content {
乐宝呗666's avatar
乐宝呗666 committed
441
  padding: 24px 20px;
乐宝呗666's avatar
乐宝呗666 committed
442 443 444
  height: calc(100% - 200px);
  overflow-y: auto;
  .field-title {
乐宝呗666's avatar
乐宝呗666 committed
445 446 447
    position: relative;
    padding-bottom: 20px;
    span {
乐宝呗666's avatar
乐宝呗666 committed
448 449 450 451
      color: #333;
      font-size: 16px;
      line-height: 20px;
      &:before {
乐宝呗666's avatar
乐宝呗666 committed
452 453 454 455 456 457 458
        content: "";
        height: 16px;
        width: 4px;
        border-radius: 1px;
        display: inline-block;
        background: #a4151d;
        position: absolute;
乐宝呗666's avatar
乐宝呗666 committed
459
        left: -20px;
乐宝呗666's avatar
乐宝呗666 committed
460
        top: 2px;
乐宝呗666's avatar
乐宝呗666 committed
461
      }
乐宝呗666's avatar
乐宝呗666 committed
462
    }
乐宝呗666's avatar
乐宝呗666 committed
463 464
  }
  .field-content {
乐宝呗666's avatar
乐宝呗666 committed
465
    padding-bottom: 32px;
乐宝呗666's avatar
乐宝呗666 committed
466 467
  }
  .input-box {
乐宝呗666's avatar
乐宝呗666 committed
468 469
    padding-bottom: 32px;
    .van-cell {
乐宝呗666's avatar
乐宝呗666 committed
470 471 472 473
      line-height: 40px;
      padding-left: 0;
      padding-right: 0;
      border-bottom: 1px solid #eee;
乐宝呗666's avatar
乐宝呗666 committed
474 475
    }
    .van-cell:after {
乐宝呗666's avatar
乐宝呗666 committed
476
      display: none;
乐宝呗666's avatar
乐宝呗666 committed
477
    }
乐宝呗666's avatar
乐宝呗666 committed
478 479
  }
  .calendar-icon {
乐宝呗666's avatar
乐宝呗666 committed
480
    .van-icon {
乐宝呗666's avatar
乐宝呗666 committed
481 482 483 484 485 486
      position: absolute;
      width: 20px;
      height: 20px;
      right: 0;
      bottom: 22px;
      z-index: 2;
乐宝呗666's avatar
乐宝呗666 committed
487
    }
乐宝呗666's avatar
乐宝呗666 committed
488 489
  }
  .commit-page-button {
乐宝呗666's avatar
乐宝呗666 committed
490 491 492 493
    position: fixed;
    bottom: 50px;
    left: 0;
    right: 0;
乐宝呗666's avatar
乐宝呗666 committed
494
    padding: 0 40px;
乐宝呗666's avatar
乐宝呗666 committed
495
    background-color: #fff;
乐宝呗666's avatar
乐宝呗666 committed
496
    box-sizing: border-box;
乐宝呗666's avatar
乐宝呗666 committed
497 498
    padding-top: 10px;
    padding-bottom: 10px;
乐宝呗666's avatar
乐宝呗666 committed
499 500
    width: 100%;
    .van-button--normal {
乐宝呗666's avatar
乐宝呗666 committed
501 502 503 504 505 506 507
      background: #a4151d;
      border-radius: 4px;
      height: 40px;
      width: 100%;
      color: #fff;
      border: none;
      font-size: 16px;
乐宝呗666's avatar
乐宝呗666 committed
508
    }
乐宝呗666's avatar
乐宝呗666 committed
509 510 511
  }
  .van-field__control,
  .van-cell__value {
乐宝呗666's avatar
乐宝呗666 committed
512
    color: #333;
乐宝呗666's avatar
乐宝呗666 committed
513
  }
乐宝呗666's avatar
乐宝呗666 committed
514

乐宝呗666's avatar
乐宝呗666 committed
515
  ::v-deep .field-textarea {
乐宝呗666's avatar
乐宝呗666 committed
516
    min-height: 80px;
乐宝呗666's avatar
乐宝呗666 committed
517
    padding: 0;
乐宝呗666's avatar
乐宝呗666 committed
518
    .van-field__value {
乐宝呗666's avatar
乐宝呗666 committed
519
      background-color: #f5f5f5;
乐宝呗666's avatar
乐宝呗666 committed
520 521
    }
    .van-cell {
乐宝呗666's avatar
乐宝呗666 committed
522
      padding: 0;
乐宝呗666's avatar
乐宝呗666 committed
523
    }
乐宝呗666's avatar
乐宝呗666 committed
524
  }
乐宝呗666's avatar
乐宝呗666 committed
525

乐宝呗666's avatar
乐宝呗666 committed
526
  .upload-content {
乐宝呗666's avatar
乐宝呗666 committed
527
    .avatar-plus {
乐宝呗666's avatar
乐宝呗666 committed
528 529 530 531 532 533 534 535 536
      width: 48px;
      height: 48px;
      line-height: 48px;
      text-align: center;
      background-color: #f5f5f5;
      border-radius: 1px;
      font-size: 25px;
      color: #999;
      margin-bottom: 12px;
乐宝呗666's avatar
乐宝呗666 committed
537 538
    }
    .tips {
乐宝呗666's avatar
乐宝呗666 committed
539
      img {
乐宝呗666's avatar
乐宝呗666 committed
540 541 542
        width: 12px;
        height: 12px;
        vertical-align: middle;
乐宝呗666's avatar
乐宝呗666 committed
543 544
      }
      span {
乐宝呗666's avatar
乐宝呗666 committed
545 546 547 548
        margin-left: 4px;
        color: #666;
        font-size: 12px;
        vertical-align: middle;
乐宝呗666's avatar
乐宝呗666 committed
549
      }
乐宝呗666's avatar
乐宝呗666 committed
550
    }
乐宝呗666's avatar
乐宝呗666 committed
551
  }
乐宝呗666's avatar
乐宝呗666 committed
552 553
}
</style>