<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight">
        <div class="w_1200">
          <el-col :span="24" class="one">
            <el-col
              :span="24"
              class="list"
              v-for="(item, index) in list"
              :key="index"
              @click="toView(item)"
            >
              <el-col :span="24" class="name">
                <el-tooltip effect="dark" :content="item.name" placement="top">
                  {{ item.name || '暂无姓名' }}
                </el-tooltip>
              </el-col>
              <el-row class="other">
                <el-col :span="8" class="other_1">
                  <span>手机号：</span>
                  {{ item.phone || '暂无' }}
                </el-col>
                <el-col :span="8" class="other_1">
                  <span>证件类型：</span>
                  {{ getDict(item.cardType, 'cardType') }}
                </el-col>
                <el-col :span="8" class="other_1">
                  <span>证件号码：</span>
                  {{ item.card || '暂无' }}
                </el-col>
              </el-row>
              <el-col :span="24" class="brief textOver">
                {{ item.remark || '没有更多备注' }}
              </el-col>
            </el-col>
          </el-col>
          <el-col :span="24" class="two">
            <el-pagination
              background
              layout="total, prev, pager, next"
              :page-sizes="[10, 20, 50, 100, 200]"
              :total="total"
              :page-size="limit"
              v-model:current-page="currentPage"
              @current-change="changePage"
              @size-change="sizeChange"
            >
            </el-pagination>
          </el-col>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { get } from 'lodash-es'
const $checkRes = inject('$checkRes')
import { UserStore } from '@/store/user'
const userStore = UserStore()
const user = computed(() => userStore.user)
// 接口
import { SignStore } from '@/store/api/platform/sign'
import { DictDataStore } from '@/store/api/system/dictData'
const store = SignStore()
const dictDataStore = DictDataStore()
// 路由
const router = useRouter()
// 加载中
const loading = ref(false)
// 列表
const list = ref([])
let skip = 0
let limit = inject('limit')
const total = ref(0)
// 字典表
const cardTypeList = ref([])
// 查看
const toView = (item) => {
  router.push({ path: '/innovation/detail', query: { id: item.match } })
}
// 请求
onMounted(async () => {
  loading.value = true
  await searchOther()
  await search({ skip, limit })
  loading.value = false
})
const searchOther = async () => {
  let result
  // 证件类型
  result = await dictDataStore.query({ code: 'cardType', is_use: '0' })
  if ($checkRes(result)) cardTypeList.value = result.data
}
const search = async (query = { skip: 0, limit }) => {
  const info = {
    skip: query.skip,
    limit: query.limit,
    user: user.value._id
  }
  const res = await store.query(info)
  if (res.errcode == '0') {
    list.value = res.data
    total.value = res.total
  }
}
// 字典数据转换
const getDict = (data, model) => {
  let res
  if (model == 'cardType') res = cardTypeList.value.find((f) => f.value == data)
  return get(res, 'label')
}
const currentPage = ref(1)
// 分页
const changePage = (page = currentPage.value) => {
  search({ skip: (page - 1) * limit, limit: limit })
}
const sizeChange = (limits) => {
  limit = limits
  currentPage.value = 1
  search({ skip: 0, limit: limit })
}
</script>
<style lang="scss" scoped>
.main {
  background: rgb(248, 248, 248);
  .one {
    margin-top: 20px;
    background: #ffffff;
    border-radius: 10px;
    padding: 15px;

    .list {
      margin-bottom: 10px;
      border-bottom: 1px solid #ebebeb;
      padding-bottom: 10px;

      .name {
        color: #337ab7;
        font-size: 18px;
        font-weight: bold;
        display: inline-block;
        margin: 10px 0;
      }

      .name:hover {
        color: #2374ff;
      }

      .other {
        padding: 5px 0;

        .other_1 {
          font-family: 'PingFangSC-Light', 'Microsoft YaHei', 'WenQuanYi Micro Hei', arial,
            sans-serif;
          font-size: 12px;
          font-weight: normal;
        }

        .other_1:hover {
          color: #2374ff;
        }
      }

      .brief {
        line-height: 30px;
        color: #666;
        font-size: 14px;
      }
    }
  }

  .two {
    display: flex;
    flex-direction: row-reverse;
    padding: 20px;
  }
}
</style>
