<template>
  <div class="table-box">
    <ProTable ref="proTable" :config="config" :api="getPlatformPage" :paramCallback="paramCallback" :selectdList="selectdList">
      <template #left_buttons>
        <!-- <el-button type="primary" :disabled="!selectdList || selectdList.length < 1" @click="pushCreditcard">新建信用卡</el-button> -->
        <el-button type="primary" @click="pushCredit">新建信用卡</el-button>
        <el-button
          type="primary"
          :disabled="!selectdList || selectdList.length < 1"
          @click="pushCreditcard"
          >新建网贷&信用贷</el-button
        >
        <el-button type="primary">发起风控审核</el-button>
      </template>
    </ProTable>
  </div>
</template>

<script setup lang="jsx" name="platformManage">
  import { ref, reactive, onMounted } from 'vue';
  import { Plus, Delete, Edit, Setting } from '@element-plus/icons-vue';
  import { getPlatformPage, deletePlatforms } from '@/api/platform';
  import { ElMessageBox, ElMessage, ElButton, ElTag } from 'element-plus';
  import { useRouter } from 'vue-router';

  const proTable = ref(null);
  const selectdList = ref([]);
  const onCheckboxChange = (row) => {
    selectdList.value = row.records;
  };
  const router = useRouter();

  const paramCallback = (param) => {
    const obj = JSON.parse(JSON.stringify(param));
    if (obj['createTime']) {
      if (obj['createTime'][0]) obj['createTimeBegin'] = obj['createTime'][0];
      if (obj['createTime'][1]) obj['createTimeEnd'] = obj['createTime'][1];
      delete obj['createTime'];
    }
    return obj;
  };
  const onCheckboxAll = (flag) => {
    if (flag.checked) {
      selectdList.value = flag.records;
    } else {
      selectdList.value = [];
    }
  };
  const pushCreditcard = () => {
    router.push({
      path: '/infoGather/customerGather/Creditcard',
      query: { id: 44 }, //这里不能直接写成 query: JSON.stringify(item)
    });
  };
  const pushCredit = () => {
    router.push({
      path: '/infoGather/customerGather/Credit',
      query: { id: 44 }, //这里不能直接写成 query: JSON.stringify(item)
    });
  };
  const config = reactive({
    onCheckboxChange: onCheckboxChange,
    onCheckboxAll: onCheckboxAll,
    columns: [
      { type: 'checkbox', width: 60,fixed: 'left' },
      { field: 'id', title: '客户ID' },
      {
        field: 'createTime',
        title: '创建日期',
        search: {
          el: 'date-picker',
          props: { type: 'daterange', valueFormat: 'YYYY-MM-DD' },
          span: 1.5,
        },
      },
      {
        field: 'createBy',
        title: '创建人',
        search: { el: 'input', span: 1, props: { clearable: true } },
      },
      { field: 'name', title: '客户名称', search: { el: 'input' } },
      { field: 'name', title: '身份证号', search: { el: 'input' } },
      { field: 'name', title: '手机', search: { el: 'input' } },
      { field: 'name', title: '电子邮箱', search: { el: 'input' } },
      { field: 'maxStagesNum', title: '预留工作单位', search: { el: 'input' } },
      { field: 'maxStagesNum', title: '预留家庭地址', search: { el: 'input' } },
      { field: 'remark', title: '备注', search: { el: 'input' } },
    ],
  });

  const query = () => proTable.value?.search();

  onMounted(() => {
    query();
  });
</script>
