<template>
  <div class="divBox">
    <!--主要内容-->
    <el-card class="box-card">
      <!--顶部搜索栏-->
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline size="small" label-width="80px">
            <el-form-item label="">
              <el-input v-model="tableFrom.uid" placeholder="请输入会员uid" clearable>
                <el-button slot="append" icon="el-icon-search" class="el-button-solt" @click="getList(1)"/>
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <!--表格信息-->
      <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini">
        <el-table-column label="ID" prop="id" min-width="80" align="center"/>
        <el-table-column label="用户信息" min-width="230" align="center">
          <template slot-scope="scope">
            <div class="user-content">
              <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="agent-type-text">
                  <el-tag type="info" effect="dark" size="small">{{ scope.row.user.uid }}</el-tag>
                  <el-tag type="success" effect="dark" size="small">{{ scope.row.role_type_text }}</el-tag>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="法大大相关信息" align="center">
          <el-table-column label="clientUserId" prop="client_user_id" min-width="200" align="center"/>
          <el-table-column label="是否授权" min-width="80" align="center">
            <template slot-scope="scope">
              {{ scope.row.available_status == 1 ? '已授权' : '未授权' }}
            </template>
          </el-table-column>
          <el-table-column label="是否实名" min-width="80" align="center">
            <template slot-scope="scope">
              {{ scope.row.id_ent_status == 1 ? '已认证' : '未认证' }}
            </template>
          </el-table-column>
          <el-table-column label="账号状态" min-width="80" align="center">
            <template slot-scope="scope">
              {{ scope.row.binding_status == 1 ? '正常' : '禁用' }}
            </template>
          </el-table-column>
          <el-table-column label="签署状态" min-width="80" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.sign_status == 1">已签署</span>
              <span v-else-if="scope.row.sign_status == 2">已拒签</span>
              <span v-else>待签署</span>
            </template>
          </el-table-column>
          <el-table-column label="合同信息" min-width="200" align="center">
            <template slot-scope="scope">
              {{ scope.row.sign_task_subject || ''}}<br />
              {{ scope.row.sign_template_id || ''}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" min-width="100" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button v-if="scope.row.binding_status == 1" type="text" size="small" @click="downloadContract(scope.row.id)">查看合同</el-button>
            <el-button v-if="scope.row.binding_status == 2" type="text" size="small" @click="lookRejectedReason(scope.row)">拒绝原因</el-button>
            <el-button v-if="scope.row.binding_status != 2 && Number(scope.row.sign_task_id) > 0 && scope.row.enterprise_status == 0" type="text" size="small" @click="signInfo(scope.row.id)">
              签署合同
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <div class="block">
        <el-pagination :page-size="tableFrom.limit" :current-page="tableFrom.page" :total="tableData.total" @current-change="pageChange" />
      </div>
    </el-card>

  </div>
</template>

<script>
import {contractDownload, contractList, contractSignInfo} from "@/api/marketing";

export default {
  name: "ContractList",
  components: {},
  data() {
    return {
      // 列表
      listLoading: false,
      tableFrom: {
        page: 1,
        limit: 20,
        uid: '',
      },
      tableData: {
        data: [],
        total: 0,
      },
    };
  },
  watch: {},
  mounted() {
    this.getList();
  },
  methods: {
    // 列表
    getList(num = ''){
      let _this = this;
      _this.listLoading = true;
      _this.tableFrom.page = num ? num : _this.tableFrom.page;
      contractList(_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('');
    },
    // 查看驳回原因
    lookRejectedReason(info){
      let msg = info.rejected_reason || '用户未填写拒绝原因！';

      this.$message.error(msg)
    },
    // 下载合同
    downloadContract(id){
      let _this = this;
      contractDownload(id).then((res) => {
        if(Number(res.status) === 200){
          let downloadUrl = res.data.downloadUrl || '';
          if(downloadUrl) window.open(downloadUrl, '_blank');
        }else{
          _this.$message.error(res.message);
        }
      }).catch((res) => {
        _this.$message.error(res.message);
      });
    },
    // 企业签署合同
    signInfo(id){
      let _this = this;
      contractSignInfo(id).then((res) => {
        if(Number(res.status) === 200){
          let actorSignTaskEmbedUrl = res.data.actorSignTaskEmbedUrl || '';
          if(actorSignTaskEmbedUrl) window.open(actorSignTaskEmbedUrl, '_blank');
        }else{
          _this.$message.error(res.message);
        }
      }).catch((res) => {
        _this.$message.error(res.message);
      });
    }


  }
};
</script>

<style scoped lang="scss">
/deep/ .el-select{
  width: 100% !important;
}
/deep/ .cell{
  padding: 0!important;
}
.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%));
    }
  }
}
</style>
