<template>
    <view class="con-body">
        <view class="con-bg">
            <!-- 头部 -->
            <customHeader ref="customHeaderRef" :title="'客户审批'" :leftFlag="true" :rightFlag="false"></customHeader>
            <!-- 高度来避免头部遮挡 -->
            <view class="top-height" :style="{ paddingTop: navBarPaddingTop + 'px' }"></view>

            <!-- 正文内容 -->
            <view class="all-body">

                <!-- 分页部分  -->
                <mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
                    :up="upOption" :down="downOption" :fixed="false" textColor="#ffffff" bgColor="#ffffff"
                    class="scroll-h" :class="{ 'loading-scroll': cssFlag }">
                    <view class="white-bg margin-bottom20" v-for="(item, index) in dataList" :key="index"
                        @click="showDetail(item)">
                        <view>
                            <view class="report-list">
                                <view class="title">客户：{{ item.cusName }}</view>
                                <view class="r-list">
                                    <view class="r-name">{{ item.visistCode }}</view>
                                    <view>

                                        <view
                                            class="r-right btn-orange"
                                            size="mini">
                                            {{ item.status }}
                                        </view>
                                    </view>

                                </view>
                                <view class="border-bottom"></view>
                                <view class="r-list">
                                    <view class="r-left">走访类型</view>
                                    <view class="r-right">{{item.visistType}}</view>
                                </view>
                                <view class="r-list" v-if="item.joinUser != null">
                                    <view class="r-left">我方领导</view>
                                    <view class="r-right">{{ item.joinUser }}</view>
                                </view>
                                <view class="border-bottom"></view>
                                <view class="r-list">
                                    <view class="r-left">报告人</view>
                                    <view class="r-right">{{ item.staffName }}</view>
                                </view>
                                <view class="border-bottom"></view>
                                <view class="r-list">
                                    <view class="r-left">报告日期</view>
                                    <view class="r-right">{{ item.visistDate }}</view>
                                </view>

                            </view>
                        </view>
                    </view>
                </mescroll-uni>
            </view>
        </view>
    </view>
</template>

<script setup>
import customHeader from '@/components/customHeader.vue'
import { ref, reactive, onMounted } from 'vue'
import MescrollUni from 'mescroll-uni/mescroll-uni.vue';
import { getNavBarPaddingTop } from '@/utils/system.js'
import { onShow } from '@dcloudio/uni-app';
import { getApprovalList, getUserInfo } from '../../../../api/crm/activity/activity';


let list = ref([])
let queryParams = reactive({
    selValue: ''
})
// 获取导航栏高度用于内容区域padding
const navBarPaddingTop = ref(0);
onMounted(() => {
    navBarPaddingTop.value = getNavBarPaddingTop() * 2;
})
const upOption = ref({
    page: { num: 0, size: 10 },
    noMoreSize: 5,
    empty: { tip: '~ 空空如也 ~' },
    textLoading: '加载中...',
    textNoMore: '已经到底了'
});
const downOption = ref({
    auto: true,
    textInOffset: '下拉刷新',
    textOutOffset: '释放更新',
    textLoading: '刷新中...'
});

let mescrollRef = ref();
function mescrollInit(mescroll) {
    mescrollRef.value = mescroll;
}
/*下拉刷新的回调 */
function downCallback(mescroll) {
    mescroll.resetUpScroll()
}
/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
function upCallback(page) {
    // JSON.parse 将数据转换为 JavaScript 对象
    // var user = JSON.parse(uni.getStorageSync("user"));
    console.log(page.num)
    getVisistList(page);
}

onShow(() => {
    getUserInfoMethod();
})

let nickName = ref();
let deptName = ref();
let userId = ref();
let posts = ref();

//获取用户信息
function getUserInfoMethod() {
    getUserInfo().then(res => {
        nickName.value = res.user.nickName;
        deptName.value = res.user.dept.deptName;
        userId.value = res.user.userId;
        posts.value = res.post;
    })
}

//查询待审批的列表信息
let dataList = ref([])
function getVisistList(page) {
    var data = {
        pageNum: page.num,
        pageSize: 10,
    };

    getApprovalList(data).then(res => {
        if (res.code == 200) {
            //设置列表数据
            if (page.num == 1) {
                dataList.value = res.rows;

            } else {
                dataList.value = dataList.value.concat(res.rows);
            }
            mescrollRef.value.mescroll.endBySize(res.rows.length, 1000);
        } else {
            uni.showToast({
                icon: 'none',
                title: "请求失败",
            });
            dataList.value = null;
            mescrollRef.value.mescroll.endErr();
        }
    })
}

//审核走访单明细
function showDetail(item){
    	uni.navigateTo({
				url: './detailForApproval?visistId=' + item.visistId
			})
}
</script>

<style scoped>
.all-body {
    /* #ifdef APP-PLUS */
    top: 150rpx;
    height: calc(100vh - 75px);
    /* #endif */
    /* #ifndef APP-PLUS */
    top: 120rpx;
    height: calc(100vh);
    /* #endif */
}

.search {
    display: flex;
}

.search .btn-search {
    border: none;
    background: none;
    line-height: normal;
    color: #fff;
    line-height: 56rpx !important;
    padding: 10rpx 0 0;
    text-align: left;
    cursor: pointer;
}

.search .btn-search::after {
    display: none;
}

.search .custom-search {
    width: 80%;

}

.search .custom-search.uni-searchbar {
    padding-right: 0 !important;
}

.scroll-h {
    /* #ifdef APP-PLUS */
    height: calc(100vh - 120px);
    /* #endif */
    /* #ifndef APP-PLUS */
    height: calc(100vh - 110px);
    /* #endif */
}

.white-bg {
    padding-bottom: 10rpx;
}
</style>
