notification.js 4.7 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        config: function () {
            var notification_index = new Vue({
                el: "#notification-index",
                data() {
                    return {
                        tipCloseFlag: true,
                        notificationDialog: false,
                        notificationData: [],
                        notificationForm: {},
                        editIndex:null,
                        editPlatform:null
                    }
                },
                mounted() {
                    this.getnotificationData();
                },
                methods: {
                    getnotificationData(){
                        let that=this;
                        Fast.api.ajax({
                            url: 'groupon/notification/config',
                            type:'GET',
                            loading: true,
                            data: {}
                        }, function (ret, res) {
                            that.notificationData=res.data;
                            return false;
                        })
                    },
                    tipClose() {
                        this.tipCloseFlag = false;
                    },
                    changeStatua(platform, event, name, status) {
                        let that = this;
                        Fast.api.ajax({
                            url: 'groupon/notification/set_status',
                            loading: true,
                            type: "POST",
                            data: {
                                platform: platform,
                                event: event,
                                name: name,
                                status: status
                            }
                        }, function (ret, res) {
                            that.getnotificationData();
                        })
                    },
                    fieldDel(index){
                        this.notificationForm.fields.splice(index,1)
                    },
                    notificationClose(type) {
                        let that = this;
                        if(this.editPlatform!='email'){
                            that.notificationForm.template_id=that.notificationForm.template_id.replace(/\s*/g,"");
                        }
                        if (type == 'yes') {
                            let content=JSON.stringify(that.notificationForm)
                            if(this.editPlatform=='email'){
                                content=$('#c-content').val()
                            }
                            Fast.api.ajax({
                                url: 'groupon/notification/set_template',
                                loading: true,
                                data: {
                                    platform: that.editMsg.platform,
                                    event: that.editMsg.event,
                                    name: that.editMsg.name,
                                    content: content
                                }
                            }, function (ret, res) {
                                that.getnotificationData();
                                that.notificationDialog = false;
                                that.notificationForm = {};
                                that.editMsg={};
                            })
                        } else {
                            that.notificationForm = {};
                            that.editMsg={};
                            that.notificationDialog = false;
                        }
                    },
                    edit(index, type) {
                        this.editMsg=this.notificationData[index][type];
                        this.notificationForm = JSON.parse(JSON.stringify(this.notificationData[index][type].content_arr));
                        this.editPlatform=type;
                        if(this.editPlatform=='email'){
                            this.$nextTick(callback=>{
                                Controller.api.bindevent();
                                $('#c-content').html(this.notificationData[index][type].content)
                            })
                        }
                        this.notificationDialog = true;
                    },
                    addfield() {
                        this.notificationForm.fields.push({
                            'name': '',
                            'template_field': '',
                            'value': '',
                        });
                    },
                },
            })
        },
    };
    return Controller;
});