<template>
    <view class="container">
        <!-- #ifdef MP-WEIXIN -->
        <view class="container-center"></view>
        <!-- #endif -->
        <view class="backShop flex-y-center" @click="back" v-if="is_shop">
            <image src="../static/images/back.png" mode=""></image>
            <view class="">
                返回商家
            </view>
        </view>

        <view class="header">
            <image :src="info.thumb" class="logo-img" mode="aspectFill"></image>
            <view class="content">
                <view class="name">{{info.title}}</view>
            </view>
        </view>

        <view class="main-block">
            <navigator url="../statistics/index/StoreIndex" class="flex-y-center haeder-title haeder-title-color ">
                <view class="border-b box-pack-between flex-grow-1 flex-y-center" style="	height: 90rpx;">
                    <view class="flex-y-center">
                        <view class="haeder flex-center haeder-color">
                            <view class="haeder-bg">
                            </view>
                        </view>
                        <view class="">
                            数据统计
                        </view>
                    </view>
                    <text class="iconfont icongengduo"></text>
                </view>
            </navigator>
            <view class="page-block">
                <view class="num-block flex box-pack-between">
                    <view class="item flex flex-col flex-center">
                        <view class="num">{{turnover.jryye}}</view>
                        <view class="name">今日营业额(元)</view>
                    </view>
                    <navigator :url="`/saomaDiancan/orderList/orderList?store_id=${store_id}&day=${day}`"
                        class="item flex flex-col flex-center">
                        <view class="num">{{turnover.jrdd}}</view>
                        <view class="name">今日订单</view>
                    </navigator>
                    <view class="item flex flex-col flex-center">
                        <view class="num">{{turnover.zyye}}</view>
                        <view class="name">总营业额(元)</view>
                    </view>
                </view>

                <view class="num-block flex box-pack-between">

                    <view class="item flex flex-col flex-center">
                        <view class="num">{{obj.dai_peisong_order||0}}</view>
                        <view class="name">待配送</view>
                    </view>

                    <view class="item flex flex-col flex-center">
                        <view class="num">{{obj.peisong_order||0}}</view>
                        <view class="name">配送中</view>
                    </view>

                    <view class="item flex flex-col flex-center">
                        <view class="num">{{obj.picked_order||0}}</view>
                        <view class="name">待自提</view>
                    </view>

                </view>
            </view>

           
            <view class="page-block">
                <view class="btn-list">

                    <block v-for="(item,index) in power_list" :key='index'>

                        <navigator v-if="item.id!=287 && item.id!=248 && item.id!=888 "
                            :url="`${item.address}?id=${item.id}`" class="item flex flex-col flex-center">
                            <image :src="item.image" class="icon-img" mode="aspectFit"></image>
                            <view class="name">{{item.name}}</view>
                        </navigator>

                        <block v-if="item.id==287 && item.name=='商品管理'">
                            <block v-for="(children,idx) of item.list" :key='idx'>
                                <navigator v-if="children.id==233 || children.name=='商品列表'"
                                    :url="`/saomaDiancan/editGoods/editGoods?store_id=${store_id}`"
                                    class="item flex flex-col flex-center">
                                    <image src="./static/images/icon_11.png" class="icon-img" mode="aspectFit"></image>
                                    <view class="name">添加商品</view>
                                </navigator>
                                <navigator :url="`${children.address}?id=${children.id}`"
                                    class="item flex flex-col flex-center">
                                    <image :src="children.image" class="icon-img" mode="aspectFit"></image>
                                    <view class="name">{{children.name}}</view>
                                </navigator>
                                
                            </block>
                        </block>


                        <block v-if="item.id== 288 && item.name=='订单管理'">
                            <block v-for="(children,idx) of item.list" :key='idx'>
                                <navigator v-if="children.id==238" :url="`${children.address}?id=${children.id}`"
                                    class="item flex flex-col flex-center">
                                    <image :src="children.image" class="icon-img" mode="aspectFit"></image>
                                    <view class="name">{{children.name}}</view>
                                </navigator>
                            </block>
                        </block>

                        <block v-if="item.id== 248 && item.name=='营销管理'">
                            <block v-for="(children,idx) of item.list" :key='idx'>
                                <navigator v-if="children.id==249" :url="`${children.address}?id=${children.id}`"
                                    class="item flex flex-col flex-center">
                                    <image :src="children.image" class="icon-img" mode="aspectFit"></image>
                                    <view class="name">{{children.name}}</view>
                                </navigator>
                            </block>
                        </block>

                        <block v-if="item.id== 888 && item.name=='数据统计'">
                            <block v-for="(children,idx) of item.list" :key='idx'>
                                <navigator v-if="children.id== 889" :url="`${children.address}?id=${children.id}`"
                                    class="item flex flex-col flex-center">
                                    <image :src="children.image" class="icon-img" mode="aspectFit"></image>
                                    <view class="name">{{children.name}}</view>
                                </navigator>
                            </block>
                        </block>

                    </block>

                    <!-- 					<navigator :url="`/storeInfoIng/storeList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_15.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">门店设置</view>
					</navigator>
					
					<navigator :url="`/saomaDiancan/orderList/orderList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_13.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">订单列表</view>
					</navigator> -->

                    <!-- <navigator :url="`/saomaDiancan/printer/printer?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_14.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">打印设置</view>
					</navigator>-->

                    <!-- 					<navigator :url="`./bannerList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_3.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">广告设置</view>
					</navigator>
					
					<navigator :url="`./staff?store_id=${store_id}&type=2`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_4.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">员工管理</view>
					</navigator>
					

					<navigator :url="`/storeInfoIng/deviceList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_14.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">设备管理</view>
					</navigator>
 -->
                    <!-- 					<navigator :url="`/saomaDiancan/member/member?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_5.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">会员设置</view>
					</navigator>

					<navigator :url="`/saomaDiancan/couponList/couponList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_7.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">优惠券管理</view>
					</navigator> -->

                    <!-- 				<navigator :url="`/saomaDiancan/goodsCatList/goodsCatList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_12.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">商品分类</view>
					</navigator>

					<navigator :url="`/saomaDiancan/editGoods/editGoods?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_11.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">添加商品</view>
					</navigator>

					<navigator :url="`/saomaDiancan/goodsList/goodsList?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_10.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">商品列表</view>
					</navigator> -->

                    <!-- 				<navigator :url="`/saomaDiancan/integral/integral?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_2.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">积分商城</view>
					</navigator> -->

                    <!-- 					<navigator :url="`/saomaDiancan/order/order?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_3.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">订单管理</view>
					</navigator>

					<navigator url="/storeInfoIng/popup/home" class="item flex flex-col flex-center">
						<image src="./static/images/icon_8.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">首页弹窗</view>
					</navigator> -->

                    <navigator url="/yuyue/WriteOff/index" class="item flex flex-col flex-center">
                        <image src="./static/images/icon_3.png" class="icon-img" mode="aspectFit"></image>
                        <view class="name">核销管理</view>
                    </navigator>

                    <!-- <navigator :url="`/saomaDiancan/activity/codeList?store_id=${store_id}`" class="item flex flex-col flex-center">
						<image src="./static/images/icon_6.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">营销码</view>
					</navigator>
					
					<navigator :url="`/saomaDiancan/ruyi/ruyi?store_id=${store_id}`" class="item flex flex-col flex-center">
						<image src="./static/images/icon_14.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">如意设备</view>
					</navigator> -->

                    <!-- <navigator :url="`/saomaDiancan/ruyi/staff?store_id=${store_id}`" class="item flex flex-col flex-center">
						<image src="./static/images/icon_14.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">员工列表</view>
					</navigator>
					
					<navigator :url="`/saomaDiancan/ruyi/handover?store_id=${store_id}`" class="item flex flex-col flex-center">
						<image src="./static/images/icon_14.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">交班记录</view>
					</navigator> -->

                    <!-- 			<navigator :url="`/statistics/goodsData/goodsData?store_id=${store_id}`"
						class="item flex flex-col flex-center">
						<image src="./static/images/icon_14.png" class="icon-img" mode="aspectFit"></image>
						<view class="name">商品数据统计</view>
					</navigator> -->

               <!--     <navigator :url="`./goodsWarehousing/index?store_id=${store_id}`"
                        class="item flex flex-col flex-center">
                        <image src="./static/images/icon_12.png" class="icon-img" mode="aspectFit"></image>
                        <view class="name">商品入库</view>
                    </navigator> -->

                    <navigator url="./saomaShoukuan/saomaShoukuan" class="item flex flex-col flex-center">
                        <image src="/static/images/saoma.png" class="icon-img" mode="aspectFit"></image>
                        <view class="name">快速收款</view>
                    </navigator>

                 <!--   <navigator url="/storeInfoIng/bindingCode/index" class="item flex flex-col flex-center">
                        <image src="./static/images/icon_18.png" class="icon-img" mode="aspectFit"></image>
                        <view class="name">空码管理</view>
                    </navigator> -->
					
					<navigator url="/storeInfoIng/reservation/index" class="item flex flex-col flex-center">
					    <image src="./static/images/yy.png" class="icon-img" mode="aspectFit"></image>
					    <view class="name">预约查询</view>
					</navigator>

                </view>
            </view>
            <view class="btm-btn" @click="loginOut">退出登录</view>
            <!-- <view class="more-block">—— 更多服务 敬请期待 ——</view> -->
        </view>

    </view>
</template>

<script>
    export default {
        data() {
            return {
                store_id: "",
                info: {},
                turnover: {},
                ad: [],
                is_shop: false,
                day: null,
                obj: {},
                // getApp().globalData.is_shop,
                qc_list: [], //待取餐列表
                power_list: []
            }
        },

        onLoad(options) {
            if (!uni.getStorageSync("admin_id")) {
                uni.reLaunch({
                    url: "/pages/login/login"
                })
            }
            this.store_id = uni.getStorageSync("store_id");
            this.is_shop = uni.getStorageSync("is_shop");
            this.day = this.getNowFormatDay();
            this.power();
            // 链接websocket 播放来单提醒
            getApp().initSocket(this.store_id)
        },

        onShow() {
            this.getInfo();
            this.getTurnover();
            this.http();
            this.getQcData()
        },

        onShareAppMessage() {

        },

        onShareTimeline() {

        },

        methods: {


            power() {
                this.request({
                    url: 'index/index',
                    data: {
                        admin_id: uni.getStorageSync("admin_id")
                    },
                    is_agent: 'agent',
                }).then(res => {
                    console.log(res, "index/index")
                    if (res.code == '200') {
                        this.power_list = res.data
                        this.$store.commit('SET_MANAGE', res.data)
                        // this.$store.state.management_list;
                    }
                }).catch((res) => {
                    uni.showToast({
                        title: res.message,
                        icon: 'none'
                    })
                });
            },
            http(e) {
                this.request({
                    url: 'Smdcshop/store_index',
                    data: {
                        admin_id: uni.getStorageSync("admin_id")
                    }
                }).then(res => {
                    if (res.code == 200) { 
                        this.obj = res.data;
                    }
                }).catch((res) => {
                    uni.showToast({
                        title: res.message,
                        icon: 'none'
                    })
                });
            },

            getNowFormatDay() {
                var char = "-";
                let nowDate = new Date();
                var day = nowDate.getDate();
                var month = nowDate.getMonth() + 1; //注意月份需要+1
                var year = nowDate.getFullYear();
                //补全0，并拼接
                return year + char + completeDate(month) + char + completeDate(day);
                //补全0
                function completeDate(value) {
                    return value < 10 ? "0" + value : value;
                }
            },

            back() {
                uni.setStorageSync("admin_id", uni.getStorageSync("admin_shopid")); //admin_id 重复
                // getApp().globalData.is_shop=null;
                uni.removeStorageSync("is_shop");
                uni.setStorageSync("is_login", 2);
                uni.reLaunch({
                    url: "/saomaDiancan/index/index"
                })
                getApp().closeSocket('返回商家 关闭接单提醒',true)
            },
            loginOut() { 
                uni.removeStorageSync("is_shop");
                uni.removeStorageSync("store_id");
                uni.removeStorageSync("store_user");
                uni.removeStorageSync("admin_id");
                uni.removeStorageSync("storeinfo");

                uni.removeStorage({
                    key: 'is_login',
                    success: (res) => {
                        uni.reLaunch({
                            url: "../pages/login/login"
                        })
                    }
                })
                getApp().closeSocket("退出登录 关闭接单提醒",true)
            },
            //门店信息
            getInfo() {
                this.request({
                    url: 'Smdcshop/storeinfo',
                    data: {
                        store_id: this.store_id
                    }
                }).then(res => {
                    console.log(res)
                    if (res.code == 200) {
                        let info = res.data
                        info.thumb = this.$siteroot + info.thumb
                        this.info = info;
                        uni.setStorageSync("storeinfo", res.data);
                    }
                })
            },
            //营业额
            getTurnover() {
                this.request({
                    url: 'Smdcshop/turnover',
                    data: {
                        store_id: this.store_id
                    }
                }).then(res => {
                    console.log(res)
                    if (res.code == 200) {
                        this.turnover = res.data
                    }
                })
            },
            //获取待取餐列表
            getQcData() {
                this.request({
                    url: 'Smdcshop/order_index_neal',
                    data: {
                        page: 1,
                        limit: 4,
                        store_id: this.store_id,
                    }
                }).then(res => {
                    if (res.code == 200 && res.data.length) {
                        this.qc_list = res.data
                    }
                })
            },
            //取餐订单时间格式化
            getQcTime(time) {
                return this.$utils.dateFormat('mm-dd HH:MM', new Date(time))
            },
            //提醒取餐
            onQucan(index) {

                this.request({
                    url: 'merchant/take_meal',
                    is_agent: 'agent',
                    data: {
                        order_id: this.qc_list[index].id
                    }
                }).then(res => {
                    if (res.code == 200) {
                        uni.showModal({
                            content: "已提醒取单",
                            showCancel: false,
                            success: () => {
                                this.getQcData()
                            }
                        })
                    }
                })
            },

        }
    }
</script>


<style lang="scss">
    .container-center {
        height: 44px;
        background-color: #3387FF;
    }

    page {
        background-color: #F4F5F7;
    }

    .backShop {
        position: absolute;
        left: 20rpx;
        /* #ifdef MP-WEIXIN */
        top: 44px;
        /* #endif */
        /* #ifdef H5 */
        top: 10rpx;
        /* #endif */
        font-size: 26rpx;
        color: #FFFFFF;
        z-index: 999;
        border: 1rpx solid #FFFFFF;
        padding: 6rpx 10rpx;
        border-radius: 4rpx;
    }

    .backShop image {
        width: 36rpx;
        height: 36rpx;
    }

    .btm-btn {
        width: 670rpx;
        height: 98rpx;
        background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
        border-radius: 8rpx;
        box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
        font-size: 32rpx;
        font-weight: 500;
        text-align: center;
        color: #fff;
        line-height: 98rpx;
        margin: 0 auto;
        margin-top: 100rpx;
        margin-bottom: 30rpx;
    }

    .header {
        width: 100%;
        height: 216rpx;
        background: url(./static/images/store_info_bg.png) no-repeat;
        background-size: 750rpx 216rpx;
        background-position: bottom center;
        position: relative;
    }

    .header .content {
        width: 700rpx;
        height: 221rpx;
        background: #fff url(./static/images/stroe_info_bg2.png) no-repeat;
        background-size: 100%;
        border-radius: 8rpx;
        position: absolute;
        left: 50%;
        top: 120rpx;
        transform: translateX(-50%);
    }

    .header .content .name {
        text-align: center;
        font-size: 36rpx;
        color: #333;
        padding-top: 96rpx;
        line-height: 125rpx;
    }

    .header .logo-img {
        display: block;
        width: 160rpx;
        height: 160rpx;
        position: absolute;
        left: 50%;
        top: 56rpx;
        transform: translateX(-50%);
        z-index: 100;
        border-radius: 200px;
    }

    .main-block {
        padding: 155rpx 25rpx 0;
    }

    .page-block {
        width: 700rpx;
        background-color: #fff;
        box-sizing: border-box;
        border-radius: 8rpx;
        margin-bottom: 30rpx;

    }

    .num-block .item {
        width: 33.33%;
        height: 162rpx;
        flex: none;
        text-align: center;
    }

    .num-block .item .num {
        color: #3387FF;
        font-size: 44rpx;
        font-weight: bold;
        font-family: DIN;
    }

    .num-block .item .name {
        font-size: 24rpx;
        color: #666;
        margin-top: 16rpx;
    }

    .btn-list {
        display: flex;
        flex-flow: row wrap;
        justify-content: flex-start;
        align-content: flex-start;
    }

    .btn-list .item {
        width: 33.33%;
        height: 145rpx;
    }

    .btn-list .item .icon-img {
        display: block;
        width: 48rpx;
        height: 48rpx;
    }

    .btn-list .item .name {
        font-size: 24rpx;
        line-height: 33rpx;
        margin-top: 16rpx;
        color: #666;
    }

    .more-block {
        font-size: 24rpx;
        color: #B2B2B2;
        text-align: center;
        line-height: 33rpx;
        padding: 60rpx 0;
        position: fixed;
        left: 50%;
        bottom: 0;
        transform: translateX(-50%);
    }

    .haeder-title {

        font-size: 32rpx;
        font-family: PingFang SC, PingFang SC-Medium;
        font-weight: 500;
        text-align: center;
        color: #333333;
        border-radius: 8rpx 8rpx 0px 0px;
        padding: 0 24rpx;
    }

    .haeder-title-color {
        background-color: #FFFFFF;
        /* border-bottom: 1rpx solid #F1F1F1; */
        /* background: linear-gradient(90deg, rgba(114, 178, 255, 0.30), rgba(114, 178, 255, 0.00)); */
    }

    .haeder-color {
        background: linear-gradient(136deg, #6397fd 4%, #3377ff 100%);
    }

    .haeder {
        width: 36rpx;
        height: 36rpx;
        border-radius: 50%;
        margin-right: 10rpx;
    }

    .haeder-bg {
        width: 16rpx;
        height: 19rpx;
        background: linear-gradient(180deg, #ffffff, rgba(255, 255, 255, 0.60) 100%);
        border-radius: 4rpx;
    }

    /* 取餐表 */
    .qc-table-block {
        box-sizing: border-box;
        width: 100%;
        padding: 10rpx 24rpx;

        .qc-table {
            display: table;
            width: 100%;
            border-collapse: collapse;
            box-sizing: border-box;


            .tr {
                display: table-row;
                border-bottom: 1px solid #f0f0f0;

                .td {
                    display: table-cell;
                    font-size: 26rpx;
                    color: #666;
                    padding: 20rpx 6rpx;
                    text-align: center;

                    .qc-btn {
                        background-color: #3387FF;
                        color: #fff;
                        border-radius: 6rpx;
                        height: 48rpx;
                        line-height: 48rpx;
                        padding: 0 10rpx;

                    }

                }
            }

            .th .td {
                font-weight: 500;
                color: #333;
            }
        }
    }
</style>
