<template>
  <div class="app-container" style="width:90%;margin:auto;">
    <!-- 添加或修改线索反馈对话框 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="学员姓名">
        <span>{{ order.stuName }}</span>
      </el-form-item>
      <el-form-item label="联系方式">
        <span>{{ order.phone }}</span>
      </el-form-item>
      <el-form-item label="地址">
        <span>{{ order.address }}</span>
      </el-form-item>
      <el-form-item label="接待人" prop="coachId">
        <span>{{ order.coachName }}</span>
      </el-form-item>
      <el-form-item label="是否联系" prop="isContact">
        <el-radio-group v-model="form.isContact" size="small" :disabled="type != 'JDR'">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="到场时间" prop="arrivalTime">
        <el-date-picker v-model="form.arrivalTime" :disabled="type != 'JDR'" clearable type="datetime" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" placeholder="请选择到场时间" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" :disabled="type != 'JDR'" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div v-if="type === 'JDR'" style="text-align: center;">
      <div style="text-align: center;">
        <el-button type="primary" @click="submitForm">提 交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getFeedbackDetailInfo, addFeedbackDetail, updateFeedbackDetail } from '@/api/zs/feedbackDetail';

import { getFeedbackOrder } from '@/api/zs/feedbackOrder';

export default {
  name: 'Follow',
  data () {
    return {
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      order: {},
      orderId: undefined,
      type: undefined
    };
  },
  created () {
    console.log(this.$route.query.no);
    this.type = this.$route.query.type;
    this.reset();
    this.getFeedbackOrder(this.$route.query.no);
    this.getFeedbackDetailInfo(this.$route.query.no);
  },
  methods: {
    /** 查询线索反馈表单 */
    getFeedbackOrder (orderId) {
      this.loading = true;
      getFeedbackOrder(orderId).then(response => {
        this.order = response.data;
        if (this.order.clueId) {
          this.form.clueId = this.order.clueId;
        }
        if (this.order.coachId) {
          this.form.coachId = this.order.coachId;
        }
        if (this.order.orderId) {
          this.form.orderId = this.order.orderId;
        }
        this.loading = false;
      });
    },
    /** 查询线索反馈表单 */
    getFeedbackDetailInfo (orderId) {
      this.loading = true;
      getFeedbackDetailInfo({ orderId: orderId, feedbackType: 1 }).then(response => {
        if (response.data) {
          this.form = response.data;
        }
        this.loading = false;
      });
    },
    // 表单重置
    reset () {
      this.form = {
        feedbackId: null,
        clueId: null,
        feedbackType: 1,
        coachId: null,
        feedbackTime: null,
        isContact: 0,
        arrivalTime: null,
        remark: null
      };
      this.resetForm('form');
    },
    /** 提交按钮 */
    submitForm () {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.feedbackId != null) {
            updateFeedbackDetail(this.form).then(response => {
              this.$modal.msgSuccess('提交成功');
            });
          } else {
            addFeedbackDetail(this.form).then(response => {
              this.$modal.msgSuccess('提交成功');
            });
          }
        }
      });
    }
  }
};
</script>
