logistics.vue 2.23 KB
<template>
    <div class="edit-logistics-page">
        <form class="edit-logistics">
            <label @click="companylist">
                选择快递公司<input class="company-val" type="text" value="{{company_name}}" readonly>
                <span class="icon icon-right"></span>
            </label>
            <label>
                快递单号
                <input class="num" type="number" v-model='num'>
            </label>
        </form>
        <div class="submit" @click="submit">确认</div>
    </div>
</template>

<script>
    const $ = require('jquery');
    const tip = require('common/tip');

    module.exports = {
        props: ['company_id', 'company_name'],
        data() {
            return {
                num: '',
            };
        },
        methods: {
            companylist: function() {
                this.$dispatch('changeView', {
                    view: 'logisticsCompany'
                });
            },
            submit: function() {
                if (!this.company_name) {
                    tip('请选择快递公司');
                    return false;
                }
                if (!this.num || !/^[0-9]*$/.test(this.num)) {
                    tip('请输入正确的快递单号');
                    return false;
                }

                $.ajax({
                    method: 'POST',
                    url: '/home/save-logistics',
                    data: {
                        company_id: this.company_id,
                        company_name: this.company_name,
                        num: this.num
                    }
                }).then(function(res) {
                    if ($.type(res) !== 'object') {
                        res = {};
                    }
                    if (res.code !== 200) {
                        tip(res.message || '网络出了点问题~');
                    } else {
                        // todo 跳转到什么页面呢?
                        // window.location.href
                    }
                }).fail(function() {
                    tip('网络错误');
                });
                return false;
            }
        }
    };
</script>

<style>
    @import "../../../scss/home/_logistics.css";
</style>