<template>
  <div class="divBox">
    <el-card class="box-card">
      <!--顶部搜索-->
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" label-width="100px" :inline="true">
            <el-form-item label="酒厂名称：" label-width="100px" style="display: inline-block;">
              <el-input style="width: 350px" v-model="tableFrom.winery_name" placeholder="请输入酒厂名称" class="selWidth"></el-input>
            </el-form-item>
            <el-form-item label="联系人姓名：" label-width="100px" style="display: inline-block;">
              <el-input style="width: 350px" v-model="tableFrom.contacts_name" placeholder="请输入联系人姓名" class="selWidth"></el-input>
            </el-form-item>
            <el-form-item label="联系电话：" label-width="100px" style="display: inline-block;">
              <el-input style="width: 350px" v-model="tableFrom.contacts_phone" placeholder="请输入联系电话" class="selWidth"></el-input>
            </el-form-item>
            <el-form-item label="状态：" label-width="100px" style="display: inline-block;">
              <el-select v-model="tableFrom.status" clearable filterable placeholder="请选择" class="selWidth">
                <el-option label="审核中" :value="0" />
                <el-option label="已通过" :value="1" />
                <el-option label="已驳回" :value="2" />
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <el-button size="small" type="primary" @click="getList(1)">搜索</el-button>
      </div>
      <!--列表-->
      <el-table v-loading="listLoading" :data="tableData.data">
        <el-table-column prop="id" label="ID" min-width="80" />
        <el-table-column label="邀请人信息" min-width="280" align="center">
          <template slot-scope="scope">
            <div class="user-content" v-if="scope.row.agent">
              <div class="user-avatar">
                <img :src="scope.row.agent.avatar || moren" />
              </div>
              <div class="user-info">
                <div class="nickname">{{ scope.row.agent.nickname }}</div>
                <div class="user-id">{{ scope.row.agent.uid }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="酒厂名称" prop="winery_name" min-width="150" align="center"/>
        <el-table-column label="年产量(吨)" prop="scale" min-width="100" align="center"/>
        <el-table-column label="窖池大小(m³)" prop="cellar_size" min-width="120" align="center"/>
        <el-table-column label="联系人" min-width="120" align="center">
          <template slot-scope="scope">
            {{ scope.row.contacts_name }}<br />
            {{ scope.row.contacts_phone }}
          </template>
        </el-table-column>
        <el-table-column label="状态" min-width="60" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0" type="info" effect="dark" size="small">审核中</el-tag>
            <el-tag v-else-if="scope.row.status == 1" type="success" effect="dark" size="small">已通过</el-tag>
            <el-tag v-else type="danger" effect="dark" size="small">已驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="申请时间" prop="create_time" min-width="150" align="center"/>
        <el-table-column label="操作" min-width="280" fixed="right" align="center">
          <template slot-scope="scope">
            <template v-if="scope.row.status == 0">
              <el-button type="success" size="small" @click="toExamine(scope.row.id, 1)">通过</el-button>
              <el-button type="danger" size="small" @click="toExamine(scope.row.id, 2)">驳回</el-button>
            </template>
            <el-button type="info" size="small" @click="seeDetails(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--查看详情-->
    <el-drawer :with-header="false" :size="1000" :visible.sync="drawer" direction="rtl" :before-close="closeSeeDetails">
      <div>
        <!--顶部内容-->
        <div class="head">
          <div class="text">
            <div class="title">
              <span class="bold">查看供应商申请信息</span>
            </div>
          </div>
        </div>
        <!--具体内容-->
        <el-form ref="seeInfoField" size="small" :model="seeInfo" label-width="130px" @submit.native.prevent>
          <el-tabs type="border-card" v-model="activeName">
            <el-tab-pane label="基本信息" name="detail">
              <div class="section">
                <div class="title">邀请人</div>
                <el-row :gutter="24" class="mt20">
                  <el-col :span="12">
                    <el-form-item label="邀请人：">
                      <div class="user-content" v-if="seeInfo.agent">
                        <div class="user-avatar">
                          <img :src="seeInfo.agent.avatar || moren" />
                        </div>
                        <div class="user-info">
                          <div class="nickname">{{ seeInfo.agent.nickname }}</div>
                          <div class="agent-type-text">
                            <el-tag type="info" effect="dark" size="small">{{ seeInfo.agent.uid }}</el-tag>
                          </div>
                        </div>
                      </div>
                    </el-form-item>
                  </el-col>
                </el-row>
                <div class="title">基础信息</div>
                <el-row :gutter="24" class="mt20">
                  <el-col :span="8">
                    <el-form-item label="酒厂名称：">
                      <el-input :value="seeInfo.winery_name" readonly disabled />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="年产量(吨)：">
                      <el-input :value="seeInfo.scale" readonly disabled />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="窖池大小(m³)：">
                      <el-input type="text" :value="seeInfo.cellar_size" readonly disabled />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="联系人姓名：">
                      <el-input :value="seeInfo.contacts_name" readonly disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="联系人电话：">
                      <el-input :value="seeInfo.contacts_phone" readonly disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="法人姓名：">
                      <el-input :value="seeInfo.corporation_name" readonly disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="法人电话：">
                      <el-input :value="seeInfo.corporation_phone" readonly disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="法人身份证：">
                      <el-image
                        class="id-image"
                        v-for="(item,index) in seeInfo.corporation_id_card"
                        :key="index"
                        :src="item"
                        :preview-src-list="[item]" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="董事长姓名：">
                      <el-input :value="seeInfo.chairman_name" readonly disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="董事长电话：">
                      <el-input :value="seeInfo.chairman_phone" readonly disabled/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="董事长身份证：">
                      <el-image
                        class="id-image"
                        v-for="(item,index) in seeInfo.chairman_id_card"
                        :key="index"
                        :src="item"
                        :preview-src-list="[item]" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-tab-pane>
            <el-tab-pane label="证件信息" name="account">
              <div class="section">
                <el-row :gutter="24" class="mt20">
                  <el-col :span="24">
                    <el-form-item label="营业执照：">
                      <el-image class="id-image" :src="seeInfo.business_license" :preview-src-list="[seeInfo.business_license]" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="生产许可证：">
                      <el-image class="id-image" :src="seeInfo.production_icense" :preview-src-list="[seeInfo.production_icense]" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="流通许可证：">
                      <el-image class="id-image" :src="seeInfo.circulative_license" :preview-src-list="[seeInfo.circulative_license]" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-form>
      </div>
      <div class="footer">
        <el-button size="small" @click="closeSeeDetails">取消</el-button>
      </div>
    </el-drawer>

  </div>
</template>

<script>
import {supplierApplyList, supplierApplyToExamine} from "@/api/supplier";

export default {
  name: "SupplierList",
  components: { },
  data() {
    return {
      listLoading: true,
      tableFrom: {
        page: 1,
        limit: 20,
        winery_name: "",
        contacts_name: "",
        contacts_phone: "",
        status: "",
      },
      tableData: {
        data: [],
        total: 0
      },
      // 弹框
      activeName: 'detail',
      drawer: false,
      seeInfo: {},
    };
  },
  mounted() {
    this.getList("");
  },
  methods: {
    // 获取申请列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      supplierApplyList(this.tableFrom).then(res => {
        this.tableData.data = res.data.list;
        this.tableData.total = res.data.count;
        this.listLoading = false;
      }).catch(res => {
        this.listLoading = false;
        this.$message.error(res.message);
      });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList("");
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList(1);
    },
    // 审核操作
    toExamine(id, status){
      let _this = this;
      let params = {
        id: id,
        status: status
      };
      if(Number(status) === 2){
        // 驳回
        _this.$prompt('驳回原因', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputErrorMessage: '请输入原因',
          inputType: 'textarea',
          inputPlaceholder: '请输入原因',
          inputValidator: (value) => {
            if (!value) {
              return '请输入原因'
            }
          }
        }).then(({value}) => {
          params.reason = value || '';
          _this.submitToExamine(params);
        }).catch(() => {})
      }else{
        // 通过
        this.$confirm('是否确认审核通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          _this.submitToExamine(params);
        }).catch(() => {});
      }
    },
    // 审核操作 - 提交审核
    submitToExamine(params){
      let _this = this;
      supplierApplyToExamine(params).then(res => {
        _this.$message.success(res.message);
        _this.getList();
      }).catch(res => {
        _this.$message.error(res.message);
      });
    },
    // 查看详情
    seeDetails(info){
      this.seeInfo = info || {};
      this.drawer = true;
    },
    // 关闭查看详情弹框
    closeSeeDetails(){
      this.drawer = false;
    }
  }
};
</script>

<style scoped lang="scss">
.user-content{
  --user-content-height-: 80px;

  height: var(--user-content-height-);
  width: 100%;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  .user-avatar{
    height: var(--user-content-height-);
    width: var(--user-content-height-);
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    img{
      height: 80%!important;
      width: 80%!important;
      border-radius: 50% !important;
    }
  }
  .user-info{
    max-width: calc(100% - var(--user-content-height-));
    height: var(--user-content-height-);
    display: inline-flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: flex-start;
    .nickname{
      width: 100%;
      height: 25px;
      line-height: 25px;
      text-align: left;
      font-size: 15px;
      font-weight: bold;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-flex;
      flex-direction: row;
      flex-wrap: nowrap;
      justify-content: flex-start;
      align-items: center;
      .user-id{
        color: #fff;
        background-color: #409eff;
        border-color: #409eff;
        height: 18px;
        line-height: 20px;
        font-size: 13px;
        padding: 0 5px;
        border-radius: 5px;
        margin-left: 10px;
        width: max-content!important;
      }
    }
    .user-id{
      width: 100%;
      text-align: left;
      font-size: 13px;
      line-height: calc(var(--user-content-height- * 35%));
    }
  }
}
.head {
  padding: 20px 20px 10px;
  .full {
    display: flex;
    align-items: center;
    .order_icon {
      width: 60px;
      height: 60px;
    }
    .text {
      align-self: center;
      flex: 1;
      min-width: 0;
      padding-left: 12px;
      font-size: 13px;
      color: #606266;
      .title {
        margin-bottom: 10px;
        font-weight: 500;
        font-size: 16px;
        line-height: 16px;
        color: #282828;
      }
    }
  }
  .bold{
    font-weight: bold;
  }
  .list {
    display: flex;
    margin-top: 20px;
    overflow: hidden;
    list-style: none;
    padding: 0;
    .item {
      flex: none;
      width: 200px;
      font-size: 14px;
      line-height: 14px;
      color: rgba(0, 0, 0, 0.85);
      .title {
        margin-bottom: 12px;
        font-size: 13px;
        line-height: 13px;
        color: #666666;
      }
    }
  }
}
.footer{
  width: 100%;
  text-align: center;
  position: absolute;
  bottom: 17px;
  padding-top: 17px;
  border-top: 1px dashed #eeeeee;
}
.selWidth{
  margin-bottom: 10px!important;
}
.id-image{
  width: 150px;
  height: 150px;
  margin-right: 10px;


}
</style>
