Newer
Older
xc-business-system / src / views / resource / customer / reviewNotice / list.vue
tanyue on 20 Aug 2023 2 KB 20230820 合格供方名录
<!-- 检测结果复查通知列表 -->
<script name="ReviewNoticeList" lang="ts" setup>
import type { DateModelType } from 'element-plus'
import dayjs from 'dayjs'
import type{ IListQuery } from './customer-notice'
import type { TableColumn } from '@/components/NormalTable/table_interface'

const { proxy } = getCurrentInstance() as any
const router = useRouter()

// 查询条件
const searchQuery = ref<IListQuery>({
  noticeNo: '', // 委托方编号
  createUserName: '', // 委托方名字
  createTimeStart: '', // 创建时间-起始
  createTimeEnd: '', // 创建时间-结束
  offset: 1,
  limit: 20,
})
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading

// 表头
const columns = ref<TableColumn[]>([
  { text: '通知单编号', value: 'noticeNo', align: 'center', width: '175' },
  { text: '通知单名称', value: 'noticeName', align: 'center' },
  { text: '创建人', value: 'createUserName', align: 'center', width: '120' },
  { text: '创建时间', value: 'createTime', align: 'center', width: '160' },
])
const customerInfoList = ref<Array<ICustomerInfo>>([]) // 表格数据

const searchList = () => {
  fetchData(true)
}

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    searchQuery.value.offset = 1
  }
  getCustomerInfoList(searchQuery.value).then((response) => {
    if (response.code === 200) {
      customerInfoList.value = response.data.rows.map((item: { createTime: string }) => {
        return {
          ...item,
          createTime: item.createTime.length > 16 ? item.createTime.substring(0, 16) : '',
        }
      })

      total.value = parseInt(response.data.total)
    }
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}

watch(dateRange, (val) => {
  if (val) {
    searchQuery.value.createTimeStart = dayjs(val[0]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD')
    searchQuery.value.createTimeEnd = dayjs(val[1]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD')
  }
  else {
    searchQuery.value.createTimeStart = ''
    searchQuery.value.createTimeEnd = ''
  }
})

onMounted(async () => {
  searchList()
})
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <search-item>
        <el-input v-model="searchQuery.noticeNo" placeholder="通知单编号" clearable />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.createUserName" placeholder="创建人" clearable />
      </search-item>
      <search-item>
        <el-date-picker v-model="dateRange" type="daterange" start-placeholder="创建时间(开始)" end-placeholder="创建时间(结束)" />
      </search-item>
    </search-area>
  </app-container>
</template>