<template src="./template.html">

</template>

<script>
    import util from "@/utils/util";
    import footTemplate from "../footTemplate.vue";
    import { loginService } from "@/services";
    import { Toast } from "mint-ui";
    export default {
        props:{
            switchOn:Boolean,
            perviewOn:Boolean,
            updateData:String,
        },
        data() {
            // var serverUrl = 'static/temp/template2/';
            var serverUrl = 'http://skyforest.static.elab-plus.com/temp/template2/';
            return {
                tel:'',  //项目关联手机号
                appcodeUrl:'',
                customerId:'',
                uploading:false,
                isSend:'', //是否跟顾问聊过天
                disabled:false,
                isshow:true,
                serverUrl:serverUrl,
                placeholder1:'这是一个超大的标题',
                placeholder2:'请在这里输入内容',
                placeholder3:'标题',
                obj:{
                    text1:'',
                    text101:'',
                    text2:'',
                    text3:'',
                    text4:'',
                    text5:'',
                    text6:'',
                    text7:'',
                    text8:'',
                    text9:'',
                    text10:'',
                    text11:'',
                    text12:'',
                    text13:'',
                    text14:'',
                    text15:'',
                    text16:'',
                    text17:'',
                    text18:'',
                    text19:'',
                    logoUrl:`${serverUrl}logo.png`,
                    picUrl1:`${serverUrl}pic1.png`,
                    picUrl2:`${serverUrl}pic3.png`,
                    picUrl3:`${serverUrl}pic4.png`,
                    picUrl4:`${serverUrl}pic5.png`,
                    picUrl5:`${serverUrl}pic6.png`,
                    picUrl6:`${serverUrl}pic7.png`,
                    picUrl7:`${serverUrl}pic8.png`,
                    picUrl8:`${serverUrl}pic9.png`,
                    picUrl9:`${serverUrl}pic10.png`,
                }

            }
        },
        components:{
            footTemplate
        },
        mounted() {
            this.customerId = localStorage.getItem('localCustomerId');
            this.appcodeUrl=localStorage.getItem('_appQrcode');
            this.tel=localStorage.getItem('_projectTel');
               if(this.updateData){
                   this.obj =JSON.parse( this.updateData)
               }

        },
        watch:{
            switchOn(val){
                if(val){

                    // console.log('1111111',this.headerTitle1)
                    // console.log('2222222222',this.obj)
                    this.$emit('com',this.obj)
                }
            },
            perviewOn(val){
                    this.disabled=val;
                    this.isshow=!val;
            },
            updateData(val){
                if(val){
                    val=JSON.parse(val);
                    this.obj = val;
                }
            }
        },
        methods: {
            async doUpload(evt,val){
                console.log(val)
                let files=evt.target.files;
                // if(files.length===0){
                //     Toast('请选择需要上传的图片');
                //     return
                // }
                let file = files[0];
                if(!file){
                    return false;
                }
                if(file.size > 0 && file.size > 5242880){
                    Toast('请小于5M的图片');
                    return
                }
                this.uploading=true;
                let form = new FormData();
                form.append('type','qiniu_upload');
                form.append('folder','template');
                form.append('uploadFile',file)
                form.append('fileName',file.name)
                let result=await loginService.uploadFile(form);
                console.log(result,'gggggg')
                if(result.data.success){
                    this.uploading=false;
                    // console.log(result);
                    console.log(this.obj[val])
                    this.obj[val]=result.data.single.filepath;
                    console.log(this.obj, this.obj[val])
                    // console.log(this.Imgurl)
                    Toast('图片上传成功')
                }else{
                    Toast('图片上传失败');
                }
            },
        }
    }
</script>

<style lang="scss" scoped>
  @import "./style.scss"
</style>
