<template>
    <view class="container">
        <uni-section title="基础信息" type="line">
            <uni-card :is-shadow="false">
                <view class="uni-body">
                    <view>车辆：{{order.car_title}} -- {{order.car_no}}</view>
                    <view>计划日期：{{order.date_plan}}</view>
                    <view>起运地：{{order.from_province}}-{{order.start_city}} =>
                        目的地：{{order.to_province}}-{{order.aim_city}}</view>
                </view>
            </uni-card>
        </uni-section>

        <uni-section title="联系信息" type="line">
            <uni-card :is-shadow="false">
                <view class="uni-body">
                    <view>
                        联系人：{{order.from_name}}
                    </view>
                    <view>
                        联系电话：{{order.from_mobile}}
                    </view>
                    <view>
                        接待员：{{order.receptionist}}
                    </view>
                </view>
            </uni-card>
        </uni-section>

        <uni-section title="费用信息" type="line">
            <uni-card :is-shadow="false">
                <view class="uni-body">
                    <view>{{order.price}} </view>
                </view>
            </uni-card>
        </uni-section>

        <uni-section title="我的备注" type="line">
            <uni-card :is-shadow="false">
                <view class="uni-body">
                    <view>{{order.remark}} </view>
                </view>
            </uni-card>
        </uni-section>

        <uni-section title="操作提示" type="line">
            <uni-card :is-shadow="false">
                <view class="uni-body">
                    <view>详情页首次打开时需要联网搜索运单信息；</view>
                    <view>打开过一次的运单信息将会缓存在APP内一段时间，在这期间即使手机没有网络也能查看</view>
                    <view>如果需要查看该运单的最新信息，可通过下拉本页面进行刷新（手机需要联网）</view>
                </view>
            </uni-card>
        </uni-section>
    </view>
</template>

<script>
    import config from "@/config/ctms.config.js";
    import ctms from '@/apis/ctms/index.js';
    export default {
        data() {
            return {
                userinfo: {},
                oid: 0,
                order: {
                    id: 1,
                    car_id: 1,
                    car_number: '车牌号',
                    car_title: '车型号',
                    start_city: "起运城市",
                    from_province: '起运省份',
                    aim_city: "目的城市",
                    to_province: '目标省份',
                    signdate: '下单日期',
                    car_extra: '随车物品',
                    checker: '验车人',
                    receiver_name: '收车人姓名',
                    receiver_mobiles: '收车人电话',
                    sender_name: '发车人姓名',
                    sender_mobiles: '发车人电话',
                },
                h5_url: '',
            }
        },
        methods: {
            getOderDetail: function(cache = null) {
                /* cache 是否读取缓存 */
                var _that = this;
                return ctms.orderpre.detail(this.oid, cache).then((res) => {
                    if (res) {
                        _that.order = res;
                        uni.showToast({
                            title: "查询完成!",
                            icon: "success"
                        });
                        uni.stopPullDownRefresh();
                        return true;
                    } else {
                        return false;
                    }
                });
            },
            callTo(tel) {
                uni.makePhoneCall({
                    phoneNumber: tel
                })
            }
        },
        onLoad(option) {
            this.oid = option.oid;
            if (!this.getOderDetail(true)) this.getOderDetail(false);
        },
        onShow: function() {

        },
        onPullDownRefresh() {
            this.getOderDetail();
            uni.stopPullDownRefresh();
        },
        //标题栏按钮响应,仅在APP-PLUS下支持
        onNavigationBarButtonTap(e) {
            //#ifdef APP-PLUS
            uni.shareWithSystem({
                summary: '运单【 ' + this.order.sn + ' 】摘要：' + this.order.signdate + '，由' + this.order
                    .from_province + this.order.start_city + '-->发往-->' + this.order.to_province + this.order
                    .aim_city + "的车辆：" + this.order.car_title + "--" + this.order.car_number + "。点击链接可查阅更多信息",
                href: this.h5_url + "?oid=" + this.oid,
                success() {
                    // 分享完成，请注意此时不一定是成功分享
                },
                fail() {
                    // 分享失败
                }
            })
            //#endif
            //#ifdef H5
            var summary = '运单【 ' + this.order.sn + ' 】摘要：' + this.order.signdate + '，由' + this.order
                .from_province + this.order.start_city + '-->发往-->' + this.order.to_province + this.order
                .aim_city + "的车辆：" + this.order.car_title + "--" + this.order.car_number + "。点击链接可查阅更多信息:" + this
                .h5_url + "?oid=" + this.oid;
            uni.setClipboardData({
                data: summary
            })
            //#endif
        }
    }
</script>

<style>
    @import url("detail.css");
</style>