<template>
  <el-card class="box-card" :class="isForm ? 'no-border' : 'add-margin-bottom'">
    <el-form :model="queryParams" :label-width="labelWidth" ref="queryForm" :rules="validateRules" :inline="true" style="position: relative" id="printMe">
      <el-row :gutter="24" class="mb8" style="margin: 0;padding-top: 10px; padding-bottom: 10px">
        <el-col v-if="user&&user.id" :span="6">
          <student-card :name="user.name" :avatar="user.img" class="block text-center" style="margin-top:20px" />
        </el-col>
        <el-col :span="user.id ? 18 : 24">
          <el-col :span="24" v-if="searchformShow.hasOwnProperty('province')">
            <el-form-item class="searchRadio" label="地区：" style="margin-bottom: 0">
              <province ref="province"></province>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="
              searchformShow.hasOwnProperty('class') &&
              searchformShow.hasOwnProperty('clbum')
            ">
            <el-form-item class="searchRadio" :prop="validateProps.clbum" label="班级：" style="margin-bottom: 0">
              <el-select clearable size="mini" v-model="queryParams.class" placeholder="请选择年级" style="margin-right: 10px" @change="radioChange('class')">
                <el-option v-for="item in classData" :key="item.code" :label="item.name" :value="item.code"></el-option>
              </el-select>
              <!-- 班级 -->
              <el-select
                size="mini"
                clearable
                v-if="searchformShow.hasOwnProperty('clbum')"
                v-model="queryParams.clbum"
                placeholder="请选择班级"
                style="margin-right: 10px"
                @change="radioChange('clbum')"
              >
                <el-option v-for="item in clbumData" :key="item.code" :label="item.name" :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24" v-for="item in refactoringSort()" :key="item.code" v-if="searchformShow.hasOwnProperty(item.code) && item.code != 'clbum'">
            <el-form-item class="searchRadio" :label="item.name" :prop="item.code" style="margin-bottom: 0">
              <div>
                <el-radio-group
                  v-model="queryParams[item.code]"
                  size="small"
                  @change="radioChange(item.code)"
                  v-if="item.code != 'class' && item.code != 'clbum'"
                >
                  <el-radio v-for="dic in item.dicData" :label="dic.code + ''" border :key="dic.code" v-if="!isForm || dic.code">{{ dic.name }}</el-radio>
                </el-radio-group>

                <div v-if="item.subset">
                  <el-radio-group v-model="queryParams[item.subset.code]" @change="radioChange(item.subset.code)">
                    <el-radio
                      style="border-radius: 0"
                      v-for="dic in item.subset.dicData"
                      :label="dic.code + ''"
                      :name="item.subset.code"
                      border
                      :key="dic.code"
                      v-if="!isForm || dic.code"
                    >{{ dic.name }}</el-radio>
                  </el-radio-group>
                </div>
              </div>
            </el-form-item>
          </el-col>

          <el-col :span="24" v-if="timeVisible">
            <el-form-item :label="timeOptions.label" :prop="validateProps.time">
              <mx-date-range-picker
                v-model="queryParams.time"
                :size="'mini'"
                :type="timeOptions.type"
                :value-format="timeOptions.valueFormat"
                :range-separator="timeOptions.rangeSeparator"
                :start-placeholder="timeOptions.startPlaceholder"
                :end-placeholder="timeOptions.endPlaceholder"
              ></mx-date-range-picker>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>
      <el-upload
        v-if="localityUpload"
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        multiple
      >
        <el-button type="primary" icon="el-icon-upload2" style="position: absolute; right: 0; top: 10px">本地上传至文件库</el-button>
      </el-upload>
      <el-button
        v-hasPermi="['front:evaluatingAccurateTeachingPersonalResources:uploadPersonResource']"
        v-if="coursewareUpload && userInfo.roles[0].roleId == 4"
        type="primary"
        @click="addLibrary"
        icon="el-icon-upload2"
        style="position: absolute; right: 0; top: 10px"
      >上传课件</el-button>
      <el-button
        v-if="personalUpload"
        :type="!uploading ? 'primary' : 'info'"
        icon="el-icon-upload2"
        @click="personal"
        style="position: absolute; right: 0; top: 10px"
      >上传至个人资源库</el-button>
      <el-button
        v-if="cloudUpload"
        :type="!uploading ? 'primary' : 'info'"
        icon="el-icon-upload2"
        @click="personal"
        style="position: absolute; right: 0; top: 10px"
      >上传至个人资源库</el-button>

      <!--      <el-row :gutter="24" v-if="!isForm&&!withoutSearchButton">-->
      <!--        <el-col :span="24" style="text-align: center;">-->
      <!--          <el-form-item>-->
      <!--            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
      <!--            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      <!--          </el-form-item>-->
      <!--        </el-col>-->
      <!--      </el-row>-->
      <!--      <div v-else-if="withoutSearchButton" style="height:10px;"></div>-->
    </el-form>
  </el-card>
</template>

<script>
import * as resources from "@/api/webApi/resources";
import * as back from "@/api/webApi/back";
import * as system from "@/api/webApi/system";
import { mapGetters } from "vuex";

export default {
  props: {
    isForm: {
      //是否是form表单形式
      type: Boolean,
      default: false,
    },
    withoutSearchButton: {
      type: Boolean,
      default: false,
    },
    searchformShow: {
      //显隐参数
      type: Object,
      default: () => {},
    },
    userData: {
      //学生数据
      type: Object,
      default: () => {},
    },
    localityUpload: {
      //本地上传至文件库
      type: Boolean,
      default: false,
    },
    cloudUpload: {
      //本地上传至云库
      type: Boolean,
      default: false,
    },
    personalUpload: {
      //上传至个人资源库
      type: Boolean,
      default: false,
    },
    coursewareUpload: {
      //上传课件
      type: Boolean,
      default: false,
    },
    validateRules: {
      // 表单校验
      type: Object,
      default: () => ({
        time: [],
        clbum: [],
      }),
    },
    validateProps: {
      type: Object,
      default: () => ({
        time: "time",
        clbum: "clbum",
      }),
    },
    labelWidth: {
      type: String,
      default: "60px",
    },
    timeOptions: {
      type: Object,
      default: () => ({
        label: "时间：",
        type: "daterange",
        valueFormat: "yyyy-MM-dd",
        rangeSeparator: "至",
        startPlaceholder: "开始日期",
        endPlaceholder: "结束日期",
      }),
    },
  },
  data() {
    return {
      clbumData: [],
      classData: [],
      user: {},
      uploading: false,
      queryParams: {
        //通过searchformShow 传的键值对来显示对应的搜索栏
        edition: "", //版本
        subjectid: "", //科目
        slipid: "", //学册
        gradeid: "", //年级
        resourceType: "", //类型
        province: "", //省市区
        wayType: "", //关联方式
        coursewareType: "", //课件类型
        catalogId: "", //分类编码
        semester: "", //学期
        exam: "", //期中期末分类
        class: "", //年级下拉
        clbum: "", //班级下拉
        time: [], // 时间
        userSubject: "", //老师或者校长的科目
        publish: "", //试卷开启状态
        studentGradeId: "", // 学生年级，管理端
      },
      form: {},
      data: [],
      timeVisible: false,
    };
  },
  watch: {
    userData() {
      this.user = this.userData || [];
    },
    "queryParams.subjectid": function (value) {
      this.queryParams.edition = "";
      if (value) {
        this.infoEdition(value);
      } else {
        this.data.forEach((item, index) => {
          if (item.code == "edition") {
            this.data.splice(index, 1);
          }
          if (item.code == "slipid") {
            this.data.splice(index, 1);
          }
        });
        console.log(this.data);
      }
    },
    "queryParams.userSubject": function (value) {
      this.queryParams.edition = "";
      if (value) {
        this.infoEdition(value);
      } else {
        this.data.forEach((item, index) => {
          if (item.code == "edition") {
            this.data.splice(index, 1);
          }
          if (item.code == "slipid") {
            this.data.splice(index, 1);
          }
        });
        console.log(this.data);
      }
    },
    "queryParams.edition": function (value) {
      this.queryParams.slipid = "";
      if (value) {
        this.infoSlip(value);
      } else {
        this.data.forEach((item, index) => {
          if (item.code == "slipid") {
            this.data.splice(index, 1);
          }
        });
      }
    },
    "queryParams.catalogId": function (value) {
      this.data.forEach((item3) => {
        if (item3.code == "catalogId") {
          item3.subset = null;
        }
      });
      if (value && value == 1) {
        system
          .getSubjectsList({})
          .then((response) => {
            let data = [];
            response.rows.forEach((item2) => {
              data.push({
                code: item2.subjectid,
                name: item2.subjectname,
              });
            });
            this.data.forEach((item3) => {
              if (item3.code == "catalogId") {
                item3.subset = {
                  dicData: data,
                  code: "catalogId_subjectid",
                };
              }
            });
            this.$forceUpdate();
          })
          .catch((err) => {
            this.loading = false;
          });
      } else {
        this.getDicts("subjects_type")
          .then((response) => {
            let data = [];
            response.data.forEach((item2) => {
              data.push({
                code: item2.dictValue,
                name: item2.dictLabel,
              });
            });
            this.data.forEach((item3) => {
              if (item3.code == "catalogId") {
                item3.subset = {
                  dicData: data,
                  code: "catalogId_subjectid",
                };
              }
            });
            this.$forceUpdate();
          })
          .catch((err) => {
            this.loading = false;
          });
      }
    },
    "queryParams.gradeid": function (value) {
      this.queryParams.semester = "";
      const semesterRequired = this.validateRules.semester?.find(
        (r) => r.required
      );
      if (value) {
        let semesterData = this.data.filter((item) => item.code == "semester");
        let dicData = [];
        this.data.forEach((item) => {
          if (item.code == "gradeid") {
            item.dicData.forEach((item2) => {
              if (value == item2.code) {
                dicData = item2.semesterData;
              }
            });
          }
        });
        if (!semesterData[0]) {
          this.data.push({
            name: "学期：",
            code: "semester",
            value: "",
            dicData: dicData,
          });
        } else {
          this.data.forEach((item) => {
            if (item.code == "semester") {
              item.dicData = dicData;
            }
          });
        }
        if (semesterRequired && dicData.length) {
          this.queryParams.semester = dicData[0].code;
          this.$nextTick(() => this.handleQuery());
        }
      } else {
        this.data.forEach((item, index) => {
          if (item.code == "semester") {
            this.data.splice(index, 1);
          }
        });
      }
    },
    "queryParams.class": function (value) {
      this.queryParams.clbum = "";
      // 2021.7.19 hht 将这里的年级纯粹当作筛选班级的作用; 如果有年级需要, 使用gradeid
      this.clbumData = [];
      const classRequired = this.validateRules.clbum?.find((r) => r.required);
      if (value) {
        //班级
        let subjectParam = {
          gradeId: value,
        };
        back
          .getUserClasses(subjectParam)
          .then((response) => {
            let data = [];
            response.data.forEach((item2) => {
              data.push({
                code: item2.id + "", // 同subjectid, 默认值
                name: item2.name,
              });
            });
            this.clbumData = data;
            if (classRequired && this.clbumData.length) {
              this.queryParams.clbum = this.clbumData[0].code;
              this.$nextTick(() => this.handleQuery());
            }
          })
          .catch((err) => {
            this.loading = false;
          });
      }
    },
    "queryParams.time": function (value) {
      this.$nextTick(() => this.handleQuery());
    },
  },
  created() {
    // this.info()
    // this.infoSubject()

    //			this.infoEdition()
    //			this.infoSlip()
    //			this.infoType()
    this.user = this.userData || {};
    // relationship.tree({subjectId: 1})

    this.queryParams.pharseId = 3; // TODO: hht 22.1.5 pharse这个参数现在无用了
    // this.infoType()

    console.log(this.$route);
    console.log(this.$router);
    console.log("----------");

    // var personalIndex = '/evaluating/accurateTeaching/personalResources/index' // 精准教学-个人资源库-微课视频
    // var personalPersonal = '/evaluating/accurateTeaching/personalResources/personal' // 精准教学-个人资源库-课件资源
    // var cloudIndex = '/evaluating/cloudTank/index' // 云库-微课视频
    // var cloudCourseware = '/evaluating/cloudTank/courseware' // 云库-课件资源
    Object.keys(this.searchformShow).forEach((key) => {
      if (key == "gradeid") {
        this.infoGradeid(); //年级
      }
      if (key == "subjectid") {
        this.infoSubject(); //科目
      }
      if (key == "resourceType") {
        this.infoType(); //类型
      }
      if (key == "wayType") {
        this.infoWayType(); //类型
      }
      if (key == "coursewareType") {
        this.infoCoursewareType();
      }
      if (key == "catalogId") {
        this.infocatalogType();
      }
      if (key == "exam") {
        this.data.push({
          name: "类型：",
          code: "exam",
          dicData: [
            {
              name: "所有",
              code: "",
            },
            {
              name: "单元测试",
              code: "3",
            },
            {
              name: "期中",
              code: "1",
            },
            {
              name: "期末",
              code: "2",
            },
          ],
        });
      }
      if (key == "workSource") {
        this.data.push({
          name: "来源：",
          code: "workSource",
          dicData: [
            {
              name: "班级",
              code: "1",
            },
            {
              name: "学校",
              code: "2",
            },
            {
              name: "系统",
              code: "3",
            },
          ],
        });
        this.$nextTick((_) => this.handleQuery());
      }
      if (key == "class") {
        this.infoClass();
      }
      if (key == "time") {
        this.timeVisible = true;
      }
      if (key == "userSubject") {
        this.infoUserSubject();
      }
      if (key == "publish") {
        this.infoPublish();
      }
      if (key == "studentGradeId") {
        this.infoStudentGradeId();
      }
      this.queryParams[key] = this.searchformShow[key];
    });
  },
  computed: {
    ...mapGetters(["currentUser"]),
    userInfo() {
      return this.currentUser;
    },
    currentSubjectName() {
      return (
        this.data
          .find((i) => i.code == "subjectid")
          ?.dicData.find((i) => i.code == this.queryParams.subjectid)?.name ||
        "--"
      );
    },
  },
  methods: {
    refactoringSort() {
      let list = [];
      Object.keys(this.searchformShow).forEach((key) => {
        this.data.forEach((item) => {
          if (item.code == key) {
            list.push(item);
          }
        });
      });
      return list;
    },
    // 云库列表
    getCloudResourcesList() {
      let _this = this;
      let listParam = {};
      resources
        .list(listParam)
        .then((response) => {
          let data = [];
          console.log(response);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    infoPublish() {
      let publishData = {
        name: "状态：",
        code: "publish",
        dicData: [
          {
            name: "所有",
            code: "",
          },
          {
            name: "已开启",
            code: "2",
          },
          {
            name: "未开启",
            code: "1",
          },
        ],
      };
      this.data.push(publishData);
    },
    //科目
    infoSubject() {
      let subjectData = {
        name: "科目：",
        code: "subjectid",
        dicData: [],
      };
      this.data.push(subjectData);
      // requied
      const subjectRequired = this.validateRules.subjectid?.find(
        (r) => r.required
      );
      if (!subjectRequired)
        subjectData.dicData.push({
          name: "所有",
          code: "",
        });
      let subjectParam = {};
      const subjectFunc = system.getSubjectsList; //subject.userList;
      const subjectFuncName = "subject.userList";
      subjectFunc(subjectParam)
        .then((response) => {
          console.log(subjectFuncName + " response=", response);
          const mappedSubjects = response.rows.map((subject) => ({
            code: subject.subjectid + "", // NOTE: 这里转化为string, 不然默认值不生效, 不清楚原因
            name: subject.subjectname,
          }));
          subjectData.dicData = subjectData.dicData.concat(mappedSubjects);
          if (subjectRequired && subjectData.dicData.length) {
            this.queryParams.subjectid = subjectData.dicData[0].code;
            this.$nextTick(() => this.handleQuery());
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    //科目
    infoUserSubject() {
      let subjectData = {
        name: "科目：",
        code: "userSubject",
        dicData: [],
      };
      this.data.push(subjectData);
      const subjectRequired = this.validateRules.userSubject?.find(
        (r) => r.required
      );
      if (!subjectRequired)
        subjectData.dicData.push({
          name: "所有",
          code: "",
        });
      let subjectParam = {};
      system
        .getUserSubjectsList(subjectParam)
        .then((response) => {
          const mappedSubjects = response.data.map((subject) => ({
            code: subject.subjectId + "", // NOTE: 这里转化为string, 不然默认值不生效, 不清楚原因
            name: subject.subjectName,
          }));
          if (response.code == 200 && response.data.length == 0) {
            this.$alert(
              "当前用户没有绑定科目，请前往个人中心绑定科目信息！",
              "提示",
              {
                confirmButtonText: "确定",
                callback: (action) => {
                  this.$router.push({
                    path: "/user/profile?activeTab=subjectDetail",
                  });
                },
              }
            );
            return;
          }
          subjectData.dicData = subjectData.dicData.concat(mappedSubjects);
          if (subjectRequired && subjectData.dicData.length) {
            this.queryParams.userSubject = subjectData.dicData[0].code;
            this.$nextTick(() => this.handleQuery());
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    //版本
    infoEdition(value) {
      let _this = this;
      let editionData = _this.data.filter((item) => item.code == "edition");
      if (!editionData[0]) {
        _this.data.push({
          name: "版本：",
          code: "edition",
          dicData: [
            {
              name: "所有",
              code: "",
            },
          ],
        });
      }
      let editionParam = {
        subjectId: value,
      };
      system
        .getGradeEditionList(editionParam)
        .then((response) => {
          let data = [];
          response.data.forEach((item2) => {
            let slips = [];
            item2.grades.forEach((item) => {
              slips.push({
                code: item.gradeid,
                name: item.gradename,
              });
            });
            data.push({
              code: item2.id,
              name: item2.name,
              slips: slips,
            });
          });
          _this.data.forEach((item3) => {
            if (item3.code == "edition") {
              item3.dicData = [
                {
                  name: "所有",
                  code: "",
                },
              ];
              item3.dicData = item3.dicData.concat(data);
            }
          });
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    //学册
    infoSlip(data) {
      let _this = this;
      let slipidData = _this.data.filter((item) => item.code == "slipid");
      if (!slipidData[0]) {
        _this.data.push({
          name: "学册：",
          code: "slipid",
          value: "",
          dicData: [],
        });
      }

      this.data.forEach((item, index) => {
        if (item.code == "edition") {
          let slips = [];
          item.dicData.forEach((item2) => {
            if (item2.code == data) {
              slips = item2.slips;
            }
          });
          _this.data.forEach((item3) => {
            if (item3.code == "slipid") {
              item3.dicData = [];
              item3.dicData = item3.dicData.concat(slips);
            }
          });
        }
      });
    },
    infoClass() {
      // requied
      const classRequired = this.validateRules.clbum?.find((r) => r.required);
      system
        .getPharseGradeList({
          pharseId: this.queryParams.pharseId,
        })
        .then((response) => {
          let data = [];
          response.rows.forEach((item2) => {
            if (!data.find((i) => i.code == item2.gradeId)) {
              data.push({
                code: item2.gradeId,
                name: item2.grade.gradename,
                semesterData: [
                  {
                    name: "所有",
                    code: "",
                  },
                  {
                    name: "上学期",
                    code: item2.gradeId + 1,
                  },
                  {
                    name: "下学期",
                    code: item2.gradeId + 2,
                  },
                ],
              });
            }
          });
          this.classData = data;
          if (classRequired && this.classData.length) {
            this.queryParams.class = this.classData[0].code;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    //类型
    infoType() {
      let _this = this;
      _this.data.push({
        name: "类型：",
        code: "resourceType",
        value: "",
        dicData: [
          {
            name: "所有",
            code: "",
          },
        ],
      });
      let typeParam = {
        slipid: _this.queryParams.slipid,
      };
      _this
        .getDicts("resource_type")
        .then((response) => {
          let data = [];
          response.data.forEach((item2) => {
            data.push({
              code: item2.dictValue,
              name: item2.dictLabel,
            });
          });

          _this.data.forEach((item3) => {
            if (item3.code == "resourceType") {
              item3.dicData = [
                {
                  name: "所有",
                  code: "",
                },
              ];
              item3.dicData = item3.dicData.concat(data);
            }
          });
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    infoCoursewareType() {
      let _this = this;
      _this.data.push({
        name: "类型：",
        code: "coursewareType",
        value: "",
        dicData: [
          {
            name: "所有",
            code: "",
          },
        ],
      });
      _this
        .getDicts("courseware_type")
        .then((response) => {
          let data = [];
          response.data.forEach((item2) => {
            data.push({
              code: item2.dictValue,
              name: item2.dictLabel,
            });
          });

          _this.data.forEach((item3) => {
            if (item3.code == "coursewareType") {
              item3.dicData = [
                {
                  name: "所有",
                  code: "",
                },
              ];
              item3.dicData = item3.dicData.concat(data);
            }
          });
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    infoGradeid() {
      //年级
      const gradeRequired = this.validateRules.gradeid?.find((r) => r.required);
      const semesterRequired = this.validateRules.semester?.find(
        (r) => r.required
      );
      let gradeData = {
        name: "年级：",
        code: "gradeid",
        value: "",
        dicData: [],
      };
      this.data.push(gradeData);
      if (!gradeRequired) {
        gradeData.dicData.push({
          name: "所有",
          code: "",
        });
      }
      system
        .getPharseGradeList({
          pharseId: this.queryParams.pharseId,
        })
        .then((response) => {
          let data = [];
          response.rows.forEach((item2) => {
            if (!data.find((i) => i.code == item2.gradeId)) {
              const singleGrade = {
                code: item2.gradeId + "",
                name: item2.grade.gradename,
                semesterData: [
                  {
                    name: "所有",
                    code: "",
                  },
                  {
                    name: "上学期",
                    code: item2.gradeId + 1 + "",
                  },
                  {
                    name: "下学期",
                    code: item2.gradeId + 2 + "",
                  },
                ],
              };
              data.push(singleGrade);
              if (semesterRequired) singleGrade.semesterData.shift();
            }
            this.classOption = data;
          });
          gradeData.dicData = gradeData.dicData.concat(data);
          if (gradeRequired && gradeData.dicData.length) {
            const demoGrade = gradeData.dicData[0];
            this.queryParams.gradeid = demoGrade.code;
            if (!this.searchformShow.hasOwnProperty("semester"))
              // 如果包含semester，则semester会触发handleQuery
              this.$nextTick(() => this.handleQuery());
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    infoStudentGradeId() {
      //年级
      const gradeRequired = this.validateRules.studentGradeId?.find(
        (r) => r.required
      );
      let gradeData = {
        name: "学生：",
        code: "studentGradeId",
        value: "",
        dicData: [],
      };
      this.data.push(gradeData);
      if (!gradeRequired) {
        gradeData.dicData.push({
          name: "所有",
          code: "",
        });
      }
      system
        .getPharseGradeList({
          pharseId: this.queryParams.pharseId,
        })
        .then((response) => {
          let data = [];
          response.rows.forEach((item2) => {
            if (!data.find((i) => i.code == item2.gradeId)) {
              const singleGrade = {
                code: item2.gradeId + "",
                name: item2.grade.gradename,
              };
              data.push(singleGrade);
            }
          });
          gradeData.dicData = gradeData.dicData.concat(data);
          if (gradeRequired && gradeData.dicData.length) {
            const demoGrade = gradeData.dicData[0];
            this.queryParams.studentGradeId = demoGrade.code;
            this.$nextTick(() => this.handleQuery());
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    infoWayType() {
      //
      let _this = this;
      _this.data.push({
        name: "关联：",
        code: "wayType",
        dicData: [
          {
            name: "同步章节",
            code: "1",
          },
          {
            name: "知识点",
            code: "2",
          },
        ],
      });
    },
    infocatalogType() {
      let _this = this;
      _this.data.push({
        name: "分类：",
        code: "catalogId",
        dicData: [
          {
            name: "单科",
            code: "1",
          },
          {
            name: "组合",
            code: "2",
          },
        ],
      });
    },
    handleQuery() {
      //搜索回调
      if (this.$refs["province"]) {
        let data = this.$refs.province.getData() || [];
        this.queryParams.province = data[0] || "";
        this.queryParams.city = data[1] || "";
        this.queryParams.area = data[2] || "";
        this.queryParams.schoolid = data[3] || "";
      }
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.$emit("handleQuery", this.queryParams);
        }
      });
    },
    personal() {
      //点击上传至个人资源库 事件
      this.uploading = !this.uploading;
      this.$emit("personal", this.uploading);
    },
    resetQuery() {
      this.$refs["queryForm"].resetFields();
      if (this.$refs["province"]) {
        this.$refs["province"].resetFields();
      }
      this.data.forEach((item) => {
        this.queryParams[item.code] = "";
      });
      this.$emit("resetQuery", this.queryParams);
      this.$forceUpdate();
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {},
    handleCheckedCitiesChange(value) {
      console.log(value);
    },
    radioChange(type) {
      console.log("radioChange by " + type);
      // 年级改变不处理
      // 年级清空要处理
      if (type == "class") {
        if (this.queryParams.class) return;
        this.queryParams.clbum = ""; // TODO: 这里强行改变, 不确定是否有影响, 因为清空年级时不会主动触发班级变化事件
      }
      //数据变化事件
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.$emit("change", this.queryParams, type);
          console.log(this.queryParams);
          this.$forceUpdate();
          this.handleQuery();
        }
      });
    },
    addLibrary() {
      if (this.$route.name == "Personal") {
        this.$router.push({
          path: "/accurateTeaching/personalResources/add?type=课件资源",
        });
      } else {
        this.$router.push({
          path: "/accurateTeaching/personalResources/add?type=自定义",
        });
      }
    },
    getClassName(classId) {
      return this.clbumData.find((i) => i.code == classId)?.name || "";
    },
    getSubjectName(subjectId) {
      return (
        this.data
          .find((i) => i.code == "subjectid")
          ?.dicData.find((i) => i.code == subjectId)?.name || subjectId
      );
    },
    getStudentGradeName(studentGradeId) {
      return (
        this.data
          .find((i) => i.code == "studentGradeId")
          ?.dicData.find((i) => i.code == studentGradeId)?.name ||
        studentGradeId
      );
    },
    validate(action) {
      this.$refs.queryForm.validate(action);
    },
  },
};
</script>

<style scoped>
.no-border {
  box-shadow: none;
  border: none;
  margin-bottom: 0;
}

.add-margin-bottom {
  margin-bottom: 15px;
}

/deep/.el-form-item__content {
  vertical-align: middle;
}

/deep/.el-form-item--medium .el-form-item__label {
  padding: 0 !important;
}

/deep/.el-card__body {
  padding: 0;
}

/deep/.el-form-item__error {
  position: inherit;
}
</style>
