import API from 'API'
import lib from 'lib'


const Api = new API();

export default {
    data() {
        return {
            showReasonList: false,
            reasonMap: this.$store.state.reasonMap,
            reason:"",
            text:"",
            fid: '',                     //板块id
            tid: '',                     //主题id
            topiclist: '',               //帖子id
            formhash: '',                //提交参数 app提供
            apiUrl: {
                delete: '/api/mobile/?module=topicadmin&action=delpost&version=2',
                banpost: '/api/mobile/?module=topicadmin&action=banpost&version=2&banned=1',
                bump: '/api/mobile/?module=topicadmin&action=bump&version=2',
                down: '/api/mobile/?module=topicadmin&action=down&version=2',
                unbanpost: '/api/mobile/?module=topicadmin&action=banpost&version=2&banned=0'
            },
            // apiUrl: '/api/mobile/?module=topicadmin&action=delete&version=2',    //接口链接
            type:"delete"
        }
        
    },
    mounted () {
        this.type = lib.getParam('type') || 'delete'
        switch (this.type) {
            case 'delete' : lib.setTitle('删除帖子')  ; break;
            case 'banpost' : lib.setTitle('屏蔽帖子')  ; break;
            case 'bump' : lib.setTitle('上升帖子')  ; break;
            case 'down' : lib.setTitle('下沉帖子')  ; break; 
            case 'unbanpost' : lib.setTitle('解除')  ; break;             
                        
        }
        this.fid = lib.getParam('fid') || ''
        this.tid = lib.getParam('tid')
        this.topiclist = lib.getParam('topiclist')
        this.formhash = lib.getParam('formhash')
    },

    methods: {
        submit() {
            var param = {
                fid: this.fid,
                tid: this.tid,
                topiclist: this.topiclist,
                formhash: this.formhash,
                reason: this.text,
                modsubmit: 'yes',
            }
            if(lib.getParam('first')) {
                param.first = lib.getParam('first')
            }
            
            Api.postData(this.apiUrl[this.type], param).done( ret => {
                if(ret.Message.messagestr) {
                    lib.showDialog(ret.Message.messagestr)
                }else {
                    lib.showDialog('未知错误')
                    console.log(ret)
                }
                
                
                
            }).fail( ret => {
                lib.showDialog(ret.Message.messagestr)
                
                //提示错误信息
                console.log(ret)
            })
        },

        selectReason(reason) {
            this.reason = reason
            this.showReasonList = false            
        },
        
    },
    computed: {

    },
    watch: {
        reason (cur, old) {
            if(this.reason) {
                this.text = this.reason
            }else{
                this.text = ''
            }
        }
    }
}