<template>
  <el-dialog title="安检单导出" :visible.sync="open" width="500px" append-to-body destroy-on-close :close-on-click-modal="false">

    <el-form :model="param" :rules="rules" label-width="80px">
      <el-form-item label="安检时间" prop="inspectDate">
        <el-date-picker
          v-model="inspectDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
          @change="timeChange"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="文件名称" prop="fileName">
        <el-input v-model="param.fileName" placeholder="请输入巡检任务标题" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" :loading="exportLoading">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>

</template>

<script>
  import { exportInspectZip } from "@/api/checktask/inspect";
  export default {
    name: "export-inspect",
    data(){
      return{
        open: false,
        inspectDate: [],
        param:{},
        exportLoading: false,
        rules:{
          fileName: [
            { required: true, message: "文件名称不能为空", trigger: "blur" },
          ],
        },
        pickerOptions:{
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e7;
          },
        }
      }
    },
    methods:{
      init(query){
        this.inspectDate = [];
        this.param = { ...query };
        this.open = true;
      },
      submitForm(){
        this.exportLoading = true;
        exportInspectZip(this.param).then((res) =>{
          this.exportLoading = false;
          if(res.code == 200){
            this.download(res.msg);
            this.open = false;
          }
        })
      },
      cancel(){
        this.open = false;
        this.inspectDate = [];
      },
      timeChange(val){
        this.param.inspectBeginTime = val[0];
        this.param.inspectEndTime = val[1];
      }
    }
  }
</script>

<style scoped>

</style>
