<script>
import { post } from '../../utils/request'

export default {
  data() {
    return {
      file: {},
      fileList: [],
      loading: false
    }
  },
  methods: {
    // 重置表单
    resetForm (formName) {
      this.file = {}
      this.$router.push({ name: 'licenseManage' })
    },
    //提交表单
    submitFormVolume(){
      if (this.loading) return
      this.loading = true
      this.$refs.upload.submit()
      const formData = new FormData()
      formData.append("file",this.file)
      post('/pdf-tech/vppLicenseCode/cancelLicenceAssignBatch', formData).then((res) => {
        setTimeout(() => {
          this.loading = false
        }, 2000)
        if(res.data.code === 200){
          this.$message({
            duration: 5000,
            message: res.data.result,
            type: "success",
          })
          this.$router.push({ name: 'licenseManage' })
        } else{
          this.$message({
            duration: 5000,
            message: 'Remove Failed',
            type: "error",
          })
        }
      })
    },
    //上传文件
    upLoadChange(file){
      this.file = file
      this.fileList.push(file)
      return false
    }
  },
}
</script>

<template>
  <div>
    <h1 class="text-28px leading-40px mb-15px font-700">Batch Remove Licenses</h1>
    
    <div class="bg-[#fff] card rounded-8px">
      <!-- 批量添加 -->
      <el-form
        label-position="top"
        label-width="100px"
        inline-message
        class="p-40px"
      >
        <el-form-item>
          <span slot="label" class="label">
            <span class="text-[24px] leading-32px">
              Remove Licenses from Excel File
            </span>
            <br>
            <span class="text-[14px] leading-20px text-[#808185]">
              Upload an xlsx file to remove licenses. You can download the sample xlsx file for an example.
            </span>
          </span>
        </el-form-item>
        <el-form-item>
          <el-upload
            class="upload-demo"
            drag
            action="111"
            :before-upload="upLoadChange"
            :auto-upload="false"
            :limit="1"
            accept=".xlsx"
            ref="upload">
            <div class="el-upload__text">Drag and drop xlsx file here or <em>browse</em></div>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <span slot="label" class="label leading-20px text-[#1460F3] hover:opacity-70 cursor-pointer">
            <a href="/download/Template Form of Batch Cancel License.xlsx" download="Template Form of Batch Cancel License.xlsx" class="font-normal">
              Download sample xlsx file <img src="@/assets/images/downLoadBlue.svg" class="inline-block ">
            </a>
          </span>
        </el-form-item>
        <el-form-item>
          <button
            type="button"
            @click="resetForm('formData')"
            class="
              w-168px
              h-48px
              border-1px border-[#1460F3]
              text-[#1460F3]
              rounded-8px
              mr-16px
              font-bold
              hover:opacity-80
            "
          >
            Back
          </button>
          <button
            type="button"
            @click="submitFormVolume()"
            class="
              w-168px
              h-48px
              bg-[#1460F3]
              text-[#fff]
              rounded-8px
              font-bold
              hover:opacity-80
            "
          >
            Remove License
          </button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.hand {
  cursor: pointer;
}
.el-form-item::v-deep label {
  color: #232a40 !important;
}
.card {
  border-radius: 8px;
  border-top-left-radius: 0px;
}
.required::v-deep label::before {
  display: none;
}
.el-form-item::v-deep label {
  font-weight: 700;
  padding: 0;
  margin-left: 8px;
}
::v-deep .el-upload__text{
  margin: 70px 0;
  color: #808185;
}
::v-deep .el-upload-dragger{
  border: 1px solid #d9d9d9;
  width: 100%;
}
::v-deep .el-upload{
  width: 50%;
}
::v-deep .el-upload-list__item{
  width: 50%;
}
</style>
