<template>
    <app-layout headerBackgroundColor="#F6F6F6" title="确认订单" textColor="dark" backgroundColor="#F6F6F6">
        <view class="tips-container">
            <widget-tips text="保险公司承保，人身财产，双重保障，下单无忧！" />
        </view>
        <view class="create-order-container">
            <view class="form-widget-group">
                <view class="widget-item" @click="selectAddress">
                    <text class="iconfont icon-dingwei icon"></text>
                    <text class="title limit-line clamp-1">
                        {{ addressText ? addressText : "请选择上门地址" }}
                    </text>
                    <text class="iconfont icon-jinru more"></text>
                </view>
                <view class="widget-item">
                    <text class="iconfont icon-shijian icon"></text>
                    <picker mode="date" :value="datetime" @change="bindDateChange" class="picker">
                        <text class="title limit-line clamp-1">
                            {{ datetime ? datetime : "选择期望上门时间" }}
                        </text>
                    </picker>
                    <text class="iconfont icon-jinru more"></text>
                </view>
            </view>
            <view class="service-view">
                <service-preview-item class="service-item" v-for="(item, idx) in serviceList" :key="idx" :data="item" />
            </view>
            <view class="insurance-box">
                <service-insurance :insurance="insurance" @change="changeInsuranceState" />
            </view>
            <view class="demand">
                <text class="title">留言</text>
                <textarea
                    class="text-area"
                    v-model="message"
                    placeholder="补充描述您的需求，或其他特殊情况"
                    placeholder-class="order-placeholder"
                />
            </view>
            <view class="agreement-container">
                <agreement :agree="agree" @change="changeAgreeState" />
            </view>
        </view>
        <view class="bottom-components" :style="{ bottom: config.safeAreaInsets.bottom + 'px' }">
            <text class="price">¥306.00</text>
            <view class="pay" @click="pay">
                <div class="text">去支付</div>
            </view>
        </view>
    </app-layout>
</template>

<script>
import AppLayout from "@/components/layout/layout";
import ServicePreviewItem from "@/components/service/preview-item";
import Agreement from "@/components/auth/agreement";
import WidgetTips from "@/components/widgets/tips";
import ServiceInsurance from "@/components/service/insurance";
import { mapState } from "vuex";
export default {
    name: "order-create",
    data() {
        return {
            addressId: 0,
            addressText: "",
            datetime: "",
            message: "",
            insurance: false,
            agree: false,
            serviceList: [
                {
                    id: 2,
                    name: "空调安装",
                    icon: require("@/static/temp/cate/1.png"),
                    buyNumber: 1,
                },
                {
                    id: 3,
                    name: "空调拆卸",
                    icon: require("@/static/temp/cate/2.png"),
                    buyNumber: 1,
                },
            ],
        };
    },
    components: {
        AppLayout,
        ServicePreviewItem,
        Agreement,
        WidgetTips,
        ServiceInsurance,
    },
    computed: {
        ...mapState({
            config: (state) => state.system.config,
        }),
    },
    onLoad() {},
    onShow() {},
    onReady() {},
    onReachBottom() {},
    onPullDownRefresh() {},
    methods: {
        bindDateChange(e) {
            this.datetime = e.detail.value;
        },
        selectAddress() {
            const that = this;
            this.$utils.toPage("/pages/address/address?openType=choose&id=" + that.addressId, {
                events: {
                    setAddress(address) {
                        that.addressId = address.id;
                        that.addressText = address.address + address.detail;
                    },
                },
            });
        },
        selectDateTime() {
            console.log("选择时间");
        },
        changeInsuranceState(state) {
            this.insurance = state;
        },
        changeAgreeState(state) {
            this.agree = state;
        },
        pay() {
            if (!this.agree) {
                uni.showToast({
                    title: "请先阅读并同意《熊熊安装服务协议》《隐私政策》",
                    icon: "none",
                });
                return;
            }
        },
    },
};
</script>

<style lang="less" scoped>
.tips-container {
    width: 710rpx;
    margin: 0 auto;
}
.create-order-container {
    width: 100%;
    margin-top: 16rpx;
    padding-bottom: 120rpx;
}
.service-view {
    margin-top: 16rpx;
    padding: 24rpx 40rpx;
    background-color: #ffffff;
    .service-item {
        display: block;
        margin-top: 28rpx;
    }
    .service-item:first-child {
        margin-top: 0;
    }
}
.insurance-box {
    width: 100%;
}
.demand {
    width: 100%;
    box-sizing: border-box;
    padding: 38rpx 40rpx;
    .title {
        font-size: 30rpx;
        font-weight: bold;
        color: #010101;
    }
    .text-area {
        width: 100%;
        height: 130rpx;
        box-sizing: border-box;
        background-color: #ffffff;
        padding: 24rpx;
        font-size: 26rpx;
        color: #333333;
        margin-top: 12rpx;
        border-radius: 10rpx;
    }
}
.agreement-container {
    width: 100%;
    box-sizing: border-box;
    padding: 0 40rpx 40rpx 40rpx;
}
.bottom-components {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 750px;
    width: 100%;
    height: 100rpx;
    margin: 0 auto;
    background-color: #ffffff;
    box-sizing: border-box;
    padding: 0 40rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .price {
        font-size: 42rpx;
        font-weight: bold;
        color: #ec7655;
    }
    .pay {
        width: 223rpx;
        height: 71rpx;
        background: #8194f2;
        border-radius: 31rpx;
        text-align: center;
        .text {
            line-height: 71rpx;
            font-size: 32rpx;
            font-weight: bold;
            color: #ffffff;
        }
    }
}
.form-widget-group {
    .widget-item {
        background-color: #ffffff;
    }
}
</style>