<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="邀约场地">
        <span>{{ order.placeName }}</span>
      </el-form-item>
      <el-form-item label="邀约时间" v-if="order.invitationTime != undefined">
        <span>{{ order.invitationTime }}</span>
      </el-form-item>
      <el-form-item label="邀约备注" prop="coachId" v-if="order.remark != undefined">
        <span>{{ order.remark }}</span>
      </el-form-item>
      <el-form-item label="接待人" prop="coachId">
        <span>{{ order.coachName }}</span>
      </el-form-item>
      <el-divider></el-divider>
      <el-form-item label="到场状态" prop="arrivalStatus">
        <el-radio-group v-model="form.arrivalStatus" size="small" :disabled="type != 'JDR'">
          <el-radio :label="1">未到场</el-radio>
          <el-radio :label="2">到场未成交</el-radio>
          <el-radio :label="3">到场已成交</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="type != 'JDR'" />
      </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: 2 }).then(response => {
        if (response.data) {
          this.form = response.data;
        }
        this.loading = false;
      });
    },
    // 表单重置
    reset () {
      this.form = {
        feedbackId: null,
        clueId: null,
        feedbackType: 2,
        coachId: null,
        arrivalStatus: 1,
        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>
