<template>
  <div>
    <el-button type="default" size="mini" @click="dialogFormVisible = true">新 建</el-button>
    <el-dialog title=" 新建跟进动态" width="600px" append-to-body :visible.sync="dialogFormVisible">
      <el-form :model="form" ref="form" label-position="top" label-width="80px">
        <el-form-item label="跟进动态" prop="content">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 18 }" v-model="form.content" placeholder="请输入跟进动态" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <upload
            ref="upload"
            :folderid="folderid"
            @onSuccess="onSuccess"
            :bindData="bindData"
            type="button">
          </upload>
          <!-- <previewImage :image="{}" :deletebtn="true"></previewImage> -->
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="warning" size="small" @click="submitLog">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import upload from '@/components/upload/preview_upload.vue'
import previewImage from '@/components/previewImage/index.vue'
export default {
  props:['ownertable'],
  components:{
    upload,
    previewImage
  },
  data () {
    return {
      dialogFormVisible:false,
      form:{
        content:''
      },
      bindData:{},
      folderid:JSON.parse(sessionStorage.getItem('folderid')).appfolderid,
      attachmentids:[]
    }
  },
  
  methods:{
    onSuccess(res) {
      this.attachmentids = res.data.attachmentids
    },
    async submitLog () {
      const res = await this.$api.requested({
        "id": 20220930121601,
        "content": {
          "sys_datafollowupid":0,
            "ownertable":this.ownertable,
            "ownerid":this.$route.query.id,
            "type":"",
            "content":this.form.content
        }
      })
      this.tool.showMessage(res,()=>{
        this.bindData = {
          "ownertable": 'sys_datafollowup',
          "ownerid": res.data.sys_datafollowupid,
          "usetype": 'default',
        }
        this.dialogFormVisible = false
        this.$refs['form'].resetFields();
          
        this.$refs['upload'].toUpload()
        this.$emit('onSuccess')
      })
    },
    onSuccess() {
      this.$emit('onSuccess')
      this.dialogFormVisible = false
    }
  }
}

</script>
<style>
</style>
<style scoped>

</style>