<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="modalTitle"
    :modal-append-to-body="false"
    style="text-align:left;"
    @close="closeDialog"
    :close-on-click-modal="false"
    width="600px"
  >
    <div class="user-panel" v-loading="loading">
        <el-form ref="form" :model="formModel" :rules="ruleValidate" :label-width="'100px'">
            <el-form-item label="公司名称" prop="companyName">
            <el-input v-model="formModel.companyName" disabled="disabled"  style="width:400px"></el-input>
            </el-form-item>
            <el-form-item label="联系人" prop="realName">
            <el-input v-model="formModel.realName" placeholder="请输入联系人" style="width:400px"></el-input>
            </el-form-item>
            <el-form-item label="联系方式" prop="companyPhone">
            <el-input v-model="formModel.companyPhone" placeholder="请输入联系方式" style="width:400px"></el-input>
            </el-form-item>
            <el-form-item label="沟通时间" prop="chatDate">
                <el-date-picker
                    v-model="formModel.chatDate"
                    type="date"
                    placeholder="选择时间" 
                    style="width:170px;margin-right:10px">
                </el-date-picker>
                <el-time-select
                    v-model="formModel.chatTime"
                    placeholder="选择时间">
                </el-time-select>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input type="textarea" :rows="2" v-model="formModel.remark" placeholder="请输入备注" style="width:400px"></el-input>
            </el-form-item>

        </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitting">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import Constant from "@/constant";
import resumeDeliverApi from "@/api/job/resumeDeliver";

export default {
  props: ["businessKey", "title"],
  data() {
    return {
      formModel: {
        id: "",
        companyPerson:"",
        companyPhone:"",
        chatDate:"",
        chatTime:"",
        chatType:""
      },
      ruleValidate: {
        realName: [{ required: true, message: "联系人不能为空", trigger: "blur" }],
        companyPhone: [{ required: true, message: "联系方式不能为空", trigger: "blur" }],
        chatDate: [{ required: true, message: "沟通日期不能为空", trigger: "blur" }],
        chatTime: [{ required: true, message: "沟通时间不能为空", trigger: "blur" }],
      },
      dataDictionaryList: [],
      showDialog: true,
      loading: false,
      submitting: false
    };
  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    handleSubmit() {
      var self = this;
      this.$refs["form"].validate(valid => {
        if (valid) {
          (function() {
            var id = self.formModel.id;

            self.formModel.chatType = "3";

            return resumeDeliverApi.add(self.formModel);

          })().then(function(response) {
            var jsonData = response.data;

            if (jsonData.result) {
              self.$message({
                message: "保存成功!",
                type: "success"
              });

              self.$emit("close", true);
            } else {
              self.$message({
                message: jsonData.message + "",
                type: "warning"
              });

              self.$emit("close", false);
            }
          });
        }
      });
    },
  },
  async mounted() {
    var self = this;
    self.loading = true;

    (function() {
      if (self.businessKey.length == 0) {
        return resumeDeliverApi.create();
      } else {
        return resumeDeliverApi.edit(self.businessKey);
      }
    })()
      .then(response => {
        var jsonData = response.data;
        self.loading = false;

        if (jsonData.result) {
          self.formModel = jsonData.data;
          self.formModel.id = this.businessKey;
        } else {
          self.$message.error(jsonData.message + "");
        }
      })
      .catch(error => {
        self.$message.error(error + "");
      });
  }
};
</script>