import inputData from '../data/input';
import verification from '$utils/verification';
import {InstructionsMessageType} from "$utils/request";
export default <LibMixins>{

    data(){
        return {
            inputData:inputData(),
            controlData:[]
        }
    },

    methods:{

        getReport(){
            return this.$request({
                url:'user_report/report_type_list',
                token:true,
                cache:true
            }).then((data)=>{
                this.controlData = data.data.map((item)=>{
                    return {
                        label: item.type_name,
                        value: item.id
                    }
                });

                if (this.controlData[0]) {
                    this.inputData[0].value = this.controlData[0].value;
                }

            })
        },

        submitVerify(callback){
             return verification.verificationPromise(this.inputData,true).then(callback);
        },

        submit(obj){

            let data = obj.data;

            if(data.image) {
                this.$refs.upload.triggerUploadPromise(data.image).then((resultData)=>{
                    data.image= resultData.data;
                    return this.submitPromise(data,obj);
                }).catch(obj.fail);
            } else {
                return this.submitPromise(data,obj);
            }

        },

        submitPromise(data,obj){
            data.to_uid  = this.uid;
            this.$request({
                url:'user_report/user_report',
                data,
                token:true,
                message:true
            }).then((data)=>{
                obj.none();
                if (data.isSuccess) {
                    this.close();
                }
            }).catch(obj.fail);
        }
    },

    created(){
        this.getReport();
    }

}
