<template>
  <div class="mobile-container">
    <van-nav-bar right-text="搜索"
      left-arrow
      @click-left="clickBack"
      @click-right="showSearch = true"
      placeholder
      fixed />
    <!-- 计划列表 -->
    <van-pull-refresh v-model="refreshLoading"
      :pull-distance="100"
      success-text="刷新成功"
      @refresh="onRefresh">
      <van-list v-model:loading="loading"
        :finished="finished"
        :immediate-check="false"
        finished-text="没有更多了"
        @load="onLoad">
        <van-cell-group inset>
          <van-swipe-cell v-for="item in planList"
            :key="item.id">
            <van-cell :title="item.prdName + '\n料号: ' + item.prdCode">
              <template #label>
                <p>批号：{{ item.manufactureBatchNo }}</p>
                <p>厂家：{{ item.manufactureDate }}</p>
              </template>
              <template #value>

              </template>
            </van-cell>
          </van-swipe-cell>
        </van-cell-group>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script setup>
import { getQualityInsPageList } from '@/api'
const router = useRouter()

/*************** 导航栏 ***************/
const showSearch = ref(false)
const clickBack = () => {
  router.back()
}
/*************** 刷新+加载 ***************/
const refreshLoading = ref(false)
const onRefresh = async () => {
  refreshLoading.value = true
  await getPlanListFn()
  refreshLoading.value = false
}
// 加载更多
const loading = ref(false)
const finished = ref(false)

const onLoad = async () => {
  if (loading.value || finished.value) return
  loading.value = true
  await getPlanListFn()
  loading.value = false
}

/*************** 计划列表 ***************/
const query = reactive({
  pageNum: 1,
  pageSize: 10,
})
const planList = ref([])
const getPlanListFn = async () => {
  const res = await getQualityInsPageList(query)
  if (res.code === 200) {
    planList.value = res.data.rows || []
    finished.value = res.data.rows.length < res.data.pageSize
  }
}
getPlanListFn()


</script>

<style scoped
  lang="scss">
  ::v-deep(.van-cell__label) {
    margin: 0;
  }
</style>