<template>
  <div class="m-core">
    <el-form :inline="true" :model="searchForm">
      <el-form-item prop="teacher">
        <el-input
          placeholder="老师姓名/编号"
          v-model.trim="searchForm.teacher"
        ></el-input>
      </el-form-item>
      <el-form-item prop="visiterType">
        <el-select
          v-model.trim="searchForm.visiterType"
          placeholder="请选择角色"
          clearable
          filterable
        >
          <el-option value="TEACHER" label="指导老师"></el-option>
          <el-option value="EDU_TEACHER" label="乐团主管"></el-option>
        </el-select>
      </el-form-item>
      <!-- @change="handleChange" -->
      <el-form-item prop="feedbackType">
        <el-select
          v-model.trim="searchForm.feedbackType"
          placeholder="请选择回访结果"
          clearable
          filterable
        >
          <el-option
            :value="item.value"
            :label="item.label"
            v-for="(item, index) in feedbackTypeList"
            :key="index"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="feedbackTypeDesc">
        <el-select
          v-model.trim="searchForm.feedbackTypeDesc"
          placeholder="请选择反馈详情"
          clearable
          filterable
        >
          <el-option
            :value="item.value"
            :label="item.label"
            v-for="(item, index) in feedbackTypeDescList"
            :key="index"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          key="visiList"
          v-model.trim="searchForm.timer"
          style="width: 420px"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="回访开始日期"
          end-placeholder="回访结束日期"
          :picker-options="{
            firstDayOfWeek: 1,
          }"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="search">搜索</el-button>
        <el-button type="primary" @click="onReSet">重置</el-button>
      </el-form-item>
    </el-form>
    <auth auths="visit/add">
      <el-button type="primary" style="margin-bottom: 20px" @click="addVisit"
        >新增回访</el-button
      >
    </auth>
    <div class="tableWrap">
      <el-table
        :data="tableList"
        :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
      >
        <el-table-column align="center" prop="teacherName" label="老师姓名">
          <template slot-scope="scope">
            <copy-text>{{ scope.row.teacherName }}</copy-text>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="visiterType" label="角色">
          <template slot-scope="scope">
            <div>
              {{ scope.row.visiterType | visiterType }}
            </div>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="visitTime" label="回访时间">
          <template slot-scope="scope">
            <div>
              {{
                scope.row.visitTime ? scope.row.visitTime.split(" ")[0] : "--"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="overview" label="学员情况">

          <template slot-scope="scope">
             <overflow-text :text="scope.row.overview"></overflow-text>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="type" label="回访结果">
          <template slot-scope="scope">
            <div>
              {{ scope.row.feedbackType | feedbackTypeFilter }}
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="type" label="反馈详情">
          <template slot-scope="scope">
            <div v-if="scope.row.feedbackTypeDesc">
              {{ scope.row.feedbackTypeDesc | feedbackTypeDescFilter }}
            </div>
            <div v-else>--</div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="type" label="原因">
          <template slot-scope="scope">
            <div>
              <overflow-text
                width="100%"
                :text="scope.row.feedback"
              ></overflow-text>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        sync
        :total.sync="rules.total"
        :page.sync="rules.page"
        :limit.sync="rules.limit"
        :page-sizes="rules.page_size"
        @pagination="getList"
      />
    </div>
    <el-dialog
      title="新增回访"
      width="800px"
      v-if="visitVisiable"
      :close-on-click-modal="false"
      :visible.sync="visitVisiable"
      append-to-body
    >
      <addVisit
        :detail="detail"
        :useVisitType="useVisitType"
        @close="visitVisiable = false"
        @submited="refresh"
      />
    </el-dialog>
  </div>
</template>
<script>
import { feedbackTypeList, feedbackTypeDescList } from "@/utils/searchArray";
import { getVisitList } from "@/views/returnVisitManager/api";
import pagination from "@/components/Pagination/index";
import { getTimes } from "@/utils";
import cleanDeep from "clean-deep";
import addVisit from "./addVisit";
export default {
  components: { pagination, addVisit },
  props: ["studentId", "studentName", "groupType"],
  data() {
    return {
      searchForm: {
        teacher: "",
        visiterType: "",
        feedbackType: "",
        timer: [],
      },
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      tableList: [],
      feedbackTypeList: feedbackTypeList,
      feedbackTypeDescList,
      visitVisiable: false,
      detail: null,
      useVisitType: null,
    };
  },
  mounted() {
    if (this.groupType == "PRACTICE") {
      this.useVisitType = ["小课回访", "网管课回访"];
    } else if (this.groupType == "THEORY") {
      this.useVisitType = ["小课回访", "乐理课回访"];
    } else {
      this.useVisitType = ["小课回访", "VIP课回访"];
    }
    this.searchForm.studentId = this.studentId;

    this.getList();
  },
  methods: {
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm = {
        teacher: "",
        visiterType: "",
        feedbackType: "",
        timer: [],
      };
      this.search();
    },
    refresh() {
      this.getList();
      this.$emit("getList");
    },
    getList() {
      // cleanDeep
      let { timer, ...rest } = this.searchForm;
      let params = {
        studentId: this.studentId,
        ...rest,
        page: this.rules.page,
        rows: this.rules.limit,
        ...getTimes(timer, ["startTime", "endTime"]),
        purpose: this.useVisitType[1] ? this.useVisitType[1] : null,
        type: this.useVisitType[0] ? this.useVisitType[0] : null,
      };
      getVisitList(cleanDeep(params)).then((res) => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
        }
      });
    },
    addVisit() {
      // 新增回访
      // row.userId = row.studentId;
      // detail   userId userName
      // this.detail = row;
      this.detail = {
        userId: this.studentId,
        userName: this.studentName,
      };
      this.visitVisiable = true;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
