<template>
  <div class="app-container">
    <div class="container">
      <!-- 数据表格 -->
      <el-table :data="tableList"
        border
        style="width: 100%">
        <el-table-column v-for="item in columns"
          :key="item.label"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          :fixed="item.fixed"
          show-overflow-tooltip>
          <template #default="scope">
            <template v-if="item.prop === 'storePicture'">
              <!-- 如果是门头照字段，渲染图片 -->
              <el-image :preview-src-list="[scope.row[item.prop]]"
                preview-teleported
                :src="scope.row[item.prop]"
                alt="图片" />
            </template>
            <template v-else-if="item.prop === 'temWorkPhotos'">
              <el-image :preview-src-list="[item]"
                preview-teleported
                v-for="item in JSON.parse(scope.row[item.prop])"
                :src="item"
                alt="图片" />
            </template>
            <template v-else-if="item.prop === 'storeTcPhoto'">
              <el-image :preview-src-list="[scope.row[item.prop]]"
                preview-teleported
                :src="scope.row[item.prop]"
                alt="图片" />
            </template>
            <template v-else-if="item.prop === 'storeZhjPhoto'">
              <el-image :preview-src-list="[scope.row[item.prop]]"
                preview-teleported
                :src="scope.row[item.prop]"
                alt="图片" />
            </template>
            <template v-else-if="item.prop === 'posPhotos'">
              <el-image :preview-src-list="[item]"
                preview-teleported
                v-for="item in JSON.parse(scope.row[item.prop])"
                :src="item"
                alt="图片" />
            </template>
            <template v-else>
              <!-- 其他字段显示原始值 -->
              {{ formatter(scope.row, scope.column, scope.row[item.prop]) }}
            </template>
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作"
          width="200"
          fixed="right">
          <template #default="scope">
            <el-button type="danger"
              @click="deleteView(scope.row)"
              text>
              删除
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <!-- 分页 -->
      <pagination :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.pageSize"
        @pagination="getTaskList" />
    </div>
  </div>
</template>

<script setup>
import { getWarZoneListAPI, getChargeListAPI, getTaskListAPI, getProCityAPI, deletePromotionSystemAPI, getPromotionSystemAPI, getPromotionActivityAPI, getExamineList } from '@/api'
import { parseTime } from '@/utils'

const { proxy } = getCurrentInstance()

/********************  任务列表  ********************/
const queryParams = reactive({
  page: 1,
  pageSize: 10
})
const total = ref(0)
const tableList = ref([])
const columns = ref([
  {
    label: '稽核标识',
    prop: 'id',
    width: 80,
  },
  {
    label: '稽核人',
    prop: 'createBy',
    width: 100,
  },
  {
    label: '稽核人工号',
    prop: 'employeeNo',
    width: 100,
  },
  {
    label: 'cp活动 ID',
    prop: 'planId',
    width: 100
  },
  {
    label: '是否执行',
    prop: 'planStatus',
    width: 100
  },
  {
    label: '战区',
    prop: 'deptQcOrgName',
    width: 100
  },
  {
    label: '城市经理',
    prop: 'manageName',
    width: 120
  },
  {
    label: '城市',
    prop: 'city',
    width: 100
  },
  {
    label: '活动日期',
    prop: 'planDate',
    width: 150
  },
  {
    label: '系统名称',
    prop: 'lineName',
    width: 150
  },
  {
    label: '门店',
    prop: 'storeName',
    width: 210
  },
  {
    label: '经销商',
    prop: 'dealerName',
    width: 200
  },
  {
    label: '活动模式',
    prop: 'pattern',
    width: 100
  },
  {
    label: '稽核日期',
    prop: 'createDate',
    width: 120
  },
  {
    label: '门头照',
    prop: 'storePicture',
    width: 150
  },
  {
    label: '促销员人数',
    prop: 'temNum',
    width: 100
  },

  {
    label: '地堆',
    prop: 'storeDd',
    width: 80
  },
  {
    label: '促销员是否在岗',
    prop: 'temOnWork',
    width: 120
  },
  {
    label: '话术',
    prop: 'temHs',
    width: 80
  },
  {
    label: '物料',
    prop: 'temWl',
    width: 80
  },
  {
    label: '着装',
    prop: 'temZz',
    width: 80
  },
  {
    label: '工作取证照片',
    prop: 'temWorkPhotos',
    width: 250
  },
  {
    label: '特陈照',
    prop: 'storeTcPhoto',
    width: 150
  },
  {
    label: '主货架照',
    prop: 'storeZhjPhoto',
    width: 150
  },
  {
    label: 'POS 金额',
    prop: 'posRmb',
    width: 120
  },
  {
    label: 'POS 照片',
    prop: 'posPhotos',
    width: 250
  },
  {
    label: '创建人',
    prop: 'createBy',
    width: 120
  },
  {
    label: '创建时间',
    prop: 'createTime',
    width: 120
  },
  {
    label: '修改人',
    prop: 'modifyBy',
    width: 120
  },
  {
    label: '修改时间',
    prop: 'mobifyTime',
    width: 120
  }
])

// 获取稽核任务列表
const getTaskList = async () => {
  const { data: { records, totalRecord } } = await getExamineList(queryParams)
  tableList.value = records
  total.value = totalRecord
}
getTaskList()

const formatter = (row, columns, value) => {
  // 判断有值再转换
  if (columns.property === 'planDate' || columns.property === 'createDate' || columns.property === 'createTime' || columns.property === 'mobifyTime') {
    return parseTime(value, '{y}-{m}-{d}')
  } else {
    return value
  }
}
// 分页
const currentChange = (page) => {
  queryParams.page = page
  getTaskList()
}
</script>

<style scoped
  lang="scss">
  ::v-deep(.el-image) {
    img {
      width: 80px !important;
      height: 50px !important;
    }
  }


</style>
