<template>
  <div class="follow" style="margin-right:10px">
    <el-button size="mini" @click="followBtn" :disabled="disabled">跟进</el-button>
    <el-drawer title="线索跟进" append-to-body :visible.sync="dialogVisible" size="30%" :before-close="handleClose">
      <div class="drawer__panel">
        <el-form :model="param" :rules="rules" ref="ruleForm" label-width="110px" class="demo-ruleForm"
          label-position="right">
          <el-form-item label="跟进时间">
            <el-date-picker v-model="timer" type="date" format="yyyy-MM-dd HH:mm:ss" disabled size="small">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="本次跟进方式" prop="followupmode">
            <el-select v-model="param.followupmode" placeholder="请选择方式" size="small">
              <el-option v-for="(item,index) in followTypeList" :key="index" :label="item.value" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="本次跟进结果" prop="logtype">
            <el-radio-group v-model="param.logtype">
              <el-radio label="跟进">跟进</el-radio>
            </el-radio-group>
          </el-form-item> -->
          <el-form-item label="跟进内容" prop="content" v-if="param.logtype == '跟进'">
            <el-input type="textarea" v-model="param.content" size="small"></el-input>
          </el-form-item>
          <upload
            ref="upload"
            :folderid="folderid"
            @onSuccess="onSuccess"
            :bindData="bindData"
            type="button">
          </upload>
        </el-form>
        
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="dialogVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="followAction" class="normal-btn-width" :loading="loading">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import upload from './upload'
export default {
  components:{upload},
  name: '',
  data () {
    return {
      loading:false,
      bindData:{},
      folderid:JSON.parse(sessionStorage.getItem('folderid')).appfolderid,
      param: {
        "sat_orderclueid": 4,
        "content": "",
        "followupmode": "", //当面拜访、电话沟通
        "logtype": "跟进", //跟进、成交、丢单、无效
        "competitor": "",
         "latitude":"",//经度，可选
        "longitude":"",//纬度，可选
        "address":"",//解析地址,
        "sat_ordercluefollowuplogid":0//传0新增
      },
      timer: new Date(),
      rules: {
        content: [
          { required: true, message: '内容不能为空', trigger: 'blur' },
        ],
        followupmode: [
          { required: true, message: '内容不能为空', trigger: 'blur' },
        ],
        logtype: [
          { required: true, message: '内容不能为空', trigger: 'blur' },
        ],
        competitor: [
          { required: true, message: '内容不能为空', trigger: 'blur' },
        ],
      },
      time: '',
      dialogVisible: false,
      followTypeList: []
    }
  },
  props: {
    detailInfo: {
      default () {
        return []
      }
    },
    position: {
      type: String
    },
    updataList: {
      type: Function
    },
    getDetail: {
      type: Function
    },
    disabled: Boolean
  },
  watch: {
    dialogVisible(val) {
      if (!val) {
        this.$refs['ruleForm'].resetFields()
        this.$refs.upload.fileLinkList = []
        this.$refs.upload.fileList = []

      }
    }
  },
  computed: {
  },
  created () {
    this.getFollowType()
  },
  methods: {
    async getFollowType () {
      let res = await this.$store.dispatch('optiontypeselect', 'followupmode')
      this.followTypeList = res.data
    },
    followBtn () {
      this.dialogVisible = true
    },
    handleClose () {
      this.dialogVisible = false
    },
    followAction () {
      this.$refs.ruleForm.validate(async val => {
        if (!val) return
        this.param.sat_orderclueid = this.detailInfo.sat_orderclueid
        let res = await this.$api.requested({
          "id":20221208100602,
          "content": this.param
        })
        this.bindData = {
          "ownertable": 'sat_ordercluefollowuplog',
          "ownerid": res.data.sat_ordercluefollowuplogid,
          "usetype": 'default',
        }
        this.loading = true
        this.$refs['upload'].toUpload(() => {
          this.loading = false
          this.$emit('onSuccess')
          this.dialogVisible = false
        })
      })
    },
    onSuccess () {

    }
  },
};
</script>

<style scoped>

.follow {
  display: inline-block;
}
/deep/.el-input,.el-select {
  width: 100%;
}
</style>
