<!--  -->
<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      学校巡堂
    </h2>
    <div class="m-core">
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
        ref="saveForm"
      >
        <el-form-item prop="keyword">
          <el-input
            class="seachInput"
            v-model.trim="searchForm.keyword"
            clearable
            @keyup.enter.native="
              (e) => {
                e.target.blur();
                $refs.saveForm.save();
                search();
              }
            "
            placeholder="老师姓名/编号/手机号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="organId">
          <el-select
            style="width: 180px !important"
            class="multiple"
            v-model.trim="searchForm.organId"
            filterable
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="cooperationOrganId">
          <el-select
            v-model.trim="searchForm.cooperationOrganId"
            :disabled="!searchForm.organId"
            filterable
            clearable
            placeholder="请选择合作单位"
          >
            <el-option
              v-for="(item, index) in cooperationList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="courseType">
          <el-select
            v-model.trim="searchForm.courseType"
            clearable
            filterable
            placeholder="课程类型"
          >
            <el-option
              v-for="(item, index) in courseType"
              :key="index"
              :value="item.value"
              :label="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="evaluateStatus">
          <el-select
            v-model.trim="searchForm.evaluateStatus"
            clearable
            filterable
            placeholder="综合评价"
          >
            <el-option
              v-for="(item, index) in evaluateStatusList"
              :key="index"
              :value="item.value"
              :label="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="problemType">
          <el-select
            v-model.trim="searchForm.problemType"
            clearable
            filterable
            placeholder="问题类型"
          >
            <el-option
              v-for="(item, index) in problemTypeList"
              :key="index"
              :value="item.value"
              :label="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="handleStatus">
          <el-select
            v-model.trim="searchForm.handleStatus"
            clearable
            filterable
            placeholder="处理状态"
          >
            <el-option :value="true" label="已处理"></el-option>
            <el-option :value="false" label="未处理"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="createTimer">
          <el-date-picker
            v-model.trim="searchForm.createTimer"
            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 native-type="submit" type="primary">搜索</el-button>
          <el-button native-type="reset" type="danger">重置</el-button>
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column align="center" prop="id" label="编号"></el-table-column>
          <el-table-column align="center" prop="organName" label="分部"></el-table-column>
          <el-table-column
            align="center"
            prop="cooperationOrganName"
            label="合作单位"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="teacherName"
            label="老师姓名"
          ></el-table-column>
          <el-table-column align="center" prop="courseType" label="课程类型">
            <template slot-scope="scope">
              <div>
                {{ scope.row.courseType | courseTypeFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="courseScheduleId"
            label="课程编号"
          ></el-table-column>
          <el-table-column align="center" prop="evaluateStatus" label="综合评价">
            <template slot-scope="scope">
              <div>{{ scope.row.evaluateStatus | evaluateStatus }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="problemType" label="问题类型">
            <template slot-scope="scope">
              <div>
                {{ scope.row.problemType | problemType }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="handleStatus" label="处理状态">
            <template slot-scope="scope">
              <div>
                {{ scope.row.handleStatus ? "已处理" : "未处理" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="课程时间">
            <template slot-scope="scope">
              <div>
                <p>{{ scope.row.startClassTime | formatTimer }}</p>
                {{
                  scope.row.startClassTime ? scope.row.startClassTime.substr(11, 5) : ""
                }}-{{
                  scope.row.endClassTime ? scope.row.endClassTime.substr(11, 5) : ""
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="操作">
            <template slot-scope="scope">
              <div>
                <!-- <el-button type="text">详情</el-button> -->
                <el-button type="text" @click="lookDetail(scope.row)">处理意见</el-button>
              </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>
    </div>
    <el-dialog
      :title="activeRow.handleStatus ? '详情' : '处理意见'"
      width="450px"
      :visible.sync="dialogFormVisible"
    >
      <patrolModels
        :id="activeRow.id"
        v-if="dialogFormVisible"
        ref="patrolModelsRef"
        @close="
          () => {
            dialogFormVisible = false;
            getList();
          }
        "
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button @click="submitMessage" type="primary">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
import pagination from "@/components/Pagination/index";
import load from "@/utils/loading";
import { getTimes } from "@/utils";
import { queryByOrganId } from "@/api/systemManage";
import { getCoursePatrolEvaluation } from "./api";
import { resetQuery } from "@/utils/utils";
import {
  courseType,
  courseListType,
  evaluateStatusList,
  problemTypeList,
} from "@/utils/searchArray";
import patrolModels from "./modals/patrolModels";
export default {
  components: { pagination, patrolModels },
  data() {
    return {
      searchForm: {
        keyword: null,
        organId: null,
        cooperationOrganId: null,
        courseType: null,
        evaluateStatus: null,
        problemType: null,
        handleStatus: null,
        createTimer: null,
      },
      courseType,
      tableList: [{}],
      organList: [],
      cooperationList: [],
      evaluateStatusList,
      problemTypeList,
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      dialogFormVisible: false,
      activeRow: { handleStatus: false },
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    // 获取分部
    if (this.$route.query.handleStatus) {
      this.$set(
        this.searchForm,
        "handleStatus",
        Boolean(this.$route.query.handleStatus * 1)
      );
    }

    if (this.$route.query.evaluateStatus) {
      this.$set(this.searchForm, "evaluateStatus", this.$route.query.evaluateStatus);
    }

    this.$store.dispatch("setBranchs");
    this.init();
  },
  methods: {
    init() {
      this.getList();
      console.log(this.$refs.saveForm, "this.$refs.saveForm", this.$refs.saveForm.save);
      // this.$refs.saveForm.save();
      // resetQuery(this, {
      //   handleStatus: undefined,
      //   evaluateStatus: undefined,
      //   filter_type: undefined,
      // });
    },
    async getList() {
      try {
        let { createTimer, ...rest } = this.searchForm;
        let params = {
          ...rest,
          page: this.rules.page,
          rows: this.rules.limit,
          ...getTimes(createTimer, ["startTime", "endTime"]),
        };
        const res = await getCoursePatrolEvaluation({
          ...params,
          page: this.rules.page,
          rows: this.rules.limit,
        });
        this.tableList = res.data.rows;
        this.rules.total = res.data.total;
      } catch (error) {
        console.log(error);
      }
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    submitMessage() {
      this.$refs.patrolModelsRef.submit();
    },
    onReSet() {
      this.$nextTick(() => {
        this.getList();
      });
    },
    lookDetail(row) {
      this.activeRow = row;
      this.dialogFormVisible = true;
      console.log("查看详情");
    },
    handleOpinion(row) {
      console.log("处理意见");
    },
    getProblemType(type) {
      if (type) {
        const arrList = type.split(",");
        arrList.map((item) => {
          return;
        });
      } else {
        return "--";
      }
    },
  },
  watch: {
    "searchForm.organId"(val) {
      if (val) {
        queryByOrganId({ organId: val }).then((res) => {
          if (res.code == 200) {
            this.cooperationList = res.data;
          }
        });
      }
    },
    // "searchForm.cooperationId"(val) {
    //   if (val) {
    //     getMusicGroup({ cooperationId: val }).then((res) => {
    //       this.musicList = res.data;
    //     });
    //   }
    // },
  },
};
</script>
<style lang="scss">
.seachInput {
  .el-input__inner {
    width: 200px !important;
  }
}
</style>
