<template>
  <div class="dialogSty">
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
<!--      <el-row>-->
<!--        <el-form label-width="90px" :model="queryForm" :rules="queryFormRules" ref="queryForm" >-->
<!--          <el-form-item label="所属企业:"  prop="qyId">-->
<!--            <el-select v-model="queryForm.qyId" style="width: 100%;" @change="handleQyChange" placeholder="请选择">-->
<!--              <el-option v-for="item in qyOption" :key="item.qyId" :label="item.qymc" :value="item.qyId">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
<!--          <el-form-item label="所属气站:" prop="qzId">-->
<!--            <el-select v-model="queryForm.qzId" style="width: 100%;" placeholder="请选择">-->
<!--              <el-option v-for="item in qzOption" :key="item.qzId" :label="item.qzmc" :value="item.qzId">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
<!--        </el-form>-->
<!--      </el-row>-->
      <el-upload
        ref="upload"
        accept=".xlsx, .xls"
        multiple
        :action="upload.action"
        drag
        :on-success="handleFileSuccess"
        :auto-upload="false"
        :headers="upload.headers"
        :on-error="handleFileError"
      >
        <!-- :disabled="upload.isUploading" -->
        <!-- :on-progress="handleFileUploadProgress"  -->
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">
<!--          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>-->
        </div>
        <div class="el-upload__tip" style="color: red;" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button @click="upload.open = false">取 消</el-button>
        <el-button type="primary" @click="submitDeliveryForm"
        >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getGasBottleTemplate } from '@/api/gasRecord'
import download from "@/mixins/download";
import {getCurrentEnterpriseAndStation} from "@/api/common";
export default {
  name: "gasBottleImportDialog",
  mixins: [ download ],
  data(){
    return{
      // 发货导入参数
      upload: {
        // 是否显示弹出层（会员导入）
        open: false,
        action:'',
        // 弹出层标题（会员导入）
        title: "",
        // 是否禁用上传
        // isUploading: false,
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + this.$store.state.user.accessToken,
        },
        // 上传的地址
        // url: process.env.VUE_APP_BASE_API + "/fm/importUser/importData"
      },
    }
  },
  async created() {
    console.log('打印this.$store.getters',this.$store);
    this.upload.action = `${window.context.portal}/manage/wCzgl/v1/fillingUpImport`;
  },
  methods:{
    open(row){
      console.log('打印row',row);
      this.upload.open = true;
      this.upload.title ='充装信息导入';
    },
    submitDeliveryForm() {
      this.$refs.upload.submit();
    },
    //文件上传失败处理
    handleFileError(err, file, fileList) {
      this.$message.error("上传失败，请重新上传!");
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.$refs.upload.clearFiles();
      this.$message.success("导入成功");
      this.$emit('handleRefresh');
    },
    /** 下载模板操作 */
    async importTemplate() {
      await getGasBottleTemplate().then((response) => {
        console.log("response", response);
        this.handleDownload(response, "气瓶信息导入模板");
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.dialogSty{

}

</style>
