<template>
  <custom-layout class="main">
    <el-col :span="24" class="one">
      <el-image class="image" :src="lists" fit="fill" />
    </el-col>
    <div class="w_1300">
      <custom-search :cityList="cityList" :typeList="typeList" :plateList="plateList" :fields="fields" :searchFields="searchFields" @toSearchInfo="toSearchInfo"></custom-search>
      <div class="twoTwo">
        <div class="twoTable">
          <div class="label" v-for="(item, index) in column" :key="index" :style="item.style">
            {{ item.name }}
          </div>
        </div>
        <div class="twoValue">
          <div class="value" v-for="(item, index) in list" :key="index">
            <div class="table-colunm table-colunm1">{{ index + 1 || '暂无' }}</div>
            <div class="table-colunm table-colunm2">{{ item.name || '暂无' }}</div>
            <div class="table-colunm">{{ item.field || '暂无' }}</div>
            <div class="table-colunm">{{ item.time || '暂无' }}</div>
            <div class="table-colunm button" @click="toView(item)">查看详情</div>
          </div>
        </div>
        <div class="twoTotal">
          <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit" v-model:current-page="currentPage" @current-change="changePage" @size-change="sizeChange" />
        </div>
      </div>
    </div>
  </custom-layout>
</template>

<script setup>
// 图片引入
import lists from '/images/bg-xqk.jpg'
// 接口
import { SupportStore } from '@/store/api/platform/support'
import { RegionStore } from '@/store/api/system/region'
import { SectorStore } from '@/store/api/platform/sector'
import { DictDataStore } from '@/store/api/system/dictData'
const store = SupportStore()
const regionStore = RegionStore()
const sectorStore = SectorStore()
const dictDataStore = DictDataStore()
// 加载中
const loading = ref(false)
// 路由
const router = useRouter()
const cityList = ref([])
const typeList = ref([])
const plateList = ref([])
const column = ref([
  { name: '序号', style: { width: '240px' }, key: 'key' },
  { name: '公司名称', style: { width: '280px' }, key: 'name' },
  { name: '服务领域', style: { width: '260px' }, key: 'field' },
  { name: '登记时间', style: { width: '260px' }, key: 'time' },
  { name: '操作', style: { width: '260px' }, key: 'operation' }
])
const searchForm = ref({})
const list = ref([])
let skip = 0
let limit = 8
const total = ref(0)
const fields = ref([
  { model: 'name', label: '公司名称' },
  { model: 'tags', label: '标签名称' },
  { model: 'time', label: '登记时间' }
])
const searchFields = ref([
  { title: '行业', type: '1', list: plateList },
  { title: '技术领域', type: '2', list: typeList },
  { title: '所在地', type: '3', list: cityList }
])
// 请求
onMounted(async () => {
  loading.value = true
  await searchOther()
  await search({ skip, limit })
  loading.value = false
})
const searchOther = async () => {
  let res
  res = await regionStore.list({ level: 'city', parent_code: 22 })
  if (res.errcode == '0') cityList.value = res.data
  cityList.value.unshift({ id: '-1', code: '-1', name: '不限', is_active: true })
  res = await sectorStore.query({ is_use: '0' })
  if (res.errcode == '0') plateList.value = res.data
  plateList.value.unshift({ id: '-1', title: '不限', is_active: true })
  // 技术领域
  res = await dictDataStore.query({ code: 'field', is_use: '0' })
  if (res.errcode == '0') typeList.value = res.data
  typeList.value.unshift({ id: '-1', value: '-1', label: '不限', is_active: true })
}
const search = async (query = { skip, limit }) => {
  skip = query.skip
  limit = query.limit
  const info = { skip: query.skip, limit: query.limit, is_use: '0', status: '1', ...searchForm.value }
  const res = await store.list(info)
  if (res.errcode == '0') {
    list.value = res.data
    total.value = res.total
  }
}
// 搜索
const toSearchInfo = async (data) => {
  searchForm.value = data
  await search({ skip, limit })
}
// 查看详情
const toView = (item) => {
  router.push({ path: '/service/detail', query: { id: item.id || item._id } })
}
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 scoped lang="scss">
.main {
  background: url(/images/pingtai.jpg) no-repeat top center;
  background-size: 100% 100%;
  .one {
    .image {
      width: 100%;
      height: 350px;
    }
  }
  .two {
    margin: 10px 0;
    background-color: $global-color-fff;
  }
  .twoTwo {
    margin: 10px 0;
    .twoTable {
      display: flex;
      justify-content: space-between;
      color: $global-color-fff;
      font-size: $global-font-size-20;
      background-color: rgba(255, 255, 255, 0.1);
      padding: 12px 0;
      .label {
        text-align: center;
      }
    }
    .twoValue {
      color: $global-color-fff;
      font-size: $global-font-size-20;
      .value {
        display: flex;
        justify-content: space-between;
        padding: 12px 0;
        .table-colunm {
          width: 260px;
          text-align: center;
        }
        .table-colunm1 {
          width: 240px !important;
        }
        .table-colunm2 {
          width: 280px !important;
        }
        .button {
          cursor: pointer; /* 改变鼠标样式为手形 */
        }
        .button:hover {
          color: $global-color-107;
        }
      }
      .value:nth-child(2n) {
        background-color: rgba(255, 255, 255, 0.1);
      }
    }
    .twoTotal {
      display: flex;
      justify-content: center;
      margin: 20px 0;
    }
  }
}
</style>
