const WxParse = require('../../wxParse/wxParse.js')
const $ = global

new $.Page({
    onLoad() {
        var article = '<div>我是富文本</div>'
        /**
         * WxParse.wxParse(bindName , type, data, target,imagePadding)
         * 1.bindName绑定的数据名(必填)
         * 2.type可以为html或者md(必填)
         * 3.data为传入的具体数据(必填)
         * 4.target为Page对象,一般为this(必填)
         * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
         */
        WxParse.wxParse('article', 'html', article, this, 5)
    },
    bookServer() {
        const {
            name,
            phone,
            address,
            notes,
            expectedDate,
            serviceDate
        } = this.data;
        if (!name || !phone || !address || !expectedDate || !serviceDate) {
            return $.wx.showToast({
                title: '请把信息填写完整'
            });
        }
        if (!this._isPhone(phone)) {
            return $.wx.showToast({
                title: '请输入正确的手机号码'
            });
        }
        $.wx.showToast({
            title: '加载中'
        }, 'loading');
        $.request('maternity_matron_order/store', 'POST', {
            level: '金牌月嫂',
            expected_date: expectedDate,
            special_demand: notes || '特殊需求',
            server_time: serviceDate,
            address,
            contact: name,
            phone
        }).then((res) => {
            $.wx.hideToast('loading');
            $.router.goto({
                path: '/pages/order/index',
                type: $.ROUTER_TYPE.SWITCH_TAB
            });
        });
    }
})