<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'>
        <el-form-item>
          <el-select
            v-model.trim="searchForm.organId"
            placeholder="请选择分部"
            clearable
            filterable
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <remote-search
            :commit="'setTeachers'"
            v-model="searchForm.userId"
          />
        </el-form-item>
        <el-form-item>
          <el-date-picker
            style="width: 100% !important"
            v-model.trim="searchForm.monthStr"
            type="month"
            value-format="yyyy-MM"
            placeholder="选择月"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="searchForm.lowSalary"
            placeholder="请选择是否预警"
            clearable
            filterable
          >
            <el-option
              value="0"
              label="否"
            ></el-option>
            <el-option
              value="1"
              label="是"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="searchForm.minSalary" type="number" placeholder="预警课酬大于"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="searchForm.maxSalary" type="number" placeholder="预警课酬小于"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" native-type="submit">搜索</el-button>
          <el-button native-type="reset" type="primary">重置</el-button>
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          :data="tableList"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
        >
          <el-table-column align="center" prop="monthStr" label="月份">
          </el-table-column>
          <el-table-column align="center" prop="organName" label="分部">
                <template slot-scope="scope">
              <div>
                <copy-text>{{ scope.row.organName }}</copy-text>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="realName" label="老师">
                 <template slot-scope="scope">
              <div>
                <copy-text>{{ scope.row.realName }}</copy-text>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="subjectListStr" label="专业">
            <template slot-scope="scope">
              <overflow-text width="100%" :text="scope.row.subjectListStr" />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="musicCourseNum"
            label="乐团节数"
          >
          </el-table-column>
          <el-table-column align="center" prop="vipCourseNum" label="VIP节数">
          </el-table-column>
          <el-table-column align="center" prop="practiceCourseNum" label="网管节数">
          </el-table-column>
          <el-table-column
            align="center"
            prop="expectMusicCourseSalary"
            label="预计乐团课酬"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.expectMusicCourseSalary | moneyFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="expectVipCourseSalary"
            label="预计VIP课酬"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.expectVipCourseSalary | moneyFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="expectPracticeCourseSalary"
            label="预计网管课酬"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.expectPracticeCourseSalary | moneyFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="预计课酬合计"
            prop="expectTotalSalary"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.expectTotalSalary | moneyFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="averageClassMinutes"
            label="平均上课时长"
          >
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="pageInfo.total"
          :page.sync="pageInfo.page"
          :limit.sync="pageInfo.limit"
          :page-sizes="pageInfo.page_size"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
import {
  getEmployeeOrgan,
  teacherCourseStatistics,
  getTeacher,
} from "@/api/buildTeam";
import pagination from "@/components/Pagination/index";
let nowDate = new Date();
let nowMonth =
  nowDate.getFullYear() +
  "-" +
  (nowDate.getMonth() + 1 >= 10
    ? nowDate.getMonth() + 1
    : "0" + (nowDate.getMonth() + 1));
export default {
  name: "operationalList",
  components: { pagination },
  data() {
    return {
      searchForm: {
        organId: null,
        monthStr: nowMonth,
        userId: null,
        maxSalary: null,
        lowSalary: null,
      },
      tableList: [{}],
      organList: [],
      teacherList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
    };
  },
  mounted() {
    // 获取分部
    // getEmployeeOrgan().then(res => {
    //   if (res.code == 200) {
    //     this.organList = res.data;
    //   }
    // })
    const { lowSalary, organId } = this.$route.query
    if (organId) {
      this.searchForm.organId = organId
    }
    let string = lowSalary == 1 || lowSalary == 0 ? String(lowSalary) : ''
    if (string) {
      this.$set(this.searchForm, 'lowSalary', string)
    }
    this.$store.dispatch("setBranchs");
    // 获取老师列表
    // getTeacher({ organId: this.organId }).then(res => {
    //   if (res.code == 200) {
    //     this.teacherList = res.data;
    //   }
    // })
    this.getList();
  },
  methods: {
    search() {
      this.pageInfo.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm = {
        organId: null,
        monthStr: nowMonth,
        userId: null,
        maxSalary: null,
        lowSalary: null,
      };
      this.getList();
    },
    getList() {
      let params = this.searchForm;
      params.page = this.pageInfo.page
      params.rows = this.pageInfo.limit
      teacherCourseStatistics(params).then((res) => {
        let result = res.data;
        if (res.code == 200) {
          this.tableList = result.rows;
          this.pageInfo.total = result.total;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
