gasBottleImportDialog.vue 5.5 KB
<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
        :data="uploadObj"
        :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('queryForm')"
        >确 定</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{
      queryFormRules:{
        qyId:[
          {required:true,message:'请选择所属企业',trigger:'change'}
        ],
        qzId:[
          {required:true,message:'请选择所属气站',trigger:'change'}
        ],
      },
      qyOption:[],
      qzOption:[],
      allOption:[],
      //上传文件携带的参数
      uploadObj: {
        czId:"",
      },
      queryForm:{
        qyId:'',
        qzId:''
      },
      // 发货导入参数
      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() {
    await this.getEnterpriseAndStationList();
    console.log('打印this.$store.getters',this.$store);
    this.upload.action = `${window.context.portal}/manage/qpxx/v1/bottleBatchImport`;
  },
  methods:{
    open(row){
      console.log('打印row',row);
      this.upload.open = true;
      this.queryForm.qzId = '';
      this.queryForm.qyId = '';
      this.upload.title ='导入气瓶信息';
    },
    //获取企业和气站数据
    async getEnterpriseAndStationList(){
      await getCurrentEnterpriseAndStation().then((res)=>{
        console.log('打印当前气站和企业信息数据====',res);
        const { value } = res;
        if(value.length>0){
          this.allOption = value;
          this.qyOption = value?value.map((item)=>{
            return {
              qyId:item.qyId,
              qymc:item.qymc
            }
          }):[];
          console.log('打印 this.qyOption ', this.qyOption );
          console.log('打印 this.allOption ', this.allOption );
        }
      })
    },
    //选择企业的数据
    handleQyChange(val){
      this.qzOption =[];
      this.queryForm.qzId ='';
      this.qzOption = this.allOption.filter((item)=>item.qyId == val)[0].qzxxList;
    },
    submitDeliveryForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.uploadObj.czId = this.queryForm.qzId;
          this.$refs.upload.submit();
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    //文件上传失败处理
    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>