<template>
    <TContainer>
        <TSearch
            v-model="queryParams.likeWork"
            placeholder="搜索客户姓名/手机号码"
            backgroundColor="#F5F5F5"
            showBorder
        />
        <u-tabs
            :list="tabs"
            :scrollable="false"
            :itemStyle="{ height: '44px', flex: 1 }"
            :activeStyle="{ color: '#0E66FB' }"
            lineWidth="49"
            lineColor="#0E66FB"
            @change="handleChangeTab"
        ></u-tabs>
        <view class="flex-1 pt-[24rpx] px-[24rpx] overflow-auto bg-[#F8F8F8]">
            <z-paging
                ref="paging"
                v-model="dataList"
                @query="queryList"
                :fixed="false"
                height="100%"
            >
                <clue-card
                    v-for="(item, index) in dataList"
                    :key="`${index} + 'unique'`"
                    :item="item"
                    @handle-update-remark="handleUpdateRemark"
                    @refresh-page="refresh"
                />
            </z-paging>
        </view>
    </TContainer>
    <w-confirm-popup v-model="popupShow" @confirm="handleConfirm">
        <template #content>
            <TTextareaField v-model="contentText" border="surround" :required="false" />
        </template>
    </w-confirm-popup>
</template>

<script setup lang="ts">
import { apiOverhaulPagelist } from '@/api/overhaul'
import { useZPaging } from '@/hooks/useZPaging'
import { ref } from 'vue'
import clueCard from '@/components/widgets/recruitsale/clue-card.vue'
import { shallowRef } from 'vue'
import { computed } from 'vue'
import { apiCluseList } from '@/api/clue'
import { converStatusEnum } from '@/enums'
import { onLoad } from '@dcloudio/uni-app'

const tabs = shallowRef([
    { name: '待领取', value: converStatusEnum.UN_RECEIVED },
    { name: '转化中', value: converStatusEnum.CONVERTED_PROCESS },
    { name: '已成交', value: converStatusEnum.CONVERTED },
    { name: '已战败', value: converStatusEnum.FAILED }
])
const activeTab = ref(converStatusEnum.UN_RECEIVED)
const queryParams = computed(() => {
    const payload = {
        situation: activeTab.value,
        likeWork: ''
    }
    return payload
})
const dataList = ref([])
const { paging, queryList, refresh, changeApi, setParams } = useZPaging(
    queryParams.value,
    apiCluseList,
    () => {}
)
const handleChangeTab = item => {
    activeTab.value = item.value
    refresh(queryParams.value)
}
const popupShow = ref(false)
const contentText = ref('')
const handleUpdateRemark = item => {
    const { id, remark } = item
    popupShow.value = true
    contentText.value = remark
}
const handleConfirm = () => {}
onLoad(() => {
    uni.$on('refreshPage', () => {
        refresh(queryParams.value)
    })
})
</script>
<style scoped></style>
