<script setup>
import { userInfo } from '~/store/user'

const { uo_type, uo_name, user_id } = userInfo
const router = useRouter();
const isBureau = ref(false)// 当前用户是否局端
isBureau.value = uo_type === '1'
const list = ref([])
const loading = ref(false)
const finished = ref(false)
let page = 1
const param = $ref({
    hysyd_hyzt: '',
    hysyd_hymc: '',
    hysyd_chry_id: user_id
})
function onLoad() {
    loading.value = true
    request({
        url: '/jdbg/hy_hysyd/index',
        data: {
            page,
            limit: 20,
            ...param,
        },
    }).then((res) => {
        const data = res.data
        list.value = [...list.value, ...data.page_data]
        finished.value = data.total_page === page
        page++
        loading.value = false
    })
}
const searchValue = $ref('')
function onClickSearch() {
    reGetList()
}
const yearOption = $ref([{ text: '状态', value: '' }, { text: '未开始', value: '0' }, { text: '进行中', value: '1' }, { text: '已结束', value: '2' }])
const itemRef = ref(null)
function onConfirm() {
    itemRef.value.toggle()
    reGetList()
}
function dropItemChange() {
    reGetList()
}
function reGetList() {
    page = 1
    list.value = []
    finished.value = false
    onLoad()
}

function handleLinkTo(item) {
    router.push({ path: '/reserveMeetingRooms/detail', query: { hysyd_id: item.hysyd_id } })
}
</script>

<template>
    <div class="index">
        <van-search v-model="param.hysyd_hymc" :clearable="false" show-action placeholder="请输入搜索关键词"
            @search="onClickSearch">
            <template #action>
                <div @click="onClickSearch">
                    搜索
                </div>
            </template>
        </van-search>
        <van-dropdown-menu>
            <van-dropdown-item v-model="param.hysyd_hyzt" :options="yearOption" @change="dropItemChange" />
        </van-dropdown-menu>
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <van-cell v-for="item in list" :key="item" @click="handleLinkTo(item)">
                <template #title>
                    <span>{{ `${item.hysyd_hymc}\u00A0\u00A0\u00A0 ${item.hysyd_hys_mc}` }}</span>
                </template>
                <template #value>
                    <span style="color:black">状态：{{ item.hysyd_hyzt }}</span>
                </template>
                <template #label>
                    <span class="van-ellipsis">会议时间：{{ item.hysyd_hysj_ks }}-{{ item.hysyd_hysj_js }}</span>
                </template>
            </van-cell>
        </van-list>
    </div>
</template>

<style lang="scss" scoped>
:deep(.van-cell__title) {
    width: 70% !important;
    flex: auto
}

:deep(.van-cell__value) {
    width: 30% !important;
    flex: auto
}
</style>
