<template>
  <div class="divBox">
    <el-card class="box-card">
      <!--表格信息-->
      <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini">
        <el-table-column prop="id" label="ID" min-width="50" align="center"/>
        <el-table-column label="申请用户" min-width="200" 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="user-id">ID：{{ scope.row.user.uid }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="运营中心身份" min-width="200" align="center">
          <template slot-scope="scope">
            <div class="user-content" v-if="scope.row.payRecord.agent">
              {{ scope.row.payRecord.agent.agent_type_text || '' }}<br />
              {{ scope.row.payRecord.agent.id ? 'ID：' + scope.row.payRecord.agent.id : '' }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="缴费类型" min-width="100" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.payRecord.pay_type == 1">定金</el-tag>
            <el-tag v-else-if="scope.row.payRecord.pay_type == 2">尾款</el-tag>
            <el-tag v-else-if="scope.row.payRecord.pay_type == 3">保证金</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="缴费金额" prop="payRecord.money" min-width="100" align="center"/>
        <el-table-column label="状态" min-width="100" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0" type="info">待审核</el-tag>
            <el-tag v-else-if="scope.row.status == 1" type="success">已退款</el-tag>
            <el-tag v-else-if="scope.row.status == 2" type="warning">已驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="申请时间" prop="apply_time" min-width="150" align="center"/>
        <el-table-column label="操作" min-width="150" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button v-if="Number(scope.row.status) === 0" type="text" size="small" class="mr10" @click="examinePass(scope.row)">通过</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 {agentPayRecordRefund, agentPayRecordRefundExamine} from '@/api/marketing'
export default {
  name: "preSaleProductList",
  components: { },
  data() {
    return {
      moren: require("@/assets/images/f.png"),
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      tableFrom: {
        page: 1,
        limit: 20
      },
    };
  },
  watch: {},
  mounted() {
    this.getList(1);
  },
  methods: {
    // 获取列表
    getList(num) {
      let _this = this;
      _this.listLoading = true;
      _this.tableFrom.page = num ? num : this.tableFrom.page;
      agentPayRecordRefund(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('');
    },
    // 审核
    examinePass(row, status = 1){
      let _this = this;
      let params = {
        id: row.id,
        status: status,
      };
      agentPayRecordRefundExamine(params).then((res) => {
        if(Number(res.status) === 200){
          _this.getList('');
        }else{
          _this.$message.error(res.message);
        }
      }).catch((res) => {
        _this.$message.error(res.message);
      });
    }




  },
};
</script>

<style scoped lang="scss">
/deep/ .el-table .cell{
  padding: 0!important;
}
.selWidth{
  margin-bottom: 10px!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: center;
  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{
    height: var(--user-content-height-);
    display: inline-flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: flex-start;
    .nickname{
      font-size: 15px;
      font-weight: bold;
      line-height: calc(var(--user-content-height- * 65%));
    }
    .user-id{
      font-size: 13px;
      line-height: calc(var(--user-content-height- * 35%));
    }
  }
}
</style>
