
import API from 'API'
import lib from 'lib'
import $ from 'jquery'


const Api = new API();


export default {
    data() {
        return {
            reason: "",                                         //警告原因
            showReasonList: false,
            text : '',                                           //原因文本内容
            radio : '1',                                        //解除或警告                     
            fid: '',                                            //板块id
            tid: '',                                            //主题id
            topiclist: [],                                      //帖子id
            formhash: '',                                       //提交参数 app提供
            userInfo: {author:"",warn_count:""},                //获取操作对象用户信息
            apiUrl: '/api/mobile/?module=topicadmin&action=warn&version=2',    //接口链接
            reasonMap : this.$store.state.reasonMap,
            
        }
    },
    mounted () {
        lib.setTitle('警告用户')
        this.fid = lib.getParam('fid') || ""
        this.tid = lib.getParam('tid')
        this.topiclist = lib.getParam('topiclist')
        this.formhash = lib.getParam('formhash')
        let self= this
        //获取用于信息
        let param = {
            get_warn : 1,
            fid: this.fid,
            tid: this.tid,
            topiclist: this.topiclist
        }
        Api.postData(this.apiUrl, param).done( ret => {
            // if(ret.Message.messageval != 'admin_succeed') {
            //     lib.showDialog(ret.Message.messagestr)
            // }
            this.userInfo.author = ret.Variables.author
            this.userInfo.warn_count = ret.Variables.warn_count
        }).fail( ret => {
            //提示错误信息
            console.log(ret.statusText)
        })
        
    },

    methods: {
        submit() {
            let param = {
                fid: this.fid,
                tid: this.tid,
                topiclist: this.topiclist,
                formhash: this.formhash,
                warned: this.radio,
                reason: this.text,
                modsubmit: 'yes',
            }
            Api.postData(this.apiUrl, param).done( ret => {
                 //判断状态
                 lib.showDialog(ret.Message.messagestr)
                
            }).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 = ''
            }
        }
    }
}