<template>
  <app-view class="home-purchase">
    <template #header>
      <app-navbar class="home-purchase__header" title="采购" :show-back-button="false">
        <template #footer>
          <Search shape="round" placeholder="商品搜索" disabled />
        </template>
      </app-navbar>
    </template>
    <app-pull-refresh class="home-purchase__container" v-model:error="error" v-model:pageIndex="pageIndex"
      :page-count="pageCount" :updateList="dataList" @refresh="onRefresh">
      <template #default="{ item }">
        <Cell @click="$router.push({ name: 'goods-details', query: { wrstandardid: item.wrstandardid } })">
          <template #title>
            <img :src="getImageUrl(item.thumurls)" />
            <span>{{ item.wrstandardname }}</span>
          </template>
        </Cell>
      </template>
    </app-pull-refresh>
  </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { Cell, Search } from 'vant'
import { getImageUrl } from '@/filters'
import { useWrstandardList } from '@/business/goods'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'

const { dataList, pageIndex, pageCount, getWrstandardList } = useWrstandardList()
const error = shallowRef(false)

const onRefresh = (callback: () => void) => {
  getWrstandardList().catch(() => {
    error.value = true
  }).finally(() => callback())
}
</script>

<style lang="less">
@import './index.less';
</style>