<template>
    <div class="common-page-content">
      <div class="common-search-container" ref="contentPanel">
        <el-form
          ref="form"
          :model="searchForm"
          label-width="auto"
          label-position="right "
          :inline="true"
          type="flex"
          justify="left"
        >
          <el-form-item label="企业名称">
            <el-input
              size="small"
              v-model="searchForm.enterprise_name_"
              clearable
              placeholder="请输入企业名称"
            ></el-input>
          </el-form-item>
        </el-form>
        <div class="container-btn">
          <el-button
            size="small"
            icon="el-icon-search"
            type="danger"
            class="btn btn-plus"
            @click="handleSearch"
          >
            搜索
          </el-button>
          <el-button
            size="small"
            icon="el-icon-refresh-right"
            class="btn btn-plus"
            @click="clearSearchForm"
          >
            重置
          </el-button>
        </div>
      </div>
      <el-row
        class="common-table-container flex searchPanel"
        :style="SearchPanel"
      >
        <el-col :span="24" class="common-table-wrapper">
          <div class="common-btn-group">
            <!-- <el-button
              size="small"
              icon="el-icon-plus"
              type="primary"
              class="btn btn-plus"
              @click="handleAdd"
            >
              新增
            </el-button>
             <el-button
              size="small"
              slot="reference"
              icon="el-icon-delete"
              type="danger"
              class="btn btn-delete"
              @click="handleDelete"
            >
              {{ this.$t('common.delete') }}
            </el-button> -->
            <!-- <el-button
              size="small"
              icon="el-icon-plus"
              type="primary"
              class="btn btn-plus"
              @click="handleAppro"
            >
              提交审核  
            </el-button> -->
          </div>
          <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
          <div class="common-table-content btn-pagenation">
            <el-table
              :border="true"
              stripe
              fit
              size="mini"
              v-loading="tableLoading"
              ref="multipleSelection"
              :data="tableData"
            >
              <el-table-column type="selection" min-width="5%" align="center">
              </el-table-column>
              <el-table-column
                prop="enterpriseName"
                show-overflow-tooltip
                min-width="130px"
                align="center"
                label="企业名称"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="supplierName"
                min-width="130px"
                label="供应商名称"
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="companyOrgcode"
                min-width="130px"
                label="供应商税号"
                align="center"
                resizable
              >
              </el-table-column>
              
              <el-table-column
              prop="level"
              min-width="100px"
              label="审核状态"
              align="center"
              resizable
            >
              <template slot-scope="scope">
                <el-tag type="info" v-if="scope.row.reviewStatus == 0"
                  >待提交</el-tag
                >
                <el-tag type="waring" v-if="scope.row.reviewStatus == 1"
                  >审核中</el-tag
                >
                <el-tag type="success" v-if="scope.row.reviewStatus == 2"
                  >已审核</el-tag
                >
                <el-tag type="danger" v-if="scope.row.reviewStatus == 3"
                  >驳回</el-tag
                >
              </template>
            </el-table-column>
            </el-table>
          </div>
          <div class="common-pagenation">
            <el-pagination
              ref="paginationPanel"
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryParam.pageBean.page"
              :page-sizes="[20, 30, 40, 50]"
              :page-size="queryParam.pageBean.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryParam.pageBean.total"
            >
            </el-pagination>
          </div>
        </el-col>
      </el-row>
      <el-dialog
        title="资质文件上传"
        :visible.sync="dialogVisible"
        width="600px"
        :close-on-click-modal="false"
        :before-close="cancelConfirm"
      >
        <el-form
          ref="form"
          label-width="auto"
          label-position="right "
          :inline="true"
        >
          <el-row :gutter="24">
            <el-col :span="24">
              <el-form-item label="文件导入" >
                <el-upload
                  class="upload-demo"
                  ref="upload"
                  :headers="headers"
                  :action="action"
                  :file-list="fileList"
                  :multiple="true"
                  accept=".png,.jpg,.jpeg,.xlsx,.xls,.pdf,.docx,.doc,.zip,.rar"
                  :show-file-list="true"
                  :before-upload="beforeUpload"
                  :on-success="handleSuccess"
                >
                  <el-button icon="el-icon-upload2" class="dia-btn" slot="trigger" size="small" type="primary"
                    >资质文件上传</el-button
                  >
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="cancelConfirm()">取 消</el-button>
          <el-button
            size="small"
            type="primary"
            @click="submitImport"
            plain
            :loading="loadingBtn"
            element-loading-text="拼命导入中"
            v-loading.fullscreen.lock="fullscreenLoading"
            >确 定</el-button
          >
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import supplierManger from '@/api/supplierManger.js'
  import {mapState} from 'vuex'
  import pagination from '@/components/pagination'
  import {TableMixin} from '@/mixins/tableMixin'
  import routerManagement from '@/api/BasicDataManagement/routerManagement.js'
  import req from '@/request.js'
  import utils from '@/utils.js'
  import {file} from 'jszip'
  export default {
    name: 'DemandEntry',
    components: {
      pagination,
    },
    mixins: [TableMixin],
    data() {
      return {
        currentPage: 1,
        tableMaxHeight: 400,
        dialogVisible: false,
        loading: false,
        tableLoading: false,
        loadingBtn:false,
        tableData: [],
        fullscreenLoading:false,
        multipleSelection: [],
        form:{},
        queryParam: {
          pageBean: {
            page: 1,
            pageSize: 20,
            total: 0,
          },
        },
        searchForm: {
          type: 2,
        }, // 顶部搜索对象
        deleteIds: '', // 是否选中列表解锁删除按钮
        fileList: [], // 文件上传
        edit: false, // 是否是修改功能
        currentDataDel: [], // 删除时排查是否有在审核的数据
      }
    },
    created() {
      this.handleSearch()
    },
    methods: {
      getDictName(code, value) {
        return utils.getDictName(code, value)
      },
      // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用,function(file, fileList)
      handleSuccess(res, file, fileList) {
        console.log(res, 'resss',file)
        if(this.fileList.length==0){
          this.fileList=[]
          this.fileList.push(res.value)
        }else{
          this.fileList.push(res.value)
        }
      },
      beforeUpload(file) {
      let acceptList = ['xlsx', 'xls','png','jpg','jpeg','xlsx','xls','pdf','docx','doc','zip','rar']
      // 根据文件名获取文件的后缀名
      let fileType = file.name.split('.').pop().toLowerCase()
      // 判断文件格式是否符合要求
      if (acceptList.indexOf(fileType) === -1) {
        this.$message.error('请上传 .png,.jpg,.jpeg,.xlsx,.xls,pdf,.docx,.doc,.zip,.rar 格式的文件 !')
        return false
      }
    },
      handleOpen(row){
        this.form =row
        this.dialogVisible = true
      },
      submitImport(){
        let data = {
          id:this.form.id,
          qualificationsList:this.fileList
        }
        this.loadingBtn = true
        this.fullscreenLoading = true
        this.$http.post('${portal}/supplier/bizSupplierEnterprise/v1/uploadAccessory',data).then(res=>{
          this.loadingBtn = false
          this.fullscreenLoading = false
          if(res.data.state){
            this.fileList = []
            this.$message.success(res.data.message)
          }
          this.handleSearch()
        })
      },
      //获取数据
      loadData() {
        this.tableLoading = true
        this.$http
          .post(
            '${portal}/supplier/bizSupplierEnterprise/v1/queryByEnterprise',
            this.queryParam
          )
          .then((res) => {
            this.tableLoading = false
            const data = (res && res.data) || {}
            this.tableData = data.rows || []
            this.queryParam.pageBean = {
              page: data.page,
              pageSize: data.pageSize,
              total: data.total,
            }
          })
      },
      //添加
      handleAdd() {
        this.$router.push({
          path: '/addTemporaryEnterprise',
        })
      },
      // 编辑
      handleEdit(rows) {
        this.$refs.form.clearValidate()
        this.$router.push({
          path: `/onboardingAddDialog/${rows.id}`,
          query: {pageBean: this.params},
        })
      },
      // 详情
      handleDetail(rows) {
        this.$router.push({
          path: `/onboardingDetail/${rows.id}`,
          query: {pageBean: this.params},
        })
      },
      cancelConfirm(){
        this.fileList = []
        this.dialogVisible = false
      },
      // 删除
      handleDelete() {
        let selection = this.$refs.multipleSelection.selection
        if (selection.length === 0) {
          this.$alert('请选择要删除的数据！', this.$t('common.tips'), {
            confirmButtonText: this.$t('common.confirm'),
            type: 'warning',
          })
        } else {
          let ids = []
          selection.forEach((item) => {
            let str = 'ids=' + item.id
            ids.push(str)
          })
          ids = ids.join('&')
          this.$confirm(this.$t('common.sureDelete'), this.$t('common.tips'), {
            confirmButtonText: this.$t('common.confirm'),
            cancelButtonText: this.$t('common.cancel'),
            type: 'warning',
          }).then(() => {
            this.tableLoading = true
            supplierManger.delManage(ids).then((res) => {
              this.tableLoading = false
              if (res.data.state) {
                this.$message.success('删除成功！')
                this.handleSearch()
              } else {
                this.$message.error('删除失败！')
              }
            })
          })
        }
      },
      //重置
      clearSearchForm() {
        this.searchForm = {
          type: 2,
        }
        this.handleSearch()
      },
      // 顶部搜索
      handleSearch() {
        let obj = this.searchForm
        let querys = []
        for (let i in obj) {
          if (obj[i]) {
            querys.push({
              group: 'main',
              operation:
                i == 'supplier_code_' || i == 'enterprise_name_'
                  ? 'LIKE'
                  : 'EQUAL',
              parentGroup: '',
              property: i,
              relation: 'AND',
              value: obj[i],
            })
          }
        }
  
        this.queryParam.querys = querys
        this.loadData(this.queryParam)
      },
      // 审核
      handleAppro(){
        
      },
      handleCurrentChange(page) {
        this.queryParam.pageBean = {...this.queryParam.pageBean, page}
        this.loadData(this.queryParam)
      },
      handleSizeChange(pageSize) {
        this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
        this.loadData(this.queryParam)
      },
      handleAppro(){
        
      },
    },
    computed: {
      ...mapState({
        headers: (state) => {
          return {Authorization: `Bearer ${state.login.currentUser.token}`}
        },
        action: function () {
          return (
            window.context.portal +
            '/biz/universal/v1/minioUpload'
          )
        },
      }),
      SearchPanel() {
        return {
          '--searchPanel': this.searchPanel + 'px',
        }
      },
    },
  }
  </script>
  
  <style lang="scss" scoped>
  .cloumn-btn {
    border: 1px solid #2761ff;
    padding: 3px 10px;
    border-radius: 5px;
    &:nth-child(1) {
      margin-right: 5px;
    }
    &:nth-child(2) {
      margin-right: 5px;
    }
    &:nth-child(1):hover {
      background-color: #2761ff;
      color: #fff;
    }
    &:nth-child(2):hover {
      background-color: #2761ff;
      color: #fff;
    }
    /deep/ i,
    span {
      font-size: 16px;
    }
  }
  .dia-btn{
    width: 100% !important;
  }
  /deep/ .el-tree-node__content {
    padding: 5px 0;
  }
  
  /deep/ .el-table thead tr th {
    background-color: #eee !important;
    border-right: 1px solid #dfe2e8 !important;
  }
  /deep/ .el-table {
    border-collapse: collapse !important;
  }
  </style>
  