<template>
    <z-paging ref="paging" v-model="list" bgColor="#f7f7f7" @query="query" safe-area-inset-bottom>
        <template #top>
            <ut-navbar title="GAP基地信息" :fixed="false" border></ut-navbar>
            <view class="d-flex a-c pd-25">
                <view class="min-w-170 flex1">
                    <ut-action-sheet v-model="form.type" :tabs="tabs" @change="onRefresh" title="选择基地类型">
                        <view class="d-flex search-select-item a-c">
                            <view class="flex1 ov-hd f-s-28 c-333 text-center f-w-5 w-s-no">{{ '全部' }}</view>
                            <up-icon size="24rpx" color="#333" name="arrow-down-fill" class="mr-5"></up-icon>
                        </view>
                    </ut-action-sheet>
                </view>
                <view class="h-86 pl-20 w-100%">
                    <ut-search ref="searchRef" v-model="form.keywords" @search="onRefresh" margin="0" :border="false" :placeholder="placeholder" bgColor="#fff" height="86rpx" borderRadius="10rpx"></ut-search>
                </view>
            </view>
        </template>
        <template>
            <template>
                <view class="pl-25 pr-25">
                    <up-swipe-action>
                        <up-swipe-action-item v-for="item in list" :name="item?.id" :key="item?.id" :options="optionsAction" @click="clickSwipe" class="mb-20 b-radius">
                            <view class="b-radius bg-#fff pd-20 p-rtv">
                                <view class="c-#333 f-s-34 f-w-5 pb-5">{{ item?.gapBaseName }}</view>
                                <view class="c-#999 f-s-24 pb-20">{{ item?.ratedDate }}获评</view>
                                <view class="d-flex pb-5">
                                    <view class="w-50%">
                                        <text class="c-#666 f-s-28">种养殖品种:</text>
                                        <text class="c-#333 f-s-28 f-w-5">{{ item?.medicineName }}</text>
                                    </view>
                                    <view class="w-50%">
                                        <text class="c-#666 f-s-28">基地面积:</text>
                                        <text class="c-#333 f-s-28 f-w-5">{{ item?.area }}</text>
                                    </view>
                                </view>
                                <view class="pb-20">
                                    <text class="c-#666 f-s-28">基地地址:</text>
                                    <text class="c-#333 f-s-28 f-w-5">{{ item?.address }}</text>
                                </view>
                                <view v-if="+item?.res == 2" class="pl-5 pr-5 pt-20 pb-20 border-top-#f7f7f7 c-#FC333F">
                                    <text class="f-s-28">审核不通过原因:</text>
                                    <text class="f-s-28">{{ item?.msg }}</text>
                                </view>
                                <image v-if="+item?.res == 2" class="w-145" src="/static/images/plant/resFailed.png" style="position: absolute; top: 0; right: 0" mode="widthFix" />
                                <image v-if="+item?.res == 0" class="w-100" src="/static/images/plant/resPendingReview.png" style="position: absolute; top: 0; right: 0" mode="widthFix" />
                                <image v-if="+item?.res == 1" class="w-90" src="/static/images/plant/resEffective.png" style="position: absolute; top: 0; right: 0" mode="widthFix" />
                            </view>
                        </up-swipe-action-item>
                    </up-swipe-action>
                </view>
            </template>
            <!-- 空数据处理 -->

            <template #empty v-if="address">
                <ut-empty class="mg-at" size="28rpx" color="#999" padding="10rpx" image="/static/images/plant/noEmptyBase.png">暂无获评GAP基地信息~</ut-empty>
                <view class="d-flex j-c f-s-28 c-#ccc">如需认定GAP基地，可前往数字云药官网进行申报</view>
                <view class="d-flex j-c f-s-28 c-primary pd-15">https://www.shuziyunyao.com/</view>
                <up-button type="primary" class="b-radius" style="width: 340rpx" @click="copyText('https://www.shuziyunyao.com/')">复制网址</up-button>
            </template>
        </template>
        <template #empty v-if="!address">
            <ut-empty class="mg-at" size="28rpx" color="#999" padding="10rpx" image="/static/images/plant/noEmptyBase.png">非云南省内企业，无法获取已获评的GAP基地信息~</ut-empty>
            <view class="d-flex j-c f-s-28 c-#ccc">可点击底部按钮上传佐证材料添加获评信息</view>
        </template>
        <template #bottom v-if="!address">
            <view class="base-bottom-wrap pd-20 pb-0">
                <up-button type="primary" @click="$u.route({ url: '/plant/base/gap-base-info-edit/index' })">
                    <img class="w-38 h-36 mr-10" src="/static/images/plant/chooseGAP.png" alt="" mode="widthFix" />
                    <text>添加GAP基地信息</text>
                </up-button>
            </view>
        </template>
    </z-paging>
</template>
<script setup lang="ts">
import { copyText } from '@/utils/public';
import { useClientRequest } from '@/utils/request';
import { useInfoStore } from '@/store';
interface ListItem {
    rows: MedicineBase[];
    code: number;
    msg: string;
    total: number;
}
interface MedicineBase {
    id: number;
    sourceType: string;
    gapBaseName: string;
    sn: string;
    medicineName: string;
    medicineId: number;
    area: number;
    basePic: string;
    lng: number;
    lat: number;
    adcode: string;
    address: string;
    ratedDate: string;
    certFile: Array<{
        fileName: string;
        url: string;
        fileSize: number;
    }>;
    res: string; // 0-待审核 1-通过 2-审核不通过
    auditor: number;
    msg: string;
    coordinates: Array<
        Array<{
            lng: number;
            lat: number;
        }>
    >;
}
const paging = ref();
const list = ref<MedicineBase[]>([]);
const placeholder = ref('搜基地名称、品种、基地地址');
const tabs = ref([
    { label: '全部', value: '' },
    { label: '有效', value: '0' },
    { label: '审核不通过', value: '1' },
    { label: '待审核', value: '2' },
]);
// 判断是否是云南的企业
const isYunnanCompany = (): boolean => {
    const adcdCode = useInfoStore().companyInfo?.adcdCode;
    return adcdCode?.startsWith('53') || false;
};
const address = computed(() => isYunnanCompany());
const form = ref({
    keywords: '',
    type: '',
});
const query = async (pageNum: number, pageSize: number) => {
    const params = {
        pageNum,
        pageSize,
        ...form.value,
    };
    // const res = await cpyList(params);
    ///app/gapCertificationInfo/pageList
    const res = await useClientRequest.get<ListItem>('/plt-api/app/gapCertificationInfo/pageList', params);
    const { rows } = res;
    paging.value.complete(rows);
};
const onRefresh = () => {
    paging.value.reload();
};
// 处理地块数据
const showAction = ref(false);
const optionsAction = reactive([
    {
        text: '删除',
        style: {
            backgroundColor: '#f56c6c',
        },
    },
]);
const clickSwipe = (index: object) => {
    console.log(index);
};
</script>
<style lang="scss" scoped>
// @import '@/assets/styles/theme.scss';
.search-select-item {
    height: 86rpx;
    background-color: #fff;
    border-radius: 10rpx;
    box-sizing: border-box;
    padding-left: 16rpx;
    padding-right: 16rpx;
    padding-top: 14rpx;
    padding-bottom: 14rpx;
}
.u-page {
    padding: 0;
}

.u-demo-block__title {
    padding: 10px 0 2px 15px;
}

.swipe-action {
    &__content {
        padding: 25rpx 0;

        &__text {
            font-size: 15px;
            color: $u-main-color;
            padding-left: 30rpx;
        }
    }
}
</style>
