<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:400px">
            </el-date-picker>
            </el-form-item>
            <el-form-item label="沟通时间" prop="chatTimeRange">
                <el-time-picker
                    is-range
                    v-model="chatTimeRange"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    placeholder="选择时间范围"
                    style="width:400px"
                    value-format="HH:mm"
                    format="HH:mm">
                </el-time-picker>
            </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:"",
        resumeDeliverId:"",
      },
      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" }],
      },
      chatTimeRange:"",
      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;

            if(self.chatTimeRange!=null&&self.chatTimeRange!=""){
                self.formModel.chatTime = self.chatTimeRange.toString();
            }

            self.formModel.chatType = "2";

            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>