commitTab.vue 14.6 KB
Newer Older
Your Name's avatar
Your Name committed
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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
<template>
  <div class="commit-page-content">
    <van-form @submit="onSubmit">
      <div class="field-title">
        <span>基本信息</span>
      </div>
      <div class="input-box">
        <van-field
          class="field-form-item"
          readonly
          clickable
          required
          name="boardName"
          input-align="right"
          :value="form.boardName"
          label="展板名称"
          placeholder="请选择展板"
          :right-icon="showBoard ? 'arrow-up' : 'arrow-down'"
          @click="showBoard = true"
          :rules="[{ required: true ,message: '请选择展板' ,trigger:'change'}]"
        />
        <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"
        />
        <van-field
          class="field-form-item"
          readonly
          clickable
          required
          name="studyTime"
          input-align="right"
          :value="form.studyTime || ''"
          label="学习时间"
          placeholder="请选择学习时间"
          :right-icon="form.studyTime || cellIcon"
          @click="onDisplay"
          :rules="[{ required: true ,message: '请选择学习时间',trigger:'change' }]"
        />
        <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
          required
          label="观影人数"
          v-model="form.num"
          placeholder="请输入观影人数"
          input-align="right"
          :rules="[{ pattern: /^[1-9]\d{0,9}$/, message: '请输入正确内容,最多10位数',trigger:'blur'}]"
        />
        <van-field
          required
          label="管理员账号"
          v-model="form.name"
          placeholder="请输入管理员账号"
          input-align="right"
          :rules="[{ required: true }]"
        />
        <van-field
          required
          type="password"
          label="管理员密码"
          v-model="form.password"
          placeholder="请输入管理员密码"
          input-align="right"
          :rules="[{ required: true }]"
        />
      </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="3"
              v-model="fileList"
              accept="video/*"
              :before-read="beforeVideo"
              :after-read="uploadVideo"
              :before-delete="deleteVideo"
              multiple
            >
              <div class="avatar-plus">
                <span>+</span>
              </div>
            </van-uploader>
          </div>
          <div class="tips">
            <img src="@/assets/images/applets/tip.png" alt />
            <span>
              最多支持上传
              <b>3</b> 段视频,每段大小不能超过 <b>10MB</b>
            </span>
          </div>
        </div>
      </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">
            <img src="@/assets/images/applets/tip.png" alt />
            <span>
              最多支持上传
              <b>6</b> 张照片
            </span>
          </div>
        </div>
      </div>
      <div class="field-title">
        <span>有话对党说</span>
      </div>
      <div class="field-content">
        <van-field
          required
          class="field-textarea"
          type="textarea"
          v-model="form.content"
          maxlength="500"
          show-word-limit
          placeholder="我有话对党说..."
          :rules="[{ required: true ,message: '请输入内容,最多500个字'}]"
        />
      </div>
      <div class="commit-page-button">
        <van-button type="default" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import util from "@/utils/index.js";
export default {
  data() {
    return {
      form: {
        username: JSON.parse(sessionStorage.getItem("userInfo")).orgName,
        organId: JSON.parse(sessionStorage.getItem("userInfo")).orgId,
        images: [], // 文件地址
        videos: [], // 文件地址
      },
      currentDate: new Date(),
      boardList: [],
      boardNameList: [],
      showBoard: false,
      cellIcon: require("@/assets/images/applets/date.png"),
      show: false,
      fileList: [], // 预览
      imgFileList: [],// 预览
      videoIds:[], // 文件ID
      imageIds:[] // 文件ID
    };
  },
  mounted() {
    this.getBoardList();
  },
  methods: {
    // 获取所属单位
    getBoardList() {
      let vm = this;
      vm.$https({
        url: "exhibitionBoard/getList",
        method: "post",
        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);
        });
    },
    // 下拉框确认按钮
    onConfirmBoard(value, index) {
      this.form.boardName = value;
      this.form.boardId = this.boardList[index].id;
      this.showBoard = false;
    },
    // 打开日历
    onDisplay() {
      this.show = true;
    },
    // 关闭日历
    onClose() {
      this.show = false;
    },
    // 确认日历
    onConfirm(event) {
      this.show = false;
      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
      );
    },
    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}分`;
    },
    // 删除图片
    async deleteImg(file,detail){
      this.form.images.splice(detail.index,1)
      const id = this.imageIds[detail.index]
      this.imageIds.splice(detail.index,1)
      await this.deleteInterface(id)
    },
    // 上传图片
    uploadImg(file) {
      let param = new FormData();
      if(Array.isArray(file)){
        file.forEach(item=>{
          param.append("file", item.file)
        })
      }else{
        param.append("file", file.file)
      }
      this.uploadImgInterface(param)
    },
    // 上传图片接口
    uploadImgInterface(param){
      let vm = this;
      vm.$https(
        {
          url: "file/datum/upload",
          method: "post",
          authType: this.backToken,
        },
        param
      )
        .then((res) => {
          if(res.data.resultCode==='200'){
            this.$toast('上传成功')
            res.data.data.fileList.forEach(item=>{
              this.form.images.push(item.fileUrl);
              this.imageIds.push(item.id);
            })
          }else{
            this.$toast(res.data.message)
          }
        })
        .catch(function (err) {
          console.log(err);
        });
    },
    // 上传视频size限制
    beforeVideo(file) {
      let isOver = true
      if(Array.isArray(file)){
        isOver = file.every(item=>item <= 10*1024*1024)
      }else{
        isOver = file.size <= 10*1024*1024
      }
      if(!isOver){
        this.$toast.fail("上传文件大小不能超过 10MB");
        return false
      }else{
        return true
      }
    },
    // 删除视频
    async deleteVideo(file,detail){
      this.form.videos.splice(detail.index,1)
      const id = this.videoIds[detail.index]
      this.videoIds.splice(detail.index,1)
      await this.deleteInterface(id)
    },
    // 上传视频
    uploadVideo(file) {
      let param = new FormData();
      if(Array.isArray(file)){
        file.forEach(item=>{
          param.append("file", item.file)
        })
      }else{
        param.append("file", file.file)
      }
      this.uploadVideoInterface(param)
    },
    // 上传视频接口
    uploadVideoInterface(param){
      let vm = this;
      vm.$https(
        {
          url: "file/video/upload",
          method: "post",
          authType: this.backToken,
        },
        param
      )
        .then((res) => {
          if(res.data.resultCode==='200'){
            this.$toast('上传成功')
            res.data.data.fileList.forEach(item=>{
              this.form.videos.push(item.fileUrl);
              this.videoIds.push(item.id);
            })
          }else{
            this.$toast(res.data.message)
          }
        })
        .catch(function (err) {
          console.log(err);
        });
    },
    // 删除接口
    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);
        });
    },
    
    // 提交数据
    onSubmit() {
      let vm = this;
      let param = {};
      for (let key in this.form) {
        if (this.form[key]) {
          param[key] = this.form[key];
        }
      }
      param.password = util.encrypt(this.form.password),
      param.images = [...param.images, ...param.videos];
      param.images = param.images.join(",");
      delete param.videos;
      vm.$https(
        {
          url: "interaction/add",
          method: "post",
          authType: this.backToken,
        },
        vm.$qs.stringify(param)
      )
        .then((res) => {
          if (res.data.resultCode === "200") {
            this.$router.replace({path:"/success",query:{txt:'提交成功',url:'/commit'}})
          } else {
            this.$toast(res.data.message)
          }
        })
        .catch(function (err) {
          console.log(err)
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.commit-page-content {
  padding: 24px 20px;
  height: calc(100% - 200px);
  overflow-y: auto;
  .field-title {
    position: relative;
    padding-bottom: 20px;
    span {
      color: #333;
      font-size: 16px;
      line-height: 20px;
      &:before {
        content: "";
        height: 16px;
        width: 4px;
        border-radius: 1px;
        display: inline-block;
        background: #a4151d;
        position: absolute;
        left: -20px;
        top: 2px;
      }
    }
  }
  .field-content {
    padding-bottom: 32px;
    .upload-content {
      .avatar-plus {
        width: 48px;
        height: 48px;
        line-height: 48px;
        text-align: center;
        background-color: #f5f5f5;
        border-radius: 1px;
        font-size: 25px;
        color: #999;
        margin-bottom: 12px;
      }
      .tips {
        img {
          width: 12px;
          height: 12px;
          vertical-align: middle;
        }
        span {
          margin-left: 4px;
          color: #666;
          font-size: 12px;
          vertical-align: middle;
        }
      }
    }
  }
  .input-box {
    padding-bottom: 32px;
    .van-cell {
      line-height: 40px;
      padding-left: 0;
      padding-right: 0;
      border-bottom: 1px solid #eee;
    }
    .van-cell:after {
      display: none;
    }
  }
  .commit-page-button {
    position: fixed;
    bottom: 50px;
    left: 0;
    right: 0;
    padding: 0 40px;
    background-color: #fff;
    box-sizing: border-box;
    padding-top: 10px;
    padding-bottom: 10px;
    width: 100%;
    .van-button--normal {
      background: #a4151d;
      border-radius: 4px;
      height: 40px;
      width: 100%;
      color: #fff;
      border: none;
      font-size: 16px;
    }
  }
  .van-field__control,
  .van-cell__value {
    color: #333;
  }
  ::v-deep .van-field__error-message {
    text-align: right;
    background: #fff;
  }
  ::v-deep .field-textarea {
    min-height: 80px;
    padding: 0;
    margin-bottom: 150px;
    .van-field__value {
      background-color: #f5f5f5;
    }
    .van-cell {
      padding: 0;
    }
  }
  ::v-deep .van-cell--required::before {
    left: -10px;
    color:#A4151D;
  }
 
}
乐宝呗666's avatar
乐宝呗666 committed
553
</style>