/*续用资源*/
<template>
  <div>
    <transition name="marsk-fade">
      <div v-show="continueConfig.isShow" class="marsk" />
    </transition>
    <transition name="slide-fade">
      <div v-show="continueConfig.isShow" class="action-limit">
        <div class="title">
          <p>续用资源</p>
          <div class="operation">
            <i class="el-icon-circle-close" @click="close" />
          </div>
        </div>
        <el-form
          ref="applyForm"
          :model="applyForm"
          :rules="rules"
          label-width="120px"
          class="apply"
          label-position="left"
        >
          <el-form-item label="资源续用时长" prop="resUsePeriod">
            <el-input
              size="mini"
              type="number"
              v-model="applyForm.resUsePeriod"
              placeholder="请填写续用时长"
              ><span slot="suffix" class="solt">小时</span></el-input
            >
          </el-form-item>
          <el-form-item label="资源续用说明">
            <el-input
              type="textarea"
              size="mini"
              :autosize="{ minRows: 3, maxRows: 5 }"
              resize="none"
              v-model="applyForm.resUseInfo"
              placeholder="请填写资源续用说明"
            ></el-input>
          </el-form-item>
        </el-form>
        <div class="btn-group">
          <el-button
            type="danger"
            size="small"
            class="next-btn"
            @click.native.prevent="sure"
            >提交申请</el-button
          >
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import { request } from '@/utils/request'
export default {
  name: 'ContinueResource',
  props: {
    continueConfig: {
      isShow: {
        type: Boolean,
        default: () => false,
      },
      resApplyId: {
        type: String,
        default: () => '',
      },
    },
  },
  data() {
    const validateTime = (rule, value, callback) => {
      if (value) {
        if (
          !/(^[1-9]\d*$)/.test(value) ||
          value.toString().indexOf('.') != -1
        ) {
          callback(new Error('资源时长只能是正整数!'))
        } else {
          callback()
        }
      } else {
        callback(new Error('请输入资源时长！'))
      }
    }
    return {
      applyForm: {
        resUsePeriod: '24',
        resUseInfo: '',
      },
      //rules前端验证
      rules: {
        resUsePeriod: [
          { required: true, trigger: 'blur', validator: validateTime },
        ],
        productDesc: [
          { required: true, message: '请输入作品说明', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    // 点击关闭
    close() {
      this.applyForm = {
        resUsePeriod: '24',
        resUseInfo: '',
      }
      this.$emit('putContinue', false)
    },
    // 点击确定
    sure() {
      this.$refs.applyForm.validate((valid) => {
        if (valid) {
          const params = {
            transCode: 'C00027',
            applyResId: this.continueConfig.resApplyId,
            resUsePeriod: this.applyForm.resUsePeriod,
            resUseInfo: this.applyForm.resUseInfo,
          }
          request(params)
            .then((res) => {
              this.$message.success(
                `已申请续用资源 ${this.applyForm.resUsePeriod} 小时，请等待审核!`
              )
              this.applyForm = {
                resUsePeriod: '24',
                resUseInfo: '',
              }
              this.$emit('putContinue', this.continueConfig)
            })
            .catch((err) => {})
        } else {
          return false
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';

.marsk-fade-enter-active,
.marsk-fade-leave-active {
  transition: all 0.5s;
}
.marsk-fade-enter,
.marsk-fade-leave-to {
  opacity: 0;
}
.marsk {
  @include position(fixed, 0, 0, 0, 0, 1000);
  background: rgba(4, 112, 204, 0.05);
}

.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateY(7.48rem);
}
.action-limit {
  @include position(absolute, 50%, auto, 55%, auto, 1001);
  @include w_h(450px);
  padding: 30px 40px;
  transform: translate(-50%, -50%);
  background: $color_f;
  border-radius: 4px;
  box-shadow: 0 0 7px 7px rgba(0, 0, 0, 0.04);
  .title {
    @include flex();
    font-size: 18px;
    font-weight: 700;
    color: $color_3;
    .operation {
      font-size: 24px;
      color: $color_9;
      &:hover {
        cursor: pointer;
        color: $color_b;
      }
    }
  }
  .num-list {
    @include w_h();
    @include flex(flex-start);
    flex-wrap: wrap;
    margin: 30px auto 10px;
  }
  .desc {
    @include flex();
    font-size: 12px;
    color: $color_6;
  }
  .apply {
    margin: 30px auto;
    .el-select {
      @include w_h();
    }
  }
  .btn-group {
    @include w_h();
    margin: 30px auto;
    .next-btn {
      @include w_h();
    }
  }
}
</style>

<style lang="scss">
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';
@supports (-webkit-mask: none) and (not (cater-color: $color_9)) {
  .el-input input {
    font-size: 12px;
    color: $color_6;
  }
}

.el-input {
  &__inner {
    padding: 0 5px;
  }
  &__inner:focus {
    border-color: $color_9;
  }
  &--suffix {
    line-height: 28px;
  }
  &--suffix .el-input__inner {
    padding-right: 20px;
  }
}
</style>
