<template>
    <view class="flex direction-column height-100pre">
        <view class="status-bar-height"></view>
        <view class="image-view"></view>
        <view class="flex justify-bewteen padding">
            <view class="appicon">
                <view class="appicon-icon">
                    <uni-icons type="hand-up-filled" size="30" color="royalblue"></uni-icons>
                </view>
                <view class="appicon-text">确认派工</view>
            </view>
            <view class="appicon">
                <view class="appicon-icon">
                    <uni-icons type="calendar-filled" size="30" color="royalblue"></uni-icons>
                </view>
                <view class="appicon-text">完成派工</view>
            </view>
            <view class="appicon">
                <view class="appicon-icon">
                    <uni-icons type="settings-filled" size="30" color="royalblue"></uni-icons>
                </view>
                <view class="appicon-text">特殊派工</view>
            </view>
            <view class="appicon">
                <view class="appicon-icon">
                    <uni-icons type="wallet-filled" size="30" color="royalblue"></uni-icons>
                </view>
                <view class="appicon-text">工资明细</view>
            </view>
        </view>
        <view class="title">未完成清单</view>
        <view class="list-view">
            <view class="list-view-item">dddsdf</view>
            <view class="list-view-item">eeesd</view>
            <view class="list-view-item">rrrrd</view>
        </view>
        <view class="height-20"></view>
    </view>
</template>

<script>
    import extend from '../../utils/extend.js';
    import token from '../../utils/token.js';
    import user from '../../utils/user.js';
    import appUpdate from '../../utils/appUpdate.js';
    import request from '../../utils/request.js';

    export default {
        data() {
            return {
                isLogin: false,
                list: [],
                isNew: true,
                appWgtVersion: '',
                isUpdating: false,
                updateProcess: 0
            }
        },
        async onShow() {
            // #ifdef APP

            let baseUrl = await request.getBaseUrl();
            // console.log('baseUrl', baseUrl);

            // 检查更新
            let updateRes = await appUpdate.check('api/PDAScan/GetVersion?name=PDA');
            this.isNew = updateRes.isNew;
            this.appWgtVersion = updateRes.appWgtVersion;

            let url = baseUrl + updateRes.url;
            // console.log(updateRes);
            // console.log('url:', url);
            // this.$refs.newVerPopup.open();
            if (updateRes.isNew) {
                uni.showModal({
                    title: '应用更新',
                    content: `发现新版本 v${updateRes.appWgtVersion}，立即更新？`,
                    async success(r) {
                        if (r.confirm) {
                            let showLoading = plus.nativeUI.showWaiting('已下载 0%', {
                                width: '120px',
                                height: '100px',
                                loading: {
                                    type: 'circle'
                                }
                            });
                            let ures = await appUpdate.update({
                                url: url,
                                progress(pr) {
                                    _this.updateProcess = pr.progress;
                                    showLoading.setTitle(`已下载 ${pr.progress}%`);
                                }
                            });
                            showLoading.close();
                            if (ures.success) {
                                uni.hideLoading();
                            } else {
                                uni.showModal({
                                    title: '错误',
                                    content: ures.message
                                });
                            }
                        }
                    }
                });
            }

            // #endif
        },
        methods: {}
    }
</script>

<style lang="scss">
    .image-view {
        position: relative;
        height: 360upx;
        background-color: #f8f8f8;
    }

    .appicon {
        padding: 20upx 0;
        width: 25%;

        .appicon-icon {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100upx;
        }

        .appicon-text {
            display: flex;
            justify-content: center;
        }
    }

    .title {
        display: flex;
        padding: 20upx;
        color: royalblue;
        margin: 0 20upx;
        align-items: center;
        background-color: #f8f8f8;
    }

    .title::before {
        display: inline-block;
        content: '';
        width: 16upx;
        height: 100%;
        background-color: royalblue;
        margin-right: 10upx;
    }

    .list-view {
        position: relative;
        flex-grow: 1;
        background-color: #f8f8f8;
        margin: 0 20upx;
        overflow-x: hidden;
        overflow-y: auto;
        
        .list-view-item {
            display: flex;
            padding: 20upx;
        }
    }
</style>