<template>
  <el-dialog :title="cons.consNum+'-'+cons.customerNumber+'-'+$t('跟进记录')" :before-close="()=>{$emit('update:showConsFollowupEdit',false)}"
             :visible.sync="showConsFollowupEdit">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="状态" prop="status">
        <dict-selector :placeholder="$t('请选择状态')" v-model="form.status"
                       :type="DICT_TYPE.ECW_CONS_FOLLOWUP_STATUS"></dict-selector>
      </el-form-item>
      <el-form-item label="跟进内容">
        <el-input type="textarea" v-model="form.followContent" :rows="6" />
      </el-form-item>

      <el-form-item label="下次跟进时间" prop="nextFollowTime">
        <el-date-picker clearable v-model="form.nextFollowTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="选择下次跟进时间" />
      </el-form-item>
      <el-form-item label="下次跟进内容">
        <el-input type="textarea" v-model="form.nextFollowContent" :rows="6" />
      </el-form-item>

      <el-form-item :label="$t('图片')">
        <image-upload v-model="form.exceptionUrls"></image-upload>
      </el-form-item>

      <el-row>
        <el-col :span="12">
          <el-form-item label="跟进人" prop="followUserId">
            <el-select
              v-model="form.followUserId"
              :placeholder="$t('请选择客户经理')"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in userServiceList"
                :key="dict.id"
                :label="dict.nickname"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="跟进时间" prop="followTime">
            <el-date-picker clearable v-model="form.followTime" type="date" value-format="yyyy-MM-dd"
                            placeholder="选择跟进时间" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="创建人">
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="创建时间">
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="最后更新人">
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最后更新时间">
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">{{ $t("确 定") }}</el-button>
      <el-button @click="$emit('update:showConsFollowupEdit',false)">{{ $t("取 消") }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import imageUpload from "@/components/ImageUpload/index.vue"
import Editor from "@/components/Editor/index.vue"
import { getCons } from "@/api/ecw/cons"
import {  listSimpleUsers } from "@/api/system/user"
import { createConsFollowup } from "@/api/ecw/consFollowup"

export default {
  name: "consFollowupEdit",
  components: { Editor, imageUpload },
  props: {
    id: Number,
    showConsFollowupEdit: Boolean
  },
  data() {
    return {
      form: {
        exceptionUrls: [],
      },
      rules: {
        status: [
          { required: true, message: "请选择状态", trigger: "blur" }
        ]
      },
      cons: {},
      userServiceList: []
    }
  },
  methods: {
    submitForm() {
      this.$refs.form.validate(validate => {
        if (validate) {
          this.form.exceptionUrls = this.params.exceptionUrls.length ? this.params.exceptionUrls.split(",") : []
          this.form.mediaBusinessType = 2
            createConsFollowup(this.form).then(response => {
            this.showConsFollowupEdit = false
            this.$emit("determine")
            this.$modal.msgSuccess("新增成功")
          })
        }
      })
    }
  },
  watch: {
    showConsFollowupEdit(val) {
      if (val) {
        getCons(this.id).then(res => {
          this.cons = res.data
        })
        listSimpleUsers().then((r) => {
          this.userServiceList = r.data;
        });
      } else {
        this.exceptionUrls = []
        this.form = {}
      }
    }
  }
}
</script>

<style scoped>

</style>
