feedback.page.js 2.42 KB
/**
 * 个人中心--意见反馈
 * @author: Lixia Zhang<lixia.zhang@yoho.cn>
 * @date: 2016/07/20
 */
import $ from 'jquery';
import tip from 'common/tip';
import yoho from 'yoho';
import interceptClick from 'common/intercept-click';
import HeaderBox from 'component/header.vue';
import Vue from 'vue';

new Vue({
    el: '#header',
    render: function(h) {
        let self = this;

        return h(HeaderBox, {
            props: {
                title: '意见反馈'
            },
            scopedSlots: {
                right: function() {
                    return h('span', {
                        'class': { //eslint-disable-line
                            'right-btn': true
                        },
                        on: {
                            click: self.submitFeed
                        }
                    }, '提交');
                }
            }
        });
    },
    methods: {
        submitFeed() {
            var suggestText = $('#suggest-textarea').val(),
                textReg = /\S+/;

            if (!textReg.test(suggestText)) {
                tip('意见不能为空');
                return;
            }

            $('#suggest-textarea').blur();
            if (yoho.isLogin()) {
                this.postData(suggestText);
            } else {
                yoho.goLogin('', () => {
                    this.postData(suggestText);
                });
            }
        },
        postData(suggestText) {
            $.ajax({
                type: 'post',
                url: '/me/save-feedback',
                data: {
                    content: suggestText,
                }
            }).then(function(data) {
                if (data.code === 200) {
                    tip('提交成功');
                    setTimeout(() => {
                        yoho.goBack();
                    }, 2000);
                } else {
                    tip('提交失败~');
                }
            }).fail(function() {
                tip('网络错误~');
            });
        }
    }
});

$(() => {
    setTimeout(() => {
        const header = Object.assign({}, interceptClick.defaultTitleMap[3]);

        header.title.des = '意见反馈';
        header.right = {
            des: '提交',
            action: 'saveFeedback'
        };
        yoho.updateNavigationBar({
            header: header,
            url: location.origin + '/me/feedback'
        });
    }, 200);
});