import test from '@/utils/test';
import notice from "@/utils/notice/index";
export default {

    methods:{

        submit(){
            if (this.submitStatus) return ;
            this.routerLogin(()=>{
                if (this.submitStatus) return null;

                test.verificationPromise(this.inputData,true).then((data)=>{

                    let imageObject = {};
                    this.inputData.map((item)=>{
                        if (item.component==='upload' && data[item.key] && data[item.key].length >= 0) {
                            imageObject[item.key] = data[item.key];
                        }
                    });

                    this.openSubmitLoading();
                    if (Object.keys(imageObject).length > 0 ) {
                        this.uploadImageAll(imageObject).then((imageData)=>{
                            data = {
                                ...data,
                                ...imageData
                            }
                            return this.submitTarget(data);
                        }).catch(()=> this.closeSubmitLoading('图片上传失败'));
                    } else {
                        this.submitTarget(data);
                    }

                });
            });

        },

        submitTarget(data){



            return this.$request({
                url:'user/feedback',
                data,
                token:true,
                message:2,
                failMessage:true,
                loading:'提交中',
                next:({status})=> this.submitStatus = status
            }).then((data)=>{
                if (data.isSuccess) {
                    notice.trigger('setup',{
                        toast:data.msg
                    });

                    this.$router.navigateBack();
                }
            })

        }



    }

}