<script setup lang="ts">
    import { nextTick, reactive, ref } from 'vue'
    import { onLoad, onNavigationBarButtonTap, onShow } from '@dcloudio/uni-app'
    import * as NongchangAPI from '@/api/model/nongchang'

    const isOnePage = ref(true)
    const paging = ref(null)
    const pageData = reactive({
        param: {
            pageNo: 1,
            pageSize: 10,
            baseName: '',
        },
        list: [],
        total: 0, // 基地总数
        type_success_total: 0, // 已认证
        type_unverified_total: 0, // 未认证
    })
    onNavigationBarButtonTap((e) => {
        console.log('onNavigationBarButtonTap', e)
    })
    onLoad(() => {})
    onShow(() => {
        nextTick(() => {
            if (!isOnePage.value && paging.value) {
                paging.value.reload()
            }

            isOnePage.value = false
        })
    })
    function getList() {
        if (!paging.value) 
return
        NongchangAPI.getFarmbaseList(pageData.param)
            .then((res) => {
                pageData.total = res.total
                paging.value.complete(res.records)
            })
            .catch(() => {
                paging.value.complete(false)
            })
    }
    onNavigationBarButtonTap((_) => {
        uni.navigateTo({
            url: './add',
        })
    })
    function queryList(pageNo, pageSize) {
        pageData.param.pageNo = pageNo
        pageData.param.pageSize = pageSize
        getList()
    }

    function handleSearch() {
        // 重置页码为1，重新搜索
        pageData.param.pageNo = 1
        if (paging.value) {
            paging.value.reload()
        }
    }
    function goDetail(id) {
        uni.navigateTo({
            url: `./add?id=${id}`,
        })
    }
    function del(id) {
        uni.showModal({
            title: '提示',
            content: '确定删除吗？',
            success: (res) => {
                if (res.confirm) {
                    NongchangAPI.delFarmbase(id).then(() => {
                        uni.showToast({
                            title: '删除成功',
                            icon: 'none',
                        })
                        if (paging.value) {
                            paging.value.reload()
                        }
                    })
                }
            },
        })
    }
</script>

<template>
    <view class="codefun-flex-col page">
        <z-paging ref="paging" v-model="pageData.list" @query="queryList">
            <view class="codefun-flex-col group_3">
                <view class="codefun-flex-row codefun-items-center section_2">
                    <image class="image_6" src="/static/images/codefun/6c5c5a3c082b8c60a307d3a7caee623c.png" />
                    <u-input
                        v-model="pageData.param.baseName"
                        placeholder="请输入搜索内容"
                        border="none"
                        class="codefun-ml-8"
                        @confirm="handleSearch"
                    />
                </view>
                <view class="codefun-mt-12 codefun-flex-col section_3">
                    <view class="codefun-flex-row codefun-justify-between group_4">
                        <view class="codefun-flex-row codefun-self-start">
                            <image
                                class="codefun-shrink-0 image_7"
                                src="/static/images/codefun/db26a8ae3f4d5f1e0a3f11d8fb5bc491.png"
                            />
                            <view
                                class="codefun-flex-col codefun-items-start codefun-shrink-0 codefun-self-center group_7"
                            >
                                <text class="text_5">{{ pageData.total }}</text>
                                <text class="font_4 text_7 mt-5">总基地数</text>
                            </view>
                            <text class="codefun-self-start font_4 text_4">个</text>
                        </view>
                        <view class="codefun-flex-col codefun-self-center group_5">
                            <view class="codefun-flex-row codefun-items-center group_6">
                                <image
                                    class="image_6"
                                    src="/static/images/codefun/118c884c539aaba710313f0682db00e1.png"
                                />
                                <view
                                    class="codefun-ml-4 codefun-flex-col codefun-justify-start codefun-items-center text-wrapper"
                                >
                                    <text class="font_3 text_6">已认证：</text>
                                </view>
                                <view
                                    class="codefun-ml-4 codefun-flex-col codefun-justify-start codefun-items-center text-wrapper_2"
                                >
                                    <text class="font_5">{{ pageData.type_success_total }}个</text>
                                </view>
                            </view>
                            <view class="codefun-flex-row codefun-items-center group_8">
                                <image
                                    class="image_6"
                                    src="/static/images/codefun/27ef797870c2085d1a14446c50cf53e0.png"
                                />
                                <view
                                    class="codefun-ml-4 codefun-flex-col codefun-justify-start codefun-items-center text-wrapper"
                                >
                                    <text class="font_3 text_6">待认证：</text>
                                </view>
                                <view
                                    class="codefun-ml-4 codefun-flex-col codefun-justify-start codefun-items-center text-wrapper_3"
                                >
                                    <text class="font_3 text_8">{{ pageData.type_unverified_total }}个</text>
                                </view>
                            </view>
                        </view>
                    </view>
                    <view class="codefun-flex-row codefun-justify-between codefun-items-center group_9">
                        <view class="codefun-flex-row">
                            <image class="image_8" src="/static/images/codefun/c24e87154a833caadfcb70fb24ae52dc.png" />
                            <view
                                class="codefun-ml-4 codefun-flex-col codefun-justify-start codefun-items-start text-wrapper_4"
                            >
                                <text class="font_5">基地认证指南</text>
                            </view>
                        </view>
                        <image class="image_9" src="/static/images/codefun/7e185c6d21ed1b0d04422b2d3835fce8.png" />
                    </view>
                </view>
                <view class="codefun-mt-12 codefun-flex-col section_4" v-if="pageData.list.length">
                    <view class="codefun-flex-col codefun-self-stretch list">
                        <view
                            class="codefun-flex-row codefun-items-center list-item"
                            v-for="(item, index) in pageData.list"
                            :key="index"
                        >
                            <view class="codefun-flex-col codefun-justify-start codefun-items-start section_5">
                                <view
                                    class="codefun-flex-col codefun-justify-start codefun-items-center text-wrapper_5"
                                >
                                    <text class="font_6">{{ item.auditStatus_dictText }}</text>
                                </view>
                            </view>
                            <view class="codefun-flex-col codefun-flex-1 group_10 ml-13">
                                <view class="codefun-flex-col">
                                    <text class="codefun-self-start font">{{ item.baseName }}</text>
                                    <view class="codefun-flex-row codefun-self-stretch mt-11">
                                        <text class="font_4 text_9">类型：{{ item.baseType_dictText }}</text>
                                        <text class="font_4 text_10 ml-13">规模：{{ item.scale }} 亩</text>
                                    </view>
                                </view>
                                <view
                                    class="codefun-mt-18 codefun-flex-row codefun-justify-between codefun-items-center group_11"
                                >
                                    <view class="codefun-flex-row" @click="goDetail(item.id)">
                                        <image
                                            class="image_10"
                                            src="/static/images/codefun/3566724e23f8a91e60ae87c2744e4090.png"
                                        />
                                        <view
                                            class="codefun-ml-4 codefun-flex-col codefun-justify-start codefun-items-center text-wrapper_6"
                                        >
                                            <text class="font_7 text_11">详情</text>
                                        </view>
                                    </view>
                                    <view class="codefun-flex-row codefun-items-center" @click="del(item.id)">
                                        <image
                                            class="codefun-shrink-0 image_10"
                                            src="/static/images/codefun/8630d19ebb6334e2028daa7d7b8b5983.png"
                                        />
                                        <text class="font_8 ml-5">删除</text>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </z-paging>
    </view>
</template>

<style scoped lang="scss">
    body {
        background-color: #e6f5e8;
    }

    .mt-5 {
        margin-top: 10rpx;
    }

    .mt-11 {
        margin-top: 22rpx;
    }

    .ml-5 {
        margin-left: 10rpx;
    }

    .ml-13 {
        margin-left: 26rpx;
    }

    .ml-9 {
        margin-left: 18rpx;
    }

    .page {
        background-color: #e6f5e8;
        mix-blend-mode: NOTTHROUGH;
        width: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        height: 100%;

        .section {
            padding: 32rpx 24rpx 32rpx 36rpx;
            background-color: #5db66f;
            mix-blend-mode: NOTTHROUGH;

            .image {
                border-radius: 64rpx;
                width: 108rpx;
                height: 42rpx;
            }

            .group {
                margin-right: 4rpx;

                .image_2 {
                    mix-blend-mode: NOTTHROUGH;
                    width: 34rpx;
                    height: 22rpx;
                }

                .image_3 {
                    mix-blend-mode: NOTTHROUGH;
                    width: 30rpx;
                    height: 22rpx;
                }

                .image_4 {
                    width: 48rpx;
                    height: 22rpx;
                }
            }

            .group_2 {
                padding-left: 6rpx;

                .image_5 {
                    mix-blend-mode: NOTTHROUGH;
                    width: 14rpx;
                    height: 26rpx;
                }

                .pos {
                    position: absolute;
                    left: 6rpx;
                    top: 50%;
                    transform: translateY(-50%);
                }

                .text {
                    color: #ffffffe6;
                    line-height: 29.6rpx;
                }

                .pos_2 {
                    position: absolute;
                    right: 0;
                    top: 50%;
                    transform: translateY(-50%);

                    .text_2 {
                        line-height: 25.78rpx;
                    }
                }
            }
        }

        .group_3 {
            padding: 28rpx 24rpx 58rpx;

            .section_2 {
                padding: 16rpx 20rpx;
                background-color: #ffffff;
                border-radius: 1998rpx;
                mix-blend-mode: NOTTHROUGH;

                .text_3 {
                    color: #cccccc;
                    line-height: 26.02rpx;
                }
            }

            .section_3 {
                padding: 0 24rpx;
                background-color: #ffffff;
                border-radius: 18.46rpx;
                mix-blend-mode: NOTTHROUGH;

                .group_4 {
                    padding: 42rpx 4rpx 30rpx 22rpx;
                    border-bottom: solid 2rpx #eeeeee;

                    .image_7 {
                        width: 100rpx;
                        height: 86rpx;
                    }

                    .group_7 {
                        margin-left: 32rpx;

                        .text_5 {
                            color: #5db66f;
                            font-size: 40rpx;
                            font-family: SourceHanSansCN;
                            line-height: 40rpx;
                        }

                        .text_7 {
                            line-height: 22.18rpx;
                        }
                    }

                    .text_4 {
                        color: #333333;
                        line-height: 40rpx;
                    }

                    .group_5 {
                        width: 219.94rpx;

                        .group_6 {
                            overflow: hidden;

                            .text-wrapper_2 {
                                padding: 8rpx 0 4rpx;
                                overflow: hidden;
                                width: 60rpx;
                                height: 40rpx;
                            }
                        }

                        .group_8 {
                            padding-top: 16rpx;

                            .text-wrapper_3 {
                                padding: 8rpx 0 4rpx;
                                overflow: hidden;
                                width: 60rpx;
                                height: 40rpx;

                                .text_8 {
                                    color: #ff9800;
                                }
                            }
                        }

                        .text-wrapper {
                            padding: 8rpx 0 4rpx;
                            overflow: hidden;
                            width: 112rpx;
                            height: 40rpx;

                            .text_6 {
                                line-height: 25.74rpx;
                            }
                        }
                    }
                }

                .group_9 {
                    padding: 12rpx 4rpx;

                    .image_8 {
                        margin: 4rpx 0;
                        width: 40rpx;
                        height: 40rpx;
                    }

                    .text-wrapper_4 {
                        padding: 12rpx 0;
                        overflow: hidden;
                        width: 168rpx;
                        height: 48rpx;
                    }

                    .image_9 {
                        margin-right: 12rpx;
                        width: 16rpx;
                        height: 26rpx;
                    }
                }

                .font_5 {
                    font-size: 28rpx;
                    font-family: SourceHanSansCN;
                    line-height: 25.76rpx;
                    color: #5db66f;
                }
            }

            .font_3 {
                font-size: 28rpx;
                font-family: SourceHanSansCN;
                line-height: 25.76rpx;
                color: #1f2937;
            }

            .section_4 {
                padding-left: 6rpx;
                padding-bottom: 26rpx;
                background-color: #ffffff;
                border-radius: 26.28rpx;
                mix-blend-mode: NOTTHROUGH;

                .list {
                    margin-left: 18rpx;
                    margin-right: 24rpx;

                    .list-item {
                        padding: 24rpx 0;
                        border-bottom: solid 2rpx #eeeeee;

                        .section_5 {
                            padding: 12rpx 0 116rpx;
                            background-image: url('/static/images/codefun/4be80e2618f3c4b4aa1ce64fd9063abf.png');
                            background-size: 100% 100%;
                            background-repeat: no-repeat;
                            width: 160rpx;
                            height: 160rpx;

                            .text-wrapper_5 {
                                padding: 8rpx 0;
                                background-image: linear-gradient(90deg, #43cf7c 0%, #5db66f 100%);
                                border-radius: 0rpx 8rpx 8rpx 0rpx;
                                mix-blend-mode: NOTTHROUGH;
                                width: 84rpx;

                                .font_6 {
                                    font-size: 20rpx;
                                    font-family: SourceHanSansCN;
                                    line-height: 18.38rpx;
                                    color: #ffffff;
                                }
                            }
                        }

                        .group_10 {
                            margin-right: 40rpx;

                            .text_9 {
                                line-height: 22.34rpx;
                            }

                            .text_10 {
                                line-height: 22.22rpx;
                            }

                            .group_11 {
                                padding-left: 64rpx;

                                .image_10 {
                                    width: 28rpx;
                                    height: 28rpx;
                                }

                                .text-wrapper_6 {
                                    padding-top: 8rpx;
                                    overflow: hidden;
                                    width: 48rpx;
                                    height: 32rpx;

                                    .text_11 {
                                        line-height: 22.12rpx;
                                    }
                                }

                                .font_8 {
                                    font-size: 24rpx;
                                    font-family: SourceHanSansCN;
                                    line-height: 22.28rpx;
                                    color: #f44336;
                                }
                            }
                        }
                    }
                }

                .group_14 {
                    margin: 18rpx 24rpx 0;

                    .text_14 {
                        line-height: 26.12rpx;
                    }

                    .text-wrapper_8 {
                        padding: 4rpx 0;
                        overflow: hidden;
                        width: 48rpx;
                        height: 32rpx;

                        .text_15 {
                            line-height: 22.2rpx;
                        }
                    }
                }

                .font_7 {
                    font-size: 24rpx;
                    font-family: SourceHanSansCN;
                    line-height: 22.28rpx;
                    color: #5db66f;
                }

                .group_15 {
                    margin-left: 24rpx;
                    margin-top: 28rpx;
                    width: 528.18rpx;

                    .text_16 {
                        line-height: 25.12rpx;
                    }

                    .text_17 {
                        line-height: 26.26rpx;
                    }
                }

                .group_16 {
                    margin-left: 24rpx;
                    margin-top: 28rpx;
                    width: 216.94rpx;

                    .text_18 {
                        line-height: 25.82rpx;
                    }

                    .text_19 {
                        line-height: 25.34rpx;
                    }
                }

                .font_9 {
                    font-size: 28rpx;
                    font-family: SourceHanSansCN;
                    line-height: 25.76rpx;
                    color: #6b7280;
                }

                .group_17 {
                    margin-left: 24rpx;
                    margin-top: 28rpx;

                    .text_20 {
                        line-height: 26.16rpx;
                    }

                    .text_21 {
                        line-height: 22.66rpx;
                    }
                }

                .divider {
                    margin: 28rpx 18rpx 0 24rpx;
                    background-color: #f3f4f6;
                    height: 2rpx;
                }

                .text_22 {
                    margin-left: 24rpx;
                    margin-top: 32rpx;
                    line-height: 26.12rpx;
                }

                .group_18 {
                    margin-left: 24rpx;
                    margin-top: 32rpx;

                    .text_23 {
                        line-height: 26.06rpx;
                    }

                    .text_24 {
                        line-height: 22.66rpx;
                    }
                }

                .font_10 {
                    font-size: 28rpx;
                    font-family: SourceHanSansCN;
                    line-height: 22.28rpx;
                    color: #1f2937;
                }

                .group_19 {
                    margin-left: 24rpx;
                    margin-top: 28rpx;

                    .text_25 {
                        line-height: 25.9rpx;
                    }

                    .text_26 {
                        line-height: 25.78rpx;
                    }
                }

                .group_20 {
                    margin-left: 24rpx;
                    margin-top: 32rpx;

                    .text_27 {
                        line-height: 25.96rpx;
                    }

                    .text_28 {
                        line-height: 25.88rpx;
                    }
                }

                .divider_2 {
                    margin-top: 28rpx;
                    background-color: #f3f4f6;
                    width: 716rpx;
                    height: 2rpx;
                }

                .text-wrapper_9 {
                    margin-left: 24rpx;
                    margin-top: 32rpx;
                    padding: 24rpx 0;
                    background-color: #5db66f;
                    border-radius: 400rpx;
                    mix-blend-mode: NOTTHROUGH;

                    .text_29 {
                        line-height: 25.9rpx;
                    }
                }
            }

            .font_4 {
                font-size: 24rpx;
                font-family: SourceHanSansCN;
                line-height: 22.28rpx;
                color: #555555;
            }
        }

        .image_6 {
            width: 32rpx;
            height: 32rpx;
        }

        .font {
            font-size: 32rpx;
            font-family: SourceHanSansCN;
            line-height: 29.88rpx;
            color: #333333;
        }

        .font_2 {
            font-size: 28rpx;
            font-family: SourceHanSansCN;
            line-height: 25.76rpx;
            color: #ffffff;
        }
    }
</style>
