<template>
    <view>
        <view v-if="'' == invoice_info.is_company" class="no_content">
            <image class="img" src="/static/images/ui/none.png" />
            <view class="warn">您目前还没有添加任何发票抬头信息</view>
            <button class="_button" @tap="_nav">前往填写开票信息</button>
        </view>
        <block wx:else>
            <view class="_container">
                <view class="line">
                    <view class="title">发票抬头</view>
                    <view class="content"></view>
                    {{ invoice_info.invoice_title }}
                </view>
                <view class="line" v-if="invoice_info.is_company == 1">
                    <view class="title">纳税人识别号</view>
                    <view class="content"></view>
                    {{ invoice_info.nsrsbh }}
                </view>
                <view class="line">
                    <view class="title">发票接收邮箱</view>
                    <view class="content"></view>
                    {{ invoice_info.email }}
                </view>
            </view>
            <button class="_button" @tap="_confirm">确认开票</button>
        </block>
    </view>
</template>

<script>
// pages/user/invoice/make_invoice/make_invoice.js
import { http } from '../../../../utils/util';
export default {
    data() {
        return {
            invoice_info: {
                is_company: ''
            }
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
       let order_no = options.order_no;
       http('/api/v1/invoice-title', 'post').then((res) => {
           res.order_no = order_no;
           this.setData({
               invoice_info: res
           });
       });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {

        _nav() {
            wx.navigateTo({
                url: '/pages/user/invoice/invoice_edit/invoice_edit_newMake'
            });
        },

        _confirm: function () {
            let data1 = this.invoice_info;

            if (data1.is_company == 0) {
                data1 = {
                    is_company: data1.is_company,
                    invoice_title: data1.invoice_title,
                    email: data1.email,
                    order_no: data1.order_no
                };
            }

            uni.showModal({
                content: '是否确认开票',
				confirmColor:"#FF333",
                success(res) {
                    if (res.confirm) {
                        http('/api/v1/invoice-add', 'post', data1).then((res) => {
                            uni.navigateBack();
                            var pages = getCurrentPages(); //获取页面栈

                            if (pages.length > 1) {
                                //上一个页面实例对象
                                var prePage = pages[pages.length - 2]; //调用上一个页面的onShow方法

                                prePage.onLoad({});
                            }

                            uni.showToast({
                                title: '开票成功',
                                icon: 'success',
                                duration: 2000
                            });
                        });
                    } else {
                        if (res.cancel) {
                            //      console.log('用户点击取消')
                        }
                    }
                }
            });
        }
    }
};
</script>
<style>
._container {
    background: #fff;
}
._container .line {
    display: flex;
    justify-content: space-between;
    border-bottom: 2rpx solid #dddddd;
    align-items: center;
    padding: 30rpx 0;
    margin: 0 30rpx;
    font-size: 28rpx;
}
._button {
    position: fixed;
    bottom: 100rpx;
    width: 312rpx;
    background: linear-gradient(90deg, #ff4284 0%, #ff1d42 100%);
    border-radius: 44rpx;
    color: #fff;
    font-size: 28rpx;
    left: 50%;
    transform: translate(-50%, 0);
}
</style>
