<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="用户UID：" label-width="100px" style="display: inline-block;">
              <el-input style="width: 350px" v-model="tableFrom.uid" placeholder="请输入用户UID" class="selWidth"></el-input>
            </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.user">
              <div class="user-avatar">
                <img :src="scope.row.user.avatar || moren" />
              </div>
              <div class="user-info">
                <div class="nickname">{{ scope.row.user.nickname }}</div>
                <div class="user-id">{{ scope.row.user.uid }}</div>
              </div>
            </div>
          </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="150">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image style="width: 36px; height: 36px" :src="scope.row.voucher_image" :preview-src-list="[scope.row.voucher_image]" />
            </div>
          </template>
        </el-table-column>
        <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>
          </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>
  </div>
</template>

<script>
import {promoterFormalExamine, promoterFormalList} from "@/api/promoter";

export default {
  name: "SupplierList",
  components: { },
  data() {
    return {
      listLoading: true,
      tableFrom: {
        page: 1,
        limit: 20,
        uid: ""
      },
      tableData: {
        data: [],
        total: 0
      },
    };
  },
  mounted() {
    this.getList("");
  },
  methods: {
    // 获取申请列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      promoterFormalList(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;
      promoterFormalExamine(params).then(res => {
        _this.$message.success(res.message);
        _this.getList();
      }).catch(res => {
        _this.$message.error(res.message);
      });
    },
  }
};
</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>
