<script setup lang="ts" name="SectionList">
import { ref, onMounted, reactive, watchEffect, nextTick } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useDict } from '@/common/utils/dict'
import PullList from '../../components/List/PullList.vue'
import DishCard from './modules/dishCard.vue'
import { tAmRetentionSampleMobileList, delTAmRetentionSample } from '@/api/resturant/dishSample.ts'
// import { showSuccessToast } from 'vant'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()

const router = useRouter()

const route = useRoute()
const pullListRef = ref<InstanceType<typeof PullList>>()

const queryParams:any = ref({
  pageNum: 1,
  pageSize: 10,
  createBy: userStore.userInfo.userId
})


// 请求方法，传入PullList组件，需返回{rows: [], total: number}
function onRequest(query?: any, isRefresh?: boolean): Promise<{rows: any[], total: number}> {
  return tAmRetentionSampleMobileList(query)
}
/**
 * 新增餐品留样
 */
function onClickAdd():void {
  router.push({
    path: '/resturant/dishSample',
    query: {
      type: 'add'
    }
  })
}

/**
 * 餐品留样详情
 */
function handleDetail(item:any):void {
  router.push({
    path: '/resturant/dishSample',
    query: {
      sampleId: item.id,
      type: 'detail'
    }
  })
}


/**
 * 修改餐品留样
 */
function handleUpdate(item:any):void {
  router.push({
    path: '/resturant/dishSample',
    query: {
      sampleId: item.id,
      type: 'update'
    }
  })
}

/**
 * 删除餐品留样
 */
function handleDelete(item):void {
  delTAmRetentionSample(item.id).then(res => {
    console.log(res)
    showSuccessToast('删除成功')
    pullListRef.value?.refresh()
  })
}


</script>

<template>
  <div class="container full">


    <!-- </div> -->
    <PullList ref="pullListRef" v-model:query-string="queryParams" :request-method="onRequest">
      <template #default="{ item, index }">
        <DishCard
          class="discard-container"
          :item="item"
          @handle-delete="handleDelete"
          @handle-detail="handleDetail"
          @handle-update="handleUpdate"/>
      </template>
    </PullList>
    <van-floating-bubble
      axis="xy"
      icon="plus"
      magnetic="x"
      @click="onClickAdd"
    />

  </div>
</template>

<style lang="less" scoped>
.discard-container {
  margin-top: 1.2rem;
  &:first-child{
    margin-top: 0;
  }
}
</style>
