<template>
    <view>
        <view class="screen">
            <picker v-model="orgIndex" :range="orgList" range-key="label" data-key="orgIndex" @change="setVal">
                <view class="picker">
                    <text>{{ orgIndex >= 0 ? orgList[orgIndex].label : '按组织' }}</text>
                    <image src="/static/subpages/statistics/images/down.png" mode="widthFix" />
                </view>
            </picker>
            <input placeholder="按姓名" @input="setVal" data-key="name" class="picker-type" />
            <input placeholder="按电话" @input="setVal" data-key="mobile" class="picker-type" />
            <view class="btn" @tap="search">筛选</view>
        </view>

        <view class="qz-container">
            <view class="qz-list">
                <view class="qz-item" v-for="(item, index) in list" :key="index">
                    <view class="user-info">
                        <view class="name">{{ item.name }} {{ item.mobile }}</view>
                        <view class="address">{{ item.agencyName ? item.agencyName : '' }}</view>
                    </view>

                    <view class="num-list">
                        <view
                            class="num-item"
                            @tap="gotopage"
                            :data-url="
                                '/subpages/statistics/pages/sjwjj/sjwjj?id=' +
                                item.reportUserId +
                                '&name=' +
                                item.name +
                                '&mobile=' +
                                item.mobile +
                                '&agencyName=' +
                                item.agencyName
                            "
                        >
                            <view class="txt">
                                <text>事件未解决数</text>
                            </view>
                            <view class="num">{{ item.eventCount }}</view>
                        </view>
                        <view
                            class="num-item"
                            @tap="gotopage"
                            :data-url="
                                '/subpages/statistics/pages/xqwmz/xqwmz?id=' +
                                item.reportUserId +
                                '&name=' +
                                item.name +
                                '&mobile=' +
                                item.mobile +
                                '&agencyName=' +
                                item.agencyName
                            "
                        >
                            <view class="txt">
                                <text>需求未满足数</text>
                            </view>
                            <view class="num">{{ item.demandCount }}</view>
                        </view>
                        <view
                            class="num-item"
                            @tap="gotopage"
                            :data-url="
                                '/subpages/statistics/pages/yxwxfw/yxwxfw?id=' +
                                item.reportUserId +
                                '&name=' +
                                item.name +
                                '&mobile=' +
                                item.mobile +
                                '&agencyName=' +
                                item.agencyName
                            "
                        >
                            <view class="txt">
                                <text>应享未享服务数</text>
                            </view>
                            <view class="num">{{ item.serviceCount }}</view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import { getPotentialDissatisfiedCountDetail, maporg } from '../../../../utils/statisticsApi';
export default {
    data() {
        return {
            orgList: [],
            orgIndex: 0,
            pageNo: 1,
            pageSize: 10,
            list: [],
            total: 0,
            mobile: '',
            name: '',
            countType: '',
            label: ''
        };
    },
    onLoad(options) {
        this.setData({
            countType: options.countType
        });
        this.getOrg();
    },
    onReachBottom() {
        if (this.list.length < this.total) {
            this.setData({
                pageNo: this.pageNo + 1
            });
            this.getList();
        }
    },
    methods: {
        getOrg() {
            maporg().then(async ({ data }) => {
                let parent = {
                    value: data.id,
                    label: data.name
                };
                this.setData({
                    orgList: [
                        parent,
                        ...data.children.map((item) => {
                            return {
                                value: item.id,
                                label: item.name
                            };
                        })
                    ]
                });
                this.getList();
            });
        },

        gotopage({ currentTarget: { dataset } }) {
            const { url } = dataset;
            uni.navigateTo({
                url
            });
        },

        setVal(e) {
            this.setData({
                [e.currentTarget.dataset.key]: e.detail.value
            });
        },

        search() {
            this.setData({
                pageNo: 1,
                list: [],
                total: 0
            });
            this.getList();
        },

        getList() {
            getPotentialDissatisfiedCountDetail({
                pageNo: this.pageNo,
                pageSize: this.pageSize,
                agencyId: this.orgList[this.orgIndex].value,
                name: this.name,
                mobile: this.mobile,
                countType: this.countType
            }).then(({ data }) => {
                this.setData({
                    list: this.list.concat(data.list),
                    total: data.total
                });
            });
        }
    }
};
</script>
<style>
.qz-container {
    padding: 20rpx;
}
page {
    background: #f7f7f7;
}

.screen {
    display: flex;
    justify-content: space-between;
    background: #fff;
    padding: 18rpx 22rpx;
}

.picker {
    width: 181rpx;
    height: 56rpx;
    background: rgba(58, 128, 231, 0.16);
    border: 1px solid #3a80e7;
    border-radius: 28rpx;
    font-size: 30rpx;
    font-weight: 500;
    color: #3a80e7;
    line-height: 56rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30rpx;
    box-sizing: border-box;
}
.picker text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.picker-type image,
.picker image {
    width: 24rpx;
    height: 24rpx;
}

.picker-type {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30rpx;
    box-sizing: border-box;
    width: 217rpx;
    height: 56rpx;
    background: rgba(193, 193, 193, 0.16);
    border: 1px solid #dbdbdb;
    border-radius: 28rpx;
    font-size: 30rpx;
    font-weight: 500;
    color: #c1c1c1;
    line-height: 56rpx;
    text-align: center;
    margin-left: 20rpx;
}

.btn {
    width: 120rpx;
    height: 56rpx;
    line-height: 56rpx;
    background: #3a80e7;
    border-radius: 28rpx;
    font-size: 28rpx;
    font-weight: 500;
    color: #ffffff;
    text-align: center;
    margin-left: 20rpx;
}

.qz-list {
    border-radius: 20rpx;
    background: #ffffff;
    padding: 30rpx 30rpx 0;
}
.qz-list .qz-item {
    border-bottom: 1px solid #eaeaea;
    padding-bottom: 40rpx;
    margin-bottom: 40rpx;
}
.qz-list .qz-item .user-info .address {
    font-size: 28rpx;
    font-weight: 400;
    color: #666666;
}

.qz-list .qz-item .user-info .name {
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
}
.qz-list .qz-item .user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.num-list {
    display: flex;
    width: 100%;
    justify-content: space-between;
    margin-top: 38rpx;
}
.num-list .num-item {
    position: relative;
}
.num-list .num-item:after {
    content: '';
    display: block;
    position: absolute;
    right: -30rpx;
    top: calc(50% - 34rpx);
    width: 1rpx;
    height: 68rpx;
    background: #c1c1c1;
    opacity: 0.66;
}
.num-list .num-item:last-child:after {
    display: none;
}
.num-list .num-item .txt {
    font-size: 28rpx;
    font-weight: 500;
    color: #999999;
}
.num-list .num-item .num {
    font-size: 42rpx;
    font-weight: bold;
    color: #ff783c;
    margin-top: 30rpx;
}
</style>
