index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <app-view class="contract">
  3. <template #header>
  4. <app-navbar class="contract__header" title="合同转让">
  5. <template #footer>
  6. <Search shape="round" placeholder="商品搜索" v-model="keyword" @search="pullRefreshRef.refresh()" />
  7. </template>
  8. </app-navbar>
  9. </template>
  10. <app-pull-refresh ref="pullRefreshRef" class="contract__container" v-model:loading="loading" v-model:error="error"
  11. v-model:pageIndex="pageIndex" :page-count="pageCount" @refresh="onRefresh">
  12. <ul class="list">
  13. <li class="list-item g-block--bg" v-for="(item, index) in dataList" :key="index">
  14. <div class="block">
  15. <img :src="getFirstImage(item.thumurls)" />
  16. <span>{{ item.wrstandardname }}</span>
  17. </div>
  18. <div class="block">
  19. <Button type="primary" size="small" round
  20. @click="$router.push({ name: 'contract-details', query: { wrstandardid: item.wrstandardid } })">查看详情</Button>
  21. </div>
  22. </li>
  23. </ul>
  24. </app-pull-refresh>
  25. </app-view>
  26. </template>
  27. <script lang="ts" setup>
  28. import { shallowRef, onActivated } from 'vue'
  29. import { Search, Button } from 'vant'
  30. import { getFileUrl } from '@/filters'
  31. import { useRequest } from '@/hooks/request'
  32. import { queryTHJPurchaseTransfer } from '@/services/api/contract'
  33. import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
  34. const dataList = shallowRef<Model.THJPurchaseTransferRsp[]>([])
  35. const error = shallowRef(false)
  36. const pullRefreshRef = shallowRef()
  37. const keyword = shallowRef('')
  38. const { loading, pageIndex, pageCount, run } = useRequest(queryTHJPurchaseTransfer, {
  39. manual: true,
  40. params: {
  41. pagesize: 20,
  42. },
  43. onSuccess: (res) => {
  44. if (pageIndex.value === 1) {
  45. dataList.value = []
  46. }
  47. dataList.value.push(...res.data)
  48. },
  49. onError: () => {
  50. error.value = true
  51. }
  52. })
  53. // 获取产品首图
  54. const getFirstImage = (url: string) => {
  55. const images = url.split(',').map((path) => getFileUrl(path))
  56. return images[0] ?? ''
  57. }
  58. const onRefresh = () => {
  59. run({ wrstandardname: keyword.value })
  60. }
  61. onActivated(() => {
  62. pullRefreshRef.value?.refresh()
  63. })
  64. </script>
  65. <style lang="less">
  66. @import './index.less';
  67. </style>