<template>
    <view class="container" v-if="systemInfo!=null">
        <view class="head-bg"  ></view>
        <view class="main">

            <!-- 微信展示 -->
            <view v-if="(systemInfo.is_hall==1||systemInfo.is_ziti==1) && systemInfo.is_waimai==1"
                class="formhead flex flex-y-center flex-x-between">
                <view class="formheadnav" :class="teen_index==1||teen_index==3?'selsect':'default'"
                    @click="selectednavbar" data-index='1'>
                    {{descFood.food1}}
                </view>
                <view class="formheadnav" :class="teen_index==2?'selsect':'default'" @click="selectednavbar"
                    data-index='2'>
                    {{descFood.food2}}
                </view>
            </view>

            <view class="formhdwm" v-if="teen_index==2"
                :class="((systemInfo.is_hall==1||systemInfo.is_ziti==1) && systemInfo.is_waimai==1)?'':'teen_radius'">
                <view class="weui-cells weui-cells_after-title">
                    <button @click="getWechatAddress" class="weui-cell weui-cell_access wmaddress"
                        hoverClass="weui-cell_active" style="border-bottom: 1rpx solid #f4f4f4;" v-if="address">
                        <view class="weui-cell__bd">
                            <view class="wmshr">
                                <text style="margin-right: 10rpx;">{{address.user_name||'请选择收货地址'}} </text>
                                <text v-if="address.sex=='1'">(先生)</text>
                                <text v-if="address.sex=='2'">(女士)</text>
                                <text style="margin-left: 10rpx;"> {{address.tel||''}}</text>
                            </view>
                            <view class="wmshdz">
                                {{address.address||''}}
                            </view>
                        </view>
                        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                    </button>
                    <button @click="getWechatAddress" class="weui-cell weui-cell_access wmaddress"
                        hoverClass="weui-cell_active" style="border-bottom: 1rpx solid #f4f4f4;" v-else>
                        <view class="weui-cell__bd">
                            请选择收货地址
                        </view>
                        <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                    </button>
                </view>
            </view>

            <view class="page-block" :class="systemInfo.is_waimai==1?'page-blocks':''">
                <view class="page-title flex flex-nowarp flex-y-center">
                    <i class="iconfont icon-canyin icon-1" :style='{color:setColor}'></i>
                    <view class="text-nowarp">{{systemInfo.title || ''}}
                        <!-- <block v-if='teen_index==1 && systemInfo.table'>({{systemInfo.table || ''}})</block> -->
                    </view>
                    <!-- <view class="desc">下单商品</view> -->
                </view>
                <view class="goods-list" v-if="carInfo">
					<block v-for="(goods,idx) in carInfo.new_list" :key="idx">
						<view class="flex-y-center carInfoHeader" @click="chooseBag(goods.pocket)">
							<view class="radio__inner"
								:style="'border: 6rpx solid' + setColor">
								<view :style="'background:#fff'"
									class="radio__inner-icon radio__inner-icon is-default-checked">
								</view>
							</view>
							购物口袋{{goods.pocket}}
							<block v-if="teen_index==2 && teen_index==3 && systemInfo.is_ziti==1 && goods.packing_fee">
								（包装费 <text style="color: red;">￥{{goods.packing_fee}}</text>）
							</block>
						</view>
						<block v-for="(item,index) of goods.list" :key="index">
							<view class="item flex flex-nowarp" v-if="index < 3 || (index>=3 && goods.showMore)">
								<image :src="getImgSrc(item.spec_image)" mode="aspectFill" class="img"></image>
								<view class="info flex flex-column">
									<view class="title">{{item.name}}</view>
									<view class="unit">{{item.spec}}</view>
									<view class="num">× {{item.num}}</view>
								</view>
								<view class="price">￥{{item.price}}</view>
							</view>
						</block>
						
						<view class="more-btn" v-if="goods.list.length > 3 && !goods.showMore" @click="onShowMore(idx)">显示更多</view>
                    </block>
					
                    <view class="total-block" v-if="teen_index==2">共 {{carInfo.carNum}}
                        件，小计：￥{{Number(carInfo.total_price)}}</view>
                    <view class="total-block" v-else>共 {{carInfo.carNum}} 件，小计：￥{{carInfo.total_price}}</view>
					
                </view>
				
            </view>

            <!-- 餐桌 -->
            <!-- 就餐人数 -->
            <view class="page-block pay-type-clock" v-if="teen_index==1">
                <view v-if='teen_index==1 && systemInfo.table'>
                    <view class="page-title flex flex-nowarp flex-y-center">
                        <view class="flex-y-center">
                            下单位置
                        </view>
                        <view class="desc">{{systemInfo.table || ''}}</view>
                    </view>
                </view>
                <block v-if="teen_index == 1 && eat_people>0">
                    <view>
                        <view class="page-title flex flex-nowarp flex-y-center">
                            <view class="flex-y-center">
                                就餐人数
                            </view>
                            <view class="desc">{{eat_people}}人</view>
                        </view>
                    </view>
                    <view>
                        <view class="page-title flex flex-nowarp flex-y-center">
                            <view class="flex-y-center">
                                费用
                            </view>
                            <view class="desc">￥{{totle_eat_people}}</view>
                        </view>
                    </view>
                </block>
            </view>
            <!-- 就餐人数end -->

            <view class="page-block pay-type-clock">
                <view v-if="systemInfo.pay_type == 1 && teen_index!=2">
                    <view class="page-title flex flex-nowarp flex-y-center box-pack-between">
                        <view class="flex-y-center" style="flex: 1;">
                            {{descOrder.title}}
                        </view>
                        <view class="flex">
                            <view v-if="systemInfo.is_hall==1" class="diningItem diningItem-act"
                                :class="teen_index==1?'diningItem_act':''"
                                :style="[teen_index==1?{color: setColor,borderColor:setColor}:'']"
                                @click="bindDining(1)">
                                {{descOrder.food1}}
                                <text v-if="teen_index==1" :style="{color: setColor}"
                                    class="iconfont icon-youxiajiaogouxuan"></text>
                            </view>
                            <view v-if="systemInfo.is_ziti==1" class="diningItem"
                                :class="teen_index==3?'diningItem_act':''"
                                :style="[teen_index==3?{color: setColor,borderColor:setColor}:'']"
                                @click="bindDining(3)">
                                {{descOrder.food2}}
                                <text v-if="teen_index==3" :style="{color: setColor}"
                                    class="iconfont icon-youxiajiaogouxuan"></text>
                            </view>
                        </view>
                    </view>

                    <block v-if="teen_index==3 && systemInfo.is_ziti==1">
                        <view class="flex-y-center">
                            <view class='flex-row flex-y-center border-bottom' style='padding: 0 24rpx;height: 100rpx;'>
                                <view class='flex-grow-1' style='padding-left: 8rpx;border-right:2rpx solid #e3e3e3;'>
                                    <input @input='KeyName' placeholder='请输入自提人'></input>
                                </view>
                                <view class='flex-grow-1' style='margin-left:32rpx;'>
                                    <input @input='KeyMobile' type="number" maxlength="11"
                                        placeholder='请输入自提电话'></input>
                                </view>
                            </view>
                        </view>
                        <picker @change="bindPickerChange" :range="wmtimearray" :value="wmindex">
                            <view class="weui-cell weui-cell_access" hoverClass="weui-cell_active">
                                <view class="weui-cell__hd">
                                    <image src="../../static/wmtime.png"
                                        style="margin-right: 5px;vertical-align: middle;width:35rpx; height:35rpx;">
                                    </image>
                                </view>
                                <view class="weui-cell__bd">自提时间</view>
                                <view class="weui-cell__ft weui-cell__ft_in-access" :style="{color:setColor}">
                                    <block>
                                        {{wmtimearray[wmindex]}}
                                    </block>
                                </view>
                            </view>
                        </picker>
                        <!-- 包装费 -->
                        <view v-if="carInfo.box_fee>0">
                            <view class="page-title flex flex-nowarp flex-y-center">
                                <view class="flex-y-center">
                                    <image src="../../static/packing.png" style="width: 50rpx;" class="VIP2"></image>
                                    包装费
                                </view>
                                <view class="desc">￥{{carInfo.box_fee}}</view>
                            </view>
                        </view>
                    </block>
                </view>
                <block v-if="systemInfo.is_vip==1">
                    <view v-if="menber_discount.name&&menber_discount.discount">
                        <view class="page-title flex flex-nowarp flex-y-center">
                            <view class="flex-y-center">
                                <image src="../../static/VIP2.png" class="VIP2"></image>会员优惠
                            </view>
                            <view class="desc">{{menber_discount.name}}专享 <text class="red" style="font-size: 40rpx;">
                                    {{menber_discount.discount}} </text> 折优惠</view>
                        </view>
                    </view>
                </block>

                <block v-if="teen_index==2">
                    <view>
                        <view class="page-title flex flex-nowarp flex-y-center">
                            <view class="flex-y-center">
                                <image src="../../static/ps.png" style="width: 50rpx;" class="VIP2"></image>
                                配送费
                            </view>
                            <view class="desc">￥{{deliveryPrice}}</view>
                        </view>
                    </view>
                    <view v-if="carInfo.box_fee>0">
                        <view class="page-title flex flex-nowarp flex-y-center">
                            <view class="flex-y-center">
                                <image src="../../static/packing.png" style="width: 50rpx;" class="VIP2"></image>
                                包装费
                            </view>
                            <view class="desc">￥{{carInfo.box_fee}}</view>
                        </view>
                    </view>
                </block>

              <!--  <block v-if="systemInfo.set.change_table==1 && teen_index==1">
                    <view @click="bindScan">
                        <view class="page-title flex flex-nowarp flex-y-center">
                            <view class="flex-y-center">
                                <image src="../../static/saoyisao.png" style="width: 50rpx;" class="VIP2"></image>
                                扫码换桌
                            </view>
                            <view class="desc arr-r"></view>
                        </view>
                    </view>
                </block> -->

                <!-- <view v-if="teen_index==1" class="box-pack-between ft26 pd20"> <text>配送费</text> <text>￥{{deliveryPrice}}</text></view> -->
                <!--pay_type==1先付后吃， teen_index外卖没有先吃后付-->

                <block v-if="systemInfo.pay_type == 1||teen_index==2">
                    <view class="page-title flex flex-nowarp flex-y-center">
                        <view>支付方式</view>
                        <view class="desc">在线支付</view>
                    </view>
                    <view class="content">
                        <!-- #ifdef MP-ALIPAY -->
                        <view class="cell flex flex-nowarp flex-y-center" @click="checkPay(2)">
                            <image src="../../static/icon_8.png" mode="aspectFit" class="pay-type-icon"></image>
                            <view class="title">支付宝支付</view>
                            <i v-if="check_index==2" class="iconfont icon-lujing check-box"
                                :style='{color:setColor}'></i>
                            <view class="rund check-box" v-else :style='{color:setColor}'></view>
                        </view>
                        <!-- #endif -->

                        <!-- #ifdef MP-WEIXIN -->
                        <view class="cell flex flex-nowarp flex-y-center" @click="checkPay(1)">
                            <image src="../../static/icon_7.png" mode="aspectFit" class="pay-type-icon"></image>
                            <view class="title">微信支付</view>
                            <i class="iconfont icon-lujing check-box" :style='{color:setColor}'
                                v-if="check_index==1"></i>
                            <view class="rund check-box" :style='{color:setColor}' v-else></view>
                        </view>
                        <!-- #endif -->

                        <view v-if="systemInfo.set.is_charge == 1" class="cell flex flex-nowarp flex-y-center"
                            @click="checkPay(4)">
                            <image src="../../static/icon_cz.png" mode="aspectFit" class="pay-type-icon"></image>
                            <view class="title">充值 <text
                                    style="font-size: 34rpx;color: red;">{{ Number(systemInfo.set.charge_num)*Number(total_price)}}</text>
                                免单</view>
                            <i class="iconfont icon-lujing check-box" :style='{color:setColor}'
                                v-if="check_index==4"></i>
                            <view class="rund check-box" :style='{color:setColor}' v-else></view>
                        </view>

                        <view v-if="systemInfo.is_vip==1&&userInfo.mobile&&menber_discount.balance"
                            class="cell flex flex-nowarp flex-y-center" @click="checkPay(3)">
                            <image src="../../static/icon_6.png" mode="aspectFit" class="pay-type-icon"></image>
                            <view class="title">余额支付(剩余余额：{{menber_discount.balance}})</view>
                            <i class="iconfont icon-lujing check-box" :style='{color:setColor}'
                                v-if="check_index==3"></i>
                            <view class="rund check-box" :style='{color:setColor}' v-else></view>
                        </view>

                        <view style="padding-bottom: 20rpx;"
                            v-if="systemInfo.is_vip==1 && userInfo.mobile && czList.length>0">
                            <scroll-view scroll-x="true" style="white-space: nowrap;">
                                <view class="pay-price pr" :class="index==paytype?'act':''"
                                    :style="index==paytype?'border-color:#fff;color:#fff;background-color:'+setColor:''"
                                    v-for='(item,index) of czList' :key="index" :data-id='item.id'
                                    :data-content='item.pay_price' @click="choice_pay(index)" :data-index='index'>
                                    <text class="maney">￥{{item.pay_price}}</text>
                                    <view class="maney_get" :style="index==paytype?'color:#fff;':''">赠送
                                        {{item.send_price}}
                                    </view>
                                </view>
                            </scroll-view>
                        </view>

                    </view>
                </block>
            </view>

            <view class="page-block pay-type-clock"
                v-if=" (systemInfo.pay_type==1||teen_index==2)">
                <view class="content">
                    <navigator
                        :url="`../use-coupon-list/use-coupon-list?total_price=${carInfo.total_price}&check_index=${check_index}&state=${teen_index}`"
                        class="cell flex flex-nowarp flex-x-between flex-y-center">
                        <view class="title">优惠劵</view>
                        <view class="flex-y-center" v-if="coupon_id">
                            <text style="color: red;">-￥{{coupon_price}}</text>
                            <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                        </view>
                        <view class="flex-y-center" v-else>
                            <text style="color: red;">未使用优惠劵{{coupon_list.length}}张</text>
                            <view class="weui-cell__ft weui-cell__ft_in-access"></view>
                        </view>
                    </navigator>
                </view>
            </view>

            <view class="page-block pay-type-clock">
                <view class="content">
                    <view class="cell flex flex-nowarp flex-x-between flex-y-center">
                        <view class="title">订单备注</view>
                        <navigator :url="`/pages/addRemarks/addRemarks?remarks=${remarks}`" hover-class="nav-hover"
                            class="desc flex flex-nowarp flex-y-center arr-r">{{remarks || '点击填写备注'}}</navigator>
                    </view>
                </view>
            </view>
        </view>

        <!-- 支付时提示开通会员 -->
        <block v-if="systemInfo.set.open==1 && !userInfo.mobile">
            <getPhone />
        </block>

        <view class="footer-block is-iphone-x">
            <view class="content is-iphone-x flex flex-nowarp flex-x-between flex-y-center">
                <view class="total-block" :style='{color:setColor}'>
                    <text class="title">共计：</text>
                    <text class="sign">￥</text>
                    <text class="money">{{total_price}}</text>
                </view>
                <block v-if="is_distance">
                    <view class="sub-btn" style="background:#999;width:300rpx;">超出配送范围
                    </view>
                </block>
                <block v-else-if="teen_index==2&&Number(total_price)<Number(systemInfo.set.delivery_price)">
                    <view class="sub-btn" style="background:#999;width:300rpx;">
                        ￥{{systemInfo.set.delivery_price}}起送
                    </view>
                </block>

                <block v-else>
                    <!-- 先充值后下单 -->
                    <block v-if="paytype!=-1 || check_index==4">
                        <view class="sub-btn" :style="{'background-color':setColor}" @click="czPay">下单</view>
                    </block>

                    <block v-else>
                        <block v-if="systemInfo.set.open==1 && systemInfo.is_vip==1 && !userInfo.mobile">
                            <view class="sub-btn" :style="{'background-color':setColor}" @click="modelGetPhone">下单
                            </view>
                        </block>
                        <!-- 餐后付款 -->
                        <block v-else>
                            <view class="sub-btn" :style="{'background-color':setColor}"
                                v-if="hebin_index==1&teen_index!=2" @click="addCheck">下单
                            </view>
                            <view class="sub-btn" :style="{'background-color':setColor}" v-else @click="addOrder">下单
                            </view>
                        </block>
                    </block>

                </block>
            </view>
        </view>

        <uni-popup ref="popup" type="center">
            <view class="merge-model" v-if="is_pop==1">
                <view class="weui-dialog__hd">
                    <text class="weui-dialog__title">提示</text>
                </view>
                <view class="weui-dialog__tip">
                    是否合并前面的订单?
                </view>
                <scroll-view scroll-y="true" style="max-height:250px;">
                    <view class="main">
                        <view class="page-block" style="padding: 0;">
                            <view class="goods-list" v-if="hebinList.length>0">
                                <block v-for="(item,index) in hebinList" :key="index">
                                    <view class="item flex flex-nowarp" v-if="index < 3 || (index>=3 && showMore)">
                                        <image :src="getImgSrc(item.spec_image)" mode="aspectFill" class="img"></image>
                                        <view class="info flex flex-column">
                                            <view class="title">{{item.name}}</view>
                                            <view class="unit text-nowarp">{{item.spec}}</view>
                                            <view class="num">× {{item.num}}</view>
                                        </view>
                                        <view class="price">￥{{item.total_price}}</view>
                                    </view>
                                </block>
                                <view class="total-block">共 {{hebinList.length}}
                                    件，小计：￥{{Number(hebinTotalPrice).toFixed(2)}}</view>
                            </view>
                        </view>
                    </view>
                </scroll-view>
                <view class="flex weui-dialog__ft">
                    <view class="weui-dialog__btn" @click="bindMerge">
                        合并
                    </view>
                    <view class="weui-dialog__btn" @click="bindNoMerge">
                        不合并
                    </view>
                </view>
            </view>
            <view class="get-phone-pop-pay" v-if="is_pop==2">
                <view class="content-block">
                    <view class="content flex flex-y-center flex-x-center">提示</view>
                </view>
                <view class="flex-center content-tel-pay">
                    <text style="min-width: 130rpx;">订单处理成功</text>
                </view>
                <navigator open-type="redirect" :url="'../paySuccess/paySuccess?order_id='+order_id"
                    class="btm-block flex flex-nowarp flex-x-between">
                    <view form-type="submit" class="btn sub-btn">确定</view>
                </navigator>
            </view>
        </uni-popup>
        <!-- 引入组件 -->
        <!-- #ifdef MP-ALIPAY -->
        <!-- <subscribe-msg /> -->
        <!-- #endif -->
        <agree />
        <vbutton :getMenberPop='getMenberPop' @modelGetClose='modelGetClose' @maskClick="maskClick" />
    </view>
</template>

<script>
    import {
        mapState,
        mapMutations
    } from 'vuex'
    // #ifdef MP-ALIPAY
    // const {
    // 	requestSubscribeMessage
    // } = requirePlugin('subscribeMsg');
    // #endif
    import vbutton from '@/components/v-phone/v-button.vue';
    import util from "../../utils/util.js";
    import getPhone from '../../diy/module/getPhone.vue';
    import agree from '@/components/agree/agree.vue';
    let hideLoading = true;
    const app = getApp();
    export default {
        components: {
            vbutton,
            getPhone,
            agree
        },
        data() {
            return {
                showMore: false,
                carInfo: {},
                remarks: "",
                order_id: "",
				isPay:0,
                // teen_index: 0,
                wmindex: 0,
                // address: null,
                wmtimearray: ['到店即取'],
                coupon_list: [],
                coupon_id: "",
                coupon_price: 0,
                activity: '',
                voucherCode: '',
                total_price: 0,
                // #ifdef MP-WEIXIN
                check_index: 1,
                // #endif
                // #ifdef MP-ALIPAY
                check_index: 2,
                // #endif
                menber_discount: {},
                my_discount: "",
                hebin_index: 0,
                hebin_type: 1,
                // setColor: "",
                // dining_index: 1, //堂食/自提
                offline_name: "",
                offline_mobile: "",
                deliveryPrice: 0,
                is_distance: false,
                hebinList: [],
                hebinTotalPrice: 0,
                is_pop: 0,
                czList: [],
                paytype: -1,
                pay_price: 0,
                send_price: 0,
                is_yuer: 0,
                order_id: '',
                eat_people: 0, //就餐人数
                totle_eat_people: 0, //就餐的总费用
                getMenberPop: false,
                order_czid: '',
                is_status: false,
                is_status_czail: false
            }
        },

		 
         onLoad(options) {
			let _this=this;
		
		// 	let res=await _this.$http.request('xcx/system', {
		// 		store_id: this.store_id,
		// 		table_id: this.table_id,
		// 	}, true);
			
		// 	console.log("onLoad");
		// 	console.log("res",res);
		// 	this.systemInfo=res.data;
			
			 
			
			
            this.eat_people = options.eat_people ? options.eat_people : 0; //就餐人数
            this.countnumPrise(options.eat_people); //计算人数的价格
            var e = util.formatTime(new Date()),
                a = util.formatTime(new Date()).substring(0, 10).replace(/\//g, "-"),
                s = util.formatTime(new Date()).substring(11, 16);
            // console.log(e, a.toString(), s.toString());
            var o = new Date(),
                i = o.getTime(),
                n = 2 * (24 - new Date(i).getHours());
            // console.log(n, new Date(i), new Date(i).getHours(), new Date(i).getMinutes());
            for (var d = ["到店即取"], r = 1; r < n; r++) {
                i = o.getTime() + 10e5 * r;
                var l = new Date(i).getMinutes();
                l < 10 && (l = "0" + l);
                var c = new Date(i).getHours() + ":" + l;
                d.push(c);
            }
            this.wmtimearray = d;
            // 合并订单不能使用优惠劵，在订单详情再使用, 多人点餐不会提示合并订单
            if (this.systemInfo.pay_type == 2 && this.systemInfo.is_qian_many != 1) {
                this.hebintable();
                return
            }
			
			
			this.check_index = (this.systemInfo.set.is_yuer == 1 && this.systemInfo.is_vip == 1 && this.userInfo
			    .mobile) ?
			    3 : this.check_index;
			
		 
            this.paycoupons(); //获取优惠劵
        },

        onShow(e) {
			
			
			
            // 支付宝支付完成不走回调问题
            if (this.is_status) {
                let order_id = uni.getStorageSync("order_id");
                this.AlipaySuccess(order_id)
            }
            if (this.is_status_czail) {
                let info = uni.getStorageSync("order_id_info");
                if (this.check_index == 4) {
                    this.order_czid = info.order_id;
                    this.addOrder();
                } else {
                    this.CzAliOrderInfo(info)
                }
            }
			
			
            // end
            if (this.userInfo.mobile && this.systemInfo.is_vip == 1) {
                this.menber_pay()
            } else {
                this.getCarList();
            }
			
			
			
            this.MyDefaultAddress();
        },

        onReady() {
            uni.setNavigationBarColor({
                frontColor: '#ffffff',
                backgroundColor: this.setColor,
            })
            this.czlist();
        },

        computed: {
            ...mapState(['systemInfo','setColor', 'table_id', 'store_id', 'userInfo', 'teen_index', 'address',
                'dining_index', 'descFood', 'descOrder'
            ])
        },
        watch: {
            teen_index(){
                this.paycoupons()
            },
        },
        methods: {
            ...mapMutations(['SET_ADDRESS', 'SET_TEEN_INDEX', 'SET_SELFMENTION']),

            maskClick() {
                this.getMenberPop = false
            },

            modelGetClose() {
                this.getMenberPop = false
                if (this.hebin_index == 1 && this.teen_index != 2) {
                    this.addCheck();
                } else {
                    this.addOrder()
                }
            },

            modelGetPhone() {
                this.getMenberPop = true
            },

            // 初始化
            socktopentInit() {
                var datas = {
                    group: this.table_id,
                    type: 'init',
                    store_id: this.store_id,
                    table_id: this.table_id,
                }
                app.sendSocketMessage(JSON.stringify(datas)).then(res => {
                    console.log('初始化！');
                })
            },

            //根据就餐人数算价格
            countnumPrise(num) {
                this.$http.request('xcx/eat_people_time', {
                    store_id: this.store_id,
                    user_id: this.userInfo.id,
                }).then(res => {
                    if (res.code == "200") {
                        //eat_cover 单价
                        let nowprise = res.data.eat_cover || 0;
                        let zongprise = Number(nowprise) * num;
                        if (res.data.eat_open == 1) {
                            //首先判断是否开启选择人数就餐且是点餐的情况
                            //判断时间开关是否开启1开启 0关闭
                            //on_time 1超过 2没超过
                            if (res.data.eat_open_time == 1) {
                                if (res.data.on_time == 1) {
                                    this.totle_eat_people = (Math.round(zongprise * 100) / 100).toFixed(2);
                                    this.computGoodsNum()
                                }
                            } else {
                                this.totle_eat_people = (Math.round(zongprise * 100) / 100).toFixed(2);
                                this.computGoodsNum()
                            }
                        }
                    }
                }).catch((res) => {
                    uni.showToast({
                        title: res.message,
                        icon: 'none'
                    })
                });
            },

            Socket() {
                if (this.systemInfo.is_qian_many == 1 && app.globalData.readyReset == 1) {
                    app.globalData.callback = (r) => {
                        // console.log('收到服务器内容', r)
                        let res = JSON.parse(r.data);
                        if (res.type == 'clear_list') {
                            this.getCarList();
                        } else if (res.type == 'ping') {
                            return
                        } else if (res.type == 'init_list' || res.type == 'add_cart_list') {
                            this.carInfo = res;
                            this.computGoodsNum();
                        }
                    }
                }
            },

            bindScan(e) {
                // 允许从相机和相册扫码
                uni.scanCode({
                    success: (res) => {
                        var store_id = this.gettParameter(res.result, 'store_id')
                        var table_id = this.gettParameter(res.result, 'table_id')
                        this.$store.commit('SET_SYSTEM', '') //清空
                        this.$store.commit('SET_STORE_ID', store_id)
                        this.$store.commit('SET_TEEN_INDEX', 1) //重置默认
                        this.$store.commit('SET_TABLE_ID', table_id)
                        this.$store.commit('SET_CATE_ID', '')
                        this.$store.dispatch('getSystemStup', store_id);
                        this.$store.dispatch('getOpenid', store_id);
                    }
                })
            },

            gettParameter: function(url, name) {
                let val = ''
                if (url.indexOf('?' + name + '=') !== -1) {
                    val = url.split('?' + name + '=')[1].split(/&|#/)[0];
                } else if (url.indexOf('&' + name + '=') !== -1) {
                    val = url.split('&' + name + '=')[1].split(/&|#/)[0];
                }
                return val
            },

            czPay(e) {

                // #ifdef MP-WEIXIN
                var url = 'xcxweixinpay/czorder',
                    user_id = this.userInfo.id;
                // #endif
                // #ifdef MP-ALIPAY
                var url = 'xcxpay/czorder',
                    user_id = this.userInfo.user_id;
                // #endif

                // Number(systemInfo.set.charge_num)*Number(total_price)
                let pirce = this.systemInfo.set.is_charge == 1 ? Number(this.total_price) * Number(this.systemInfo.set
                    .charge_num) : 0;
                let pay_price = this.check_index == 4 ? pirce : this.pay_price;

                this.$http.request(url, {
                    store_id: this.store_id,
                    user_id: user_id,
                    pay_price: pay_price,
                    send_price: this.paytype > -1 ? this.send_price : 0,
                }).then(res => {
                    // this.list = res.data;
                    // #ifdef MP-ALIPAY
                    this.czAliPay(res.data)
                    // #endif
                    // #ifdef MP-WEIXIN
                    this.czWxPay(res.data)
                    // #endif
                }).catch((err) => {
                    uni.showToast({
                        title: err.message,
                        icon: "none"
                    })
                })
            },

            //支付宝支付
            czAliPay(info) {

                // 防止支付完成不走回调
                this.is_status_czail = true;
                uni.setStorageSync("order_id_info", info);

                my.tradePay({
                    // 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号trade_no
                    tradeNO: info.trade_no,
                    success: (res) => {
                        if (res.resultCode == 9000) {
                            // 免单充值
                            if (this.check_index == 4 && info.order_id) {
                                this.order_czid = info.order_id;
                                this.addOrder();
                            } else {
                                // 普通充值
                                this.CzAliOrderInfo(info)
                            }
                        } else if (res.resultCode == 8000 || res.resultCode == 6004) {
                            uni.showToast({
                                title: "支付结果未知，请核对",
                                icon: "none"
                            })
                        }
                    },
                    fail: (res) => {
                        uni.showToast({
                            title: '支付失败',
                            icon: 'none'
                        })
                    }
                });
            },
            // 支付宝充值
            CzAliOrderInfo(info) {
                this.is_status_czail = false
                this.$http.request('xcxpay/CzAliOrderInfo', {
                    out_trade_no: info.out_trade_no,
                    store_id: this.store_id,
                }).then(res => {
                    uni.showModal({
                        content: '余额储值成功',
                        confirmText: '确定下单',
                        showCancel: false,
                        success: r => {
                            this.addOrder();
                        }
                    })
                })
            },
            // 微信充值
            czWxPay(info) {
                wx.requestPayment({
                    timeStamp: info.timeStamp,
                    nonceStr: info.nonceStr,
                    package: info.package,
                    signType: info.signType,
                    paySign: info.paySign,
                    success: (res) => {
                        if (this.check_index == 4 && info.order_id) {
                            this.order_czid = info.order_id;
                            this.addOrder();
                        } else {
                            this.Czdiscount();
                        }
                    },
                    fail: (res) => {
                        uni.showToast({
                            title: '支付失败',
                            icon: 'none'
                        })
                    }
                })
            },

            Czdiscount() {
                this.$http.request('xcx/discount', {
                    user_id: this.userInfo.id,
                    store_id: this.store_id,
                }, "", "", hideLoading).then(res => {
                    if (Number(res.data.balance) < Number(this.total_price)) {
                        uni.showToast({
                            title: "您的余额不足，请充值后使用",
                            icon: "none"
                        })
                        return
                    }

                }).catch(err => {
                    console.log(err)
                })
            },

            choice_pay(e) {
                if (this.paytype == e) {
                    this.paytype = -1
                    return
                }
                if (this.check_index != 3) {
                    return
                }
                this.paytype = e;
                this.pay_price = this.czList[e].pay_price;
                this.send_price = this.czList[e].send_price;
            },

            czlist() {
                this.$http.request('xcx/czlist', {
                    store_id: this.store_id
                }).then(res => {
                    this.czList = res.data;
                })
            },

            // 会员充值end
            KeyName(t) {
                this.offline_name = t.detail.value;
            },

            KeyMobile(t) {
                this.offline_mobile = t.detail.value;
            },

            // 默认地址
            MyDefaultAddress() {
                if (this.teen_index != 2) {
                    return
                }
                if (this.address.id) {
                    this.getDeliveryPrice();
                } else {
                    this.$http.request('xcx/MyDefaultAddress', {
                        user_id: this.userInfo.id,
                    }, "", "", hideLoading).then(res => {
                        this.SET_ADDRESS(res.data)
                        this.getDeliveryPrice();
                    }).catch(err => {
                        console.log(err)
                    })
                }
            },

            // 获取配送费
            getDeliveryPrice() {
                this.$http.request('xcx/getDeliveryPrice', {
                    lat: this.address.lat,
                    lng: this.address.lng,
                    store_id: this.store_id,
                }, "", "", hideLoading).then(res => {
                    this.deliveryPrice = Number(res.data.delivery_price) || 0;
                    let distance = Number(res.data.distance);
                    if (distance > this.systemInfo.set.number && this.systemInfo.set.number != 0) {
                        this.is_distance = true;
                    } else {
                        this.is_distance = false;
                    }
                    this.computGoodsNum();
                }).catch(err => {
                    console.log(err)
                })
            },

            addCheck() {
                this.is_pop = 1;
                this.hebintablelist();
                this.$refs.popup.open();
            },

            // 合并
            bindMerge() {
                this.hebin_type = 2;
                this.addOrder();
                this.$refs.popup.close();
            },

            // 不合并
            bindNoMerge() {
                this.hebin_type = 1;
                this.addOrder();
                this.$refs.popup.close();
            },

            // 合并状态
            hebintable() {
                // 餐后付款pay_type==2 & this.teen_index==2外卖
                if (this.teen_index == 2) {
                    return
                }
                this.$http.request('xcx/hebintable', {
                    store_id: this.store_id, //是	string	门店id
                    table_id: this.table_id, //是	string	桌号
                }, "", "", hideLoading).then(res => {
                    this.hebin_index = res.data;
                }).catch(err => {
                    console.log(err)
                })
            },

            // 合并订单列表
            hebintablelist() {
                this.$http.request('xcx/hebintablelist', {
                    store_id: this.store_id, //是	string	门店id
                    table_id: this.table_id, //是	string	桌号
                }, "", "", hideLoading).then(res => {
                    this.hebinList = res.data;
                    for (let i of res.data) {
                        this.hebinTotalPrice += Number(i.total_price);
                    }
                }).catch(err => {
                    console.log(err)
                })
            },

            // 获取会员折扣
            menber_pay() {
                this.$http.request('xcx/discount', {
                    user_id: this.userInfo.id,
                    store_id: this.store_id,
                }, "", "", hideLoading).then(res => {
                    this.menber_discount = res.data;
                    if (res.data.discount) {
                        this.my_discount = Number(res.data.discount);
                    }
                    this.getCarList();
                }).catch(err => {
                    console.log(err)
                })
            },

            checkPay(index) {
                this.check_index = index;
                let carInfo = this.carInfo;
                if (index != 3) {
                    this.paytype = -1;
                }
                if (this.voucherCode && index !== 2) {
                    uni.showModal({
                        title: "提示",
                        content: "优惠劵状态发生变化,请重新选择优惠劵",
                        showCancel: false,
                        cancelText: '取消',
                        confirmText: '重新选择',
                        success: res => {
                            if (res.confirm) {
                                this.coupon_id = ""; //修改上一页data里面的sh参数值为100
                                this.coupon_price = 0;
                                this.activity = '';
                                this.voucherCode = '';
                                uni.navigateTo({
                                    url: `../use-coupon-list/use-coupon-list?total_price=${carInfo.total_price}&check_index=${index}&state=${this.teen_index}`
                                })
                            }
                        },
                        fail: () => {},
                        complete: () => {}
                    });
                }
            },

            bindPickerChange: function(t) {
                this.wmindex = t.detail.value;
            },

            bindDining(e) {
                this.fastTake(2, e);
            },

            selectednavbar: function(e) {
                let index = e.currentTarget.dataset.index;
                index = index == 1 ? (this.systemInfo.is_hall == 1 ? index : this.systemInfo.is_ziti == 1 ? 3 :
                    index) : index;
                this.fastTake(1, index);
            },

            // 必选商品校检
            fastTake(type, t) {
                // 切换清空优化劵
                this.coupon_id = "";
                this.coupon_price = 0;
                this.activity = '';
                this.voucherCode = '';
                this.coupon_full = '';
                // type==1 头部切换点餐外卖 2 到店自提
                this.$http.request('xcx/fastTake', {
                    store_id: this.store_id,
                    user_id: uni.getStorageSync('user_id'),
                    state: Number(t),
                }, "", true, true).then(res => {
                    this.SET_TEEN_INDEX(t);
                    this.computGoodsNum(); //计算价格当是点餐的到店取餐情况下要加多个包装费
                    if (type == 1) {
                        if (t == 2) {
                            this.MyDefaultAddress();
                        } else {
                            this.deliveryPrice = 0;
                            this.is_distance = false;
                            this.computGoodsNum();
                        }
                    }
                }).catch(err => {
                    uni.showModal({
                        title: '提示',
                        content: err.message,
                        showCancel: true,
                        cancelText: '取消',
                        confirmText: '去选择',
                        success: res => {
                            if (res.confirm) {
                                this.SET_TEEN_INDEX(t);
                                uni.navigateBack({
                                    delta: 1
                                })
                            }
                        },
                        fail: () => {},
                        complete: () => {}
                    });
                })
            },

            getWechatAddress: function(e) {
                uni.navigateTo({
                    url: '../address/address?teen_index=2'
                })
            },

            onShowMore(idx) {
				console.log(idx,this.carInfo.new_list[idx].showMore)
				this.carInfo.new_list[idx].showMore = !this.carInfo.new_list[idx].showMore;
                // this.showMore = true
            },

            //拼接图片全路径
            getImgSrc(src) {
                return this.$utils.getImgSrc(src)
            },

            paycoupons() {
                this.$http.request('xcx/payTicket', {
                    user_id: this.userInfo.id,
                    // store_id: this.store_id,
                    // is_use: this.teen_index
                }, "", "", hideLoading).then(res => { 
                    this.coupon_list = res.data;
                }).catch(err => {
                    console.log(err)
                })
            },

            getCarList() {
                if (this.systemInfo.is_qian_many == 1 && app.globalData.readyReset == 1) {
                    this.socktopentInit();
                    this.Socket();
                    // url = 'xcx/cart_lista';
                    // datas = {
                    // 	table_id: this.table_id,
                    // 	store_id: this.store_id,
                    // }
                    return
                }
                var url, datas;
                url = 'xcx/cart_list';
                datas = {
                    user_id: this.userInfo.id,
                    store_id: this.store_id,
                }
                this.$http.request(url, datas, "", "", hideLoading).then(res => {
					
					if(res.data.new_list){
						for(let i of res.data.new_list){
							i.showMore = false
						}
					}

                    this.carInfo = res.data;
                    this.computGoodsNum();
                }).catch(err => {
                    console.log(err)
                })
            },

            computGoodsNum(res) {
                let carInfo = this.carInfo,
                    my_discount = this.my_discount;
                let list = carInfo.list
                let num = 0
                for (let i in list) {
                    num += list[i].num
                }
                carInfo.carNum = num
                let price = Number(carInfo.total_price);
                let box_fee = Number(carInfo.box_fee) || 0; //包装费

                if (my_discount && my_discount > 0 && this.systemInfo.is_vip == 1 && this.userInfo.mobile) {
                    price = price * (my_discount * 0.1)
                }

                let total_num = price - this.coupon_price + this.deliveryPrice

                //如果不是店内就餐就加餐盒费
                if (this.teen_index == 2 || this.teen_index == 3) {
                    total_num += box_fee
                }

                //总价格加就餐人数
                if (this.teen_index == 1 && Number(this.totle_eat_people) > 0) {
                    total_num += Number(this.totle_eat_people)
                }

                this.total_price = (Math.round(total_num * 100) / 100).toFixed(2)
                this.carInfo = carInfo
            },

            addOrder() {
                // 重复点击
                if (!this.clickThrottle()) {
                    return
                }
                if (this.order_id) {
                    if (this.systemInfo.pay_type == 1) {
                        //先付后吃
                        // #ifdef MP-ALIPAY
                        this.aliPay(this.order_id, this.total_price)
                        // #endif
                    } else {
                        //先吃后付
                        uni.showModal({
                            content: "下单成功",
                            showCancel: false,
                            success: () => {
                                this.SET_TEEN_INDEX(1);
                                uni.navigateBack()
                            }
                        })
                    }
                    return false
                }
                let list = this.carInfo.list || []
                if (list.length == 0) {
                    uni.showToast({
                        title: '请先选择商品',
                        icon: 'none'
                    })
                    return false
                }
                let sz = []
			
                for (let i in list) {
                    sz.push({
                        name: list[i].name,
                        img: list[i].spec_image,
                        num: list[i].num,
                        money: list[i].price,
                        spec: list[i].spec,
                        goods_id: list[i].goods_id,
						packing_fee: list[i].packing_fee,
						pocket: list[i].pocket, 
                    })
                }
                let address = this.address,
                    params, state = Number(this.teen_index);

                if (state == 2 && !address.id) {
                    uni.showToast({
                        title: "地址不能为空",
                        icon: "none"
                    })
                    return
                }
                if (state == 1 && !this.table_id) {
                    uni.showToast({
                        title: "桌号不能为空",
                        icon: "none"
                    })
                    return
                }
                if (Number(this.total_price) < 0) {
                    uni.showToast({
                        title: "支付金额不能小于0",
                        icon: "none"
                    })
                    return
                }
                params = {
                    state: state, //1堂食 2外卖 3打包
                    admin_id: this.systemInfo.admin_id, //商户id
                    store_id: this.store_id, //是	string	门店id
                    total_price: this.carInfo.total_price, //是	string	总价
                    pay_price: this.total_price, //是	string	支付金额
                    table_id: this.table_id, //是	string	桌号
                    sz: JSON.stringify(sz), //商品信息
                    remark: this.remarks || '', //备注
                    user_id: this.userInfo.id, //用户id
                    type: this.hebin_type, //1不合并,2合并
                    // this.systemInfo.pay_type,   // 传type==2,  不合并传type==1	 
                    coupon_id: this.coupon_id, //优惠劵id
                    coupon_price: this.coupon_price, //优惠劵金额
                    activity: this.activity, //商家优惠劵金额
                    voucherCode: this.voucherCode, //商家劵码
                    pay_type: this.check_index == 4 ? 5 : this.check_index, //1是微信支付。2是支付宝支付。3是余额支付 4现金  5充值免单
                    delivery_price: this.deliveryPrice || 0, //外卖配送费
                    discount: this.my_discount || 0, // 会员折扣
                    box_fee: this.carInfo.box_fee, //包装费
                    eat_people: this.eat_people, //就餐人数
                    czorder_id: this.order_czid, //充值免单id
                }
                if (state == 2) {
                    params.address_id = address.id
                }
                // var myreg = /^[1][3,4,5,7,8,9,][0-9]{9}$/;
                if (params.state == 3) {
                    params.name = this.offline_name;
                    params.mobile = this.offline_mobile;
                    params.time = this.wmtimearray[this.wmindex];
                    if (!this.offline_name) {
                        uni.showToast({
                            title: "请填写自提人",
                            icon: 'none'
                        });
                        return false;
                    }
                    if (!this.offline_mobile) {
                        uni.showToast({
                            title: "请填写自提号码",
                            icon: 'none'
                        });
                        return false;
                    }
                    if (this.offline_mobile.length != 11) {
                        uni.showToast({
                            title: "联系电话格式不正确",
                            icon: 'none'
                        });
                        return false;
                    }
                }
                let subscribe = uni.getStorageSync('balance_subscribe');

                uni.showLoading({
                    title: '正在加载',
                    mask: true
                })
                var url = this.systemInfo.is_qian_many == 1 && app.globalData.readyReset == 1 ? 'xcx/addhbordera' : 'xcx/addhborder';
                this.$http.request(url, params).then(res => {
                    uni.hideLoading();
                    uni.setStorageSync("lastChoose", false)
                    this.order_id = res.data.id;
					this.isPay=res.data.isPay;
					 
					console.log(this.systemInfo.pay_type);
					console.log("state",state);
					console.log("checkIndex",this.check_index);
                    // 先付后吃pay_type==2直接下单,外卖都可以直接下单
                    if (this.systemInfo.pay_type == 1 || state == 2) {
                        if (this.check_index == 2) {
                            let that = this;
                            let entityIds = [subscribe.alipay_balance];
                            // 外卖没有取餐消息
                            if (state != 2) {
                                entityIds.push(subscribe.qucang_tid);
                            }
                            // return
                            // #ifdef MP-ALIPAY
                            // 调用方法，唤起订阅组件
                            my.requestSubscribeMessage({
                                thirdTypeAppId: that.systemInfo.alipay_appid, // 可选，isv接入场景下必填
                                entityIds: entityIds, // 模板id列表，最多3个
                                // 接收结果的回调方法
                                complete: (r) => {
                                    console.log('订阅回调', r);
                                    that.aliPay(res.data, that.total_price)
                                },
                            });
                            // #endif
                        } else if (this.check_index == 1) {
                            // #ifdef MP-WEIXIN
                            let tmplIds = [subscribe.pay_tid, subscribe.jf_tid];
                            console.log(tmplIds, "tmplIdstmplIdstmplIdstmplIdstmplIdstmplIdstmplIdstmplIdstmplIdstmplIds")
                            // 外卖没有取餐消息
                            if (state != 2 && subscribe.wechat_qucang_tid) {
                                tmplIds.push(subscribe.wechat_qucang_tid);
                            }
                            uni.requestSubscribeMessage({
                                tmplIds: tmplIds,
                                success: (r) => {
                                    console.log(r, "success")
                                },
                                complete: (r) => {
                                    console.log(r, "complete")
									if(this.isPay!=undefined && this.isPay==1){
										//已支付
										uni.redirectTo({
										    url: '/pages/paySuccess/paySuccess?order_id=' +
										        this.order_id
										})
									}else{
										this.wxPay(res.data.id, this.total_price)
									}
                                    
                                }
                            })
                            // #endif
                        } else if (this.check_index == 3) {
                            let tmplIds = [subscribe.balance_tid, subscribe.jf_tid];
                            // 外卖没有取餐消息
                            if (state != 2) {
                                tmplIds.push(subscribe.wechat_qucang_tid);
                            }
                            // #ifdef MP-WEIXIN
                            uni.requestSubscribeMessage({
                                tmplIds: tmplIds,
                                success: (r) => {
                                    console.log(r, "success")
                                },
                                complete: (r) => {
                                    console.log(r, "complete")
                                    // this.wxPay(res.data, this.total_price)
                                    this.yuer_pay(res.data)
                                }
                            })
                            // #endif
                            // #ifdef MP-ALIPAY
                            let that = this;
                            let entityIds = [subscribe.alipay_balance];
                            // 外卖没有取餐消息
                            if (state != 2) {
                                entityIds.push(subscribe.qucang_tid);
                            }
                            // 调用方法，唤起订阅组件
                            my.requestSubscribeMessage({
                                // appId: "2021xxxxx", 可选.
                                thirdTypeAppId: that.systemInfo.alipay_appid, // 可选，isv接入场景下必填
                                entityIds: entityIds, // 模板id列表，最多3个
                                // 接收结果的回调方法
                                complete: (r) => {
                                    console.log('订阅回调', r);
                                    that.yuer_pay(res.data)
                                },
                            });
                            // #endif
                        } else if (this.check_index == 4) {
                            //先吃后付
                            this.AddIntegral(res.data)
                            uni.setStorageSync("lastChoose", false) //下单成功后清除让重新选择就餐人数
                            uni.showModal({
                                content: '支付成功',
                                showCancel: false,
                                success: r => {
                                    uni.redirectTo({
                                        url: '/pages/paySuccess/paySuccess?order_id=' +
                                            res.data
                                    })
                                }
                            })
                        }
                    } else {
                        //先吃后付
                        uni.showModal({
                            content: "下单成功",
                            showCancel: false,
                            success: () => {
                                // this.SET_TEEN_INDEX(1);
                                this.$store.commit('SET_CREAT', true)
                                uni.navigateBack()
                            }
                        })
                    }

                    if (this.systemInfo.is_qian_many == 1 && app.globalData.readyReset == 1) {
                        let datas = {
                            group: this.table_id,
                            type: "clear",
                            store_id: this.store_id,
                            table_id: this.table_id,
                        }
                        app.sendSocketMessage(JSON.stringify(datas)).then(res => {
                            console.log('发送成功！');
                        })
                    }

                })
            },

            AddIntegral(order_id) {
                this.$http.request('xcx/AddIntegral', {
                    order_id,
                }).then(res => {

                })
            },

            //支付宝支付
            aliPay(order_id, money) {
                uni.showLoading({
                    title: '正在加载',
                    mask: true
                })
                this.$http.request('Xcxpay/getAliorderNo', {
                    user_id: this.userInfo.user_id,
                    money: money,
                    order_id,
                    store_id: this.store_id,
                }).then(res => {
                    uni.hideLoading();
                    let out_trade_no = res.data.out_trade_no

                    // 防止支付完成不走回调
                    this.is_status = true;
                    uni.setStorageSync("order_id", order_id);
                    my.tradePay({
                        // 调用统一收单交易创建接口（alipay.trade.create），获得返回字段支付宝交易号trade_no
                        tradeNO: res.data.trade_no,
                        success: (res) => {
                            if (res.resultCode == 9000) {
                                this.AlipaySuccess(order_id);
                                // my.alert({
                                // 	content: "订单处理成功",
                                // 	showCancle: false,
                                // 	success: () => {
                                // 		uni.navigateTo({
                                // 			url: '../paySuccess/paySuccess'
                                // 		})
                                // 	}
                                // });
                            } else if (res.resultCode == 8000 || res.resultCode == 6004) {
                                my.alert({
                                    content: "支付结果未知，请核对",
                                    showCancle: false,
                                    success: () => {
                                        uni.switchTab({
                                            url: '../index/index'
                                        })
                                    }
                                });
                            } else {
                                my.alert({
                                    content: "支付失败",
                                    showCancle: false,
                                    success: () => {
                                        this.$store.commit("SET_TABACTIVE", 2)
                                        uni.switchTab({
                                            url: '/pages/myOrderList/myOrderList?tabActive=2'
                                        })
                                    }
                                });
                            }
                        },
                        fail: (res) => {
                            my.alert({
                                content: JSON.stringify(res),
                            });
                        }
                    });

                }).catch(err => {
                    console.log(err)
                    uni.hideLoading();
                })
            },

            AlipaySuccess(order_id) {
                this.is_status = false;
                this.AddIntegral(order_id)
                uni.setStorageSync("lastChoose", false) //下单成功后清除让重新选择就餐人数
                this.is_pop = 2;
                this.order_id = order_id;
                this.$refs.popup.open();
            },

            wxPay(order_id, money) {
                uni.showLoading({
                    title: '正在加载',
                    mask: true
                })
                this.$http.request('Xcxweixinpay/pay', {
                    order_id,
                    money,
                    openid: this.userInfo.openid
                }).then(res => {
                    uni.hideLoading();
                    wx.requestPayment({
                        timeStamp: res.data.timeStamp,
                        nonceStr: res.data.nonceStr,
                        package: res.data.package,
                        signType: res.data.signType,
                        paySign: res.data.paySign,
                        success: (res) => {
                            this.AddIntegral(order_id)
                            uni.setStorageSync("lastChoose", false) //下单成功后清除让重新选择就餐人数
                            uni.showModal({
                                content: '支付成功',
                                showCancel: false,
                                success: r => {
                                    uni.redirectTo({
                                        url: '/pages/paySuccess/paySuccess?order_id=' +
                                            order_id
                                    })
                                }
                            })
                        },
                        fail: (res) => {
                            uni.showModal({
                                content: '支付失败',
                                showCancel: false,
                                success: r => {
                                    this.$store.commit("SET_TABACTIVE", 2)
                                    uni.switchTab({
                                        url: '/pages/myOrderList/myOrderList?tabActive=2'
                                    })
                                }
                            })

                            // uni.showToast({
                            // 	title: '支付失败',
                            // 	icon: 'none'
                            // })

                        }
                    })
                }).catch((err) => {
                    uni.hideLoading();
                })
            },

            // 余额支付
            yuer_pay(order_id) {
                uni.showLoading({
                    title: '正在加载',
                    mask: true
                })
                // #ifdef MP-WEIXIN
                var is_type = 1;
                // #endif
                // #ifdef MP-ALIPAY
                var is_type = 2;
                // #endif
                this.$http.request('xcx/yuer_pay', {
                    order_id,
                    user_id: this.userInfo.id,
                    is_type,
                }).then(res => {
                    uni.hideLoading();
                    this.AddIntegral(order_id)
                    uni.setStorageSync("lastChoose", false) //下单成功后清除让重新选择就餐人数
                    uni.showModal({
                        content: '支付成功',
                        showCancel: false,
                        success: r => {
                            uni.redirectTo({
                                url: '/pages/paySuccess/paySuccess?order_id=' + order_id
                            })
                        }
                    })
                }).catch(err => {
                    uni.hideLoading();
                    uni.showModal({
                        content: err.message,
                        showCancel: false,
                        success: r => {
                            this.$store.commit("SET_TABACTIVE", 2)
                            uni.switchTab({
                                url: '/pages/myOrderList/myOrderList?tabActive=2'
                            })
                        }
                    })
                })
            }
        }
    }
</script>

<style lang="scss">
    @import url("./creatOrder.css");
</style>
