<template>
  <div class="app-container">
    <el-form style="background-color: #fff; padding: 15px 5px; border-radius:10px;"  :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <p class="bgtan" style="margin-top: 0;">搜索条件</p>
	  <!-- <el-form-item label="申请时间" prop="applyTime">
        <el-date-picker clearable
          v-model="queryParams.applyTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请时间">
        </el-date-picker>
      </el-form-item> -->
    <!--  <el-form-item label="调课班级id" prop="subjectClassId">
        <el-input
          v-model="queryParams.subjectClassId"
          placeholder="请输入调课班级id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
	  <el-form-item label="调课班级" prop="subjectClassId">
	  		  <el-select v-model="queryParams.subjectClassId" placeholder="请选择班级名称">
	  		    <el-option
	  		      v-for="dict in kiueseghs"
	  		      :key="dict.deptId"
	  		      :label="dict.deptName"
	  		      :value="dict.deptId"
	  			  clearable
	  			   @keyup.enter.native="handleQuery"
	  		    ></el-option>
	  		  </el-select>
	  </el-form-item>
      <el-form-item label="调课科目" prop="subject">
        <el-select v-model="queryParams.subject" placeholder="请选择调课科目" clearable>
          <el-option
            v-for="dict in dict.type.sys_subject"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="被调科目" prop="beSubject">
        <el-select v-model="queryParams.beSubject" placeholder="请选择被调科目" clearable>
          <el-option
            v-for="dict in dict.type.sys_subject"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="调课周几" prop="week">
        <el-select v-model="queryParams.week" placeholder="请选择调课周几" clearable>
          <el-option
            v-for="dict in dict.type.sys_week"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="结果" prop="isPass">
        <el-select v-model="queryParams.isPass" placeholder="请选择结果" clearable>
          <el-option
            v-for="dict in dict.type.tkchand"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <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-form>

    <el-row :gutter="10" class="mb8" style=" margin: 0;margin-top: 20px;padding: 10px 5px; ">
    <p class="bgtan" style="margin-top: 0;">调课信息</p>
	 <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['course:change:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['course:change:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['course:change:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['course:change:export']"
        >导出</el-button>
      </el-col> -->
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <div v-if="changeList.length !=0">
      <el-row :gutter="10">
        <el-col :span="6" v-for="(item,index) in changeList" :key="idnex" v-if="changeList.length !=0" style="margin-bottom: 20px;">
           <div style="background: #FFFFFF;border-radius: 4px;">
             <div style="border-bottom: 1px solid #DADADA;" class="ingweflq">
               <div>
                 <span></span>
                 <p>{{item.subjectClass ==null? '暂无数据' : item.subjectClass}}</p>
               </div>
                <img src="../../../assets/images/pic_xyht_tksj_zt_ty.png" alt="">
             </div>

             <div class="tiaonge">
                <div class="ingwlka">
                  <p style="width: 50%;"><span  class="ogtwo">调课科目：</span>
                   <el-tooltip class="item" effect="dark" :content="item.subject" placement="top-start">
                  <span class="isap" style="width: 40%;">
                   {{item.subject ==null? '暂无数据' : item.subject}}
                   </span>
                     </el-tooltip>
                   </p>
                  <p class="ignlq" style="width: 50%;"><span style="" class="ogtwo">被调科目：</span>
                  <el-tooltip class="item" effect="dark" :content="item.beSubject" placement="top-start">
                  <span class="isap" style="width: 40%;">
                   {{item.beSubject ==null? '暂无数据' : item.beSubject}}
                   </span>
                     </el-tooltip>
                  </p>
                </div>
                <p>
                <span>调课周几：<span class="isap">{{item.subjectWeek ==null? '暂无数据' : item.subjectWeek}}</span></span>
                </p>
                <p>
                  <span>被调课周几：</span>
                  <span class="isap">{{item.week ==null? '暂无数据' : item.week}}</span>
                </p>
                <p>
                  <span>调课时间：</span>
                  <span class="isap">{{item.subjectTime ==null? '暂无数据' : item.subjectTime}}({{item.isFrame=='AM'?'上午' : item.isFrame=='PM'?'下午' : '晚上'}})</span>
                </p>
                <p>
                  <span>被调时间：</span>
                  <span class="isap">{{item.beSubjectTime ==null? '暂无数据' : item.beSubjectTime}}({{item.beIsFrame=='AM'?'上午' : item.beIsFrames=='PM'?'下午' : '晚上'}})</span>
                </p>
                <p>
                  <span>申请时间：</span>
                  <span class="isap">{{item.applyTime ==null? '暂无数据' : item.applyTime}}</span>
                </p>
                <div class="ingwlka">
                  <p style="width: 50%;"><span  class="ogtwo">申{{"\xa0\xa0"}}请{{"\xa0"}}人：</span>
                   <el-tooltip class="item" effect="dark" :content="item.applyName" placement="top-start">
                  <span class="isap" style="width: 40%;">
                   {{item.applyName ==null? '暂无数据' : item.applyName}}
                   </span>
                     </el-tooltip>
                   </p>
                  <p class="ignlq" style="width: 50%;">申{{"\xa0\xa0"}}核{{"\xa0"}}人：
                  <el-tooltip class="item" effect="dark" :content="item.auditUser" placement="top-start">
                  <span class="isap" style="width: 40%;">
                   {{item.auditUser ==null? '暂无数据' : item.auditUser}}
                   </span>
                     </el-tooltip>
                  </p>
                </div>
                 <p><span>内容描述：</span>
                 <span class="isap">{{item.content ==null? '暂无数据' : item.content}}</span>
                 </p>
                 <p>
                   <span>审核意见：</span>
                  <span class="isap">{{item.opinion ==null? '暂无数据' : item.opinion}}</span></p>
             </div>
             <div class="tonwbb">
              <p style="color: #5F8BF4;"    @click="getPass(item)"v-if="item.isPass == 1"  v-hasPermi="['course:change:reply']">同意</p>
              <p style="color: #FF6969;" @click="getPass(item)" v-if="item.isPass == 1"  v-hasPermi="['course:change:reply']">不同意</p>
              <p style="color: #00B034;"  @click="handleUpdate(item)"v-hasPermi="['course:change:edit']" v-if="item.isPass == 1">修改</p>
              <p style="color: #FF6969;" @click="handleDelete(item)" v-hasPermi="['course:change:remove']">删除</p>
             </div>
           </div>
        </el-col>



      </el-row>
      <div style="background-color: #fff; padding-bottom: 15px;">
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
    <div v-if="changeList.length ==0" style="text-align: center;margin: 40px 0;">
       <img src="../../../assets/images/pic_xyht_zwsj.png" alt="">
    </div>

   <!-- <div style="background-color: #fff; padding: 0 10px; padding-bottom: 30px; border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;">
	<el-table border :max-height="tableMaxHeight" v-loading="loading" :data="changeList" @selection-change="handleSelectionChange">
	  <el-table-column type="selection" width="55" align="center" />
	  <el-table-column label="调课班级" align="center" prop="subjectClass"  width="120"/>
	  <el-table-column label="调课科目" align="center" prop="subject"  width="120"/>
	  <el-table-column label="被调科目" align="center" prop="beSubject"  width="120"/>
	  <el-table-column label="调课周几" align="center" prop="subjectWeek" width="120">
	    <template slot-scope="scope">
			<div style="display: flex;justify-content: center; text-align: center; width: 100%;">
				<dict-tag :options="dict.type.sys_week" :value="scope.row.subjectWeek"/>
				<span>第{{scope.row.isNum}}节课</span>
			</div>
	    </template>
	  </el-table-column>
	  <el-table-column label="被调课周几" align="center" prop="week" width="120" style="display: flex;">
	    <template slot-scope="scope" >
			<div style="display: flex; justify-content: center; text-align: center; width: 100%;">
				<dict-tag :options="dict.type.sys_week" :value="scope.row.week"/>第{{scope.row.beIsNum}}节课
			</div>
	    </template>
	  </el-table-column>
	  <el-table-column label="调课时间" align="center" prop="subjectTime" width="140">
	    <template slot-scope="scope">
	      <span>{{ scope.row.subjectTime}}</span>
	    </template>
	  </el-table-column>
	  <el-table-column label="被调时间" align="center" prop="beSubjectTime" width="140">
	    <template slot-scope="scope">
	      <span>{{ scope.row.beSubjectTime}}</span>
	    </template>
	  </el-table-column>
	  <el-table-column label="结果" align="center" prop="isPass" width="100">
	    <template slot-scope="scope">
	      <dict-tag :options="dict.type.tkchand" :value="scope.row.isPass"/>
	    </template>
	  </el-table-column>
	  <el-table-column label="申请人" align="center" prop="applyName"  width="100"/>
	  <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
	    <template slot-scope="scope">
	      <span>{{ scope.row.applyTime}}</span>
	    </template>
	  </el-table-column>
	  <el-table-column label="审核人" align="center" prop="auditUser" width="100"/>
	  <el-table-column label="审核意见" align="center" prop="opinion"  width="100"/>
	  <el-table-column label="内容描述" align="center" prop="content" width="100" show-overflow-tooltip/>
	  <el-table-column label="备注" align="center" prop="remark" />
	  <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="180">
	    <template slot-scope="scope">
	      <el-button
	        size="mini"
	        type="text"
	        icon="el-icon-edit"
	        @click="handleUpdate(scope.row)"
	        v-hasPermi="['course:change:edit']"

	      >修改</el-button>
	      <el-button
	        size="mini"
	        type="text"
	        style="background: red;color: #FFF;padding: 7px;"
	        @click="handleDelete(scope.row)"
	        v-hasPermi="['course:change:remove']"
	      >删除</el-button>
		  <el-button
		   size="mini" type="text" style="background: #00B034;color: #FFF;padding: 7px;"
		    @click="getPass(scope.row)"
			v-if="scope.row.isPass == 1"
		    v-hasPermi="['course:change:edit']"
		  >同意</el-button>
		  <el-button
		    size="mini" type="text" style="background: #3FBCEF;color: #FFF;padding: 7px;"
		    @click="infoBtn(scope.row)"
		    v-hasPermi="['course:change:edit']"
			v-if="scope.row.isPass == 1"
		  >不同意</el-button>
	    </template>
	  </el-table-column>
	</el-table>

	<pagination
	  v-show="total>0"
	  :total="total"
	  :page.sync="queryParams.pageNum"
	  :limit.sync="queryParams.pageSize"
	  @pagination="getList"
	/>
   </div> -->


    <!-- 添加或修改调课对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
		  <el-row>
			  <el-col :span="8">
				  <el-form-item label="调课班级" prop="subjectClassId">
				  		  <el-select style="width: 100%;" v-model="form.subjectClassId" placeholder="请选择班级名称">
				  		    <el-option
				  		      v-for="dict in kiueseghs"
				  		      :key="dict.deptId"
				  		      :label="dict.deptName"
				  		      :value="dict.deptId"
				  			  clearable
				  			  @click.native="mjyhess(dict)"
				  		    ></el-option>
				  		  </el-select>
				  </el-form-item>
			  </el-col>
			  <el-col :span="8">
			  	  <el-form-item label="调课科目" prop="subject">
			  	    <el-select style="width: 100%;" v-model="form.subject" placeholder="请选择调课科目">
			  	      <el-option
			  	        v-for="dict in dict.type.sys_subject"
			  	        :key="dict.value"
			  	        :label="dict.label"
			  	        :value="dict.label"
			  	      ></el-option>
			  	    </el-select>
			  	  </el-form-item>
			  </el-col>
			  <el-col :span="8">
			  		<el-form-item label="被调科目" prop="beSubject">
			  		  <el-select style="width: 100%;" v-model="form.beSubject" placeholder="请选择被调科目">
			  		    <el-option
			  		      v-for="dict in dict.type.sys_subject"
			  		      :key="dict.value"
			  		      :label="dict.label"
			  		      :value="dict.label"
			  		    ></el-option>
			  		  </el-select>
			  		</el-form-item>
			  </el-col>
			  <el-col :span="8">
			  		<el-form-item label="周几" prop="week">
			  		  <el-select style="width: 100%;" v-model="form.week" placeholder="请选择周几">
			  		    <el-option
			  		      v-for="dict in dict.type.sys_week"
			  		      :key="dict.value"
			  		      :label="dict.label"
			  		      :value="dict.value"
			  		    ></el-option>
			  		  </el-select>
			  		</el-form-item>
			  </el-col>
			  <el-col :span="8">
			  		<el-form-item label="内容描述">
						<el-input v-model="form.content" type="textarea" placeholder="请输入内容" />
			  		</el-form-item>
			  </el-col>
			  <el-col :span="8">
				  <el-form-item label="备注" prop="remark">
				    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
				  </el-form-item>
			  </el-col>
		  </el-row>
        <!-- <el-form-item label="调课班级id" prop="subjectClassId">
          <el-input v-model="form.subjectClassId" placeholder="请输入调课班级id" />
        </el-form-item> -->


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listChange, getChange, delChange, addChange, updateChange,setPass } from "@/api/system/change";
import { listDept,listDeptode} from "@/api/system/dept";
export default {
  name: "Change",
  dicts: ['sys_subject', 'sys_week','tkchand'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调课表格数据
      changeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  tableMaxHeight:400,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        applyId: null,
        applyName: null,
        applyTime: null,
        subjectClassId: null,
        subjectClass: null,
        subject: null,
        beSubject: null,
        week: null,
        isPass: null,
        content: null,
        auditId: null,
        auditUser: null,
        opinion: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        subjectClassId: [
          { required: true, message: "调课班级id不能为空", trigger: "blur" }
        ],
        subject: [
          { required: true, message: "调课科目不能为空", trigger: "change" }
        ],
        beSubject: [
          { required: true, message: "被调科目不能为空", trigger: "change" }
        ],
        week: [
          { required: true, message: "周几不能为空", trigger: "change" }
        ],
      },
	  kiuesegh:[],
	  kiueseghs:[],
	  nike:''
    };
  },
  created() {
	  window.onresize = () => {
	            this.changeTableMaxHeight()
	          }
	          this.changeTableMaxHeight()
	this.nike = this.$store.state.user.nickName
    this.getList();
	this.getdept(0)

	// console.log(this.$store.state.user,4)

  },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  methods: {
	  getdept(val){
	  		  let kuesf={'parentId':val}
	  		  // this.kiuesegh = []
	  		listDeptode(kuesf).then(response => {
	  		  this.deptOptions = this.handleTree(response.data, "deptId");
	  		  this.deptOptions.filter(rou =>{
	  			  if(rou.children != undefined){
	  			  	rou.children.filter(rour =>{
	  			  		this.kiuesegh.push(rour)
	  			  	})
	  			  }
	  			  // this.kiuesegh = rou.children
	  			  // this.kiuesegh.push(rou.children)
	  			  console.log(rou.children)
	  		  })
	  		  this.kiueseghs = this.kiuesegh
	  		  // this.deptOptions = response.data
	  		  console.log(this.kiuesegh)
	  		});
	  },
    /** 查询调课列表 */
    getList() {
      this.loading = true;
      listChange(this.queryParams).then(response => {
        this.changeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        applyId: null,
        applyName: null,
        applyTime: null,
        subjectClassId: null,
        subjectClass: null,
        subject: null,
        beSubject: null,
        week: null,
        isPass: null,
        content: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        auditId: null,
        auditUser: null,
        opinion: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加调课";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getChange(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改调课";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateChange(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChange(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
	  delChange(ids).then(response => {
	   this.getList();
	   this.$modal.msgSuccess("删除成功");
	  });
      // this.$modal.confirm('是否确认删除调课编号为"' + ids + '"的数据项？').then(function() {
      //   return delChange(ids);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('course/change/export', {
        ...this.queryParams
      }, `change_${new Date().getTime()}.xlsx`)
    },
	mjyhess(val){
		this.form.subjectClass = val.deptName
	},
	getPass(row) {
	  const _this = this
	  this.$confirm('是否同意调课', "提醒", {
	    confirmButtonText: "确定",
	    cancelButtonText: "取消",
	    type: "warning"
	  }).then(function() {
	    return setPass({
	    isPass: 2,
	    id: row.id,
		subjectClassId:row.subjectClassId,
		beSubject:row.beSubject,
	    // xmStatus:row.xmStatus
	  })
	  }).then(() => {
		   _this.getList();
	    _this.msgSuccess("提交成功");
	  })
	},
	infoBtn(row) {
	  const _this = this
	    this.$prompt("请输入不同意意见", "提醒", {
	      confirmButtonText: "确定",
	      cancelButtonText: "取消",
	      type: "warning",
	      inputValidator: (value) => {
	                if(!value) {
	                  return '不同意意见不能为空！';
	                }
	               }
	    })
	      .then(function({ value }) {
	          return setPass({
	           isPass: 3,
	           id: row.id,
	           subjectClassId:row.subjectClassId,
	           beSubject:row.beSubject,
	            opinion:value
	          });

	      })
	      .then(({ value }) => {
	       _this.getList();
	       _this.msgSuccess("提交成功");
	      });
	},
	// 获取屏幕高度
	showFilterForm () {
	      this.filterActive = !this.filterActive
	      this.changeTableMaxHeight()
	    },

	    changeTableMaxHeight () {
	      let height = document.body.offsetHeight // 网页可视区域高度
	      // if (this.filterActive) {
	      //   this.tableMaxHeight = height - 320
	      // } else {
	        this.tableMaxHeight = height - 250
	      // }
	      console.log(height)
	    }
  }
};
</script>

<style scoped lang="scss">

  .ingweflq{
   display: flex;
   align-items: center;
   justify-content: space-between;
   div{
    display: flex;
    align-items: center;
   }
   p{
     font-family: PingFang SC;
     font-weight: 800;
     font-size: 16px;
     color: #161616;
   }
   span{
      width: 8px;
      height: 8px;
      background: #4775EA;
      border-radius: 50%;
      margin-left: 15px;
      margin-right: 10px;
   }
   img{
     width: 70px;
     height: 30px;
   }
  }
  .tiaonge{
    padding: 20px 15px;
    p{
      margin: 0;
      line-height: 29px;
      display: flex;
      span{
        font-weight: bold;
        font-size: 14px;
        color: #161616;
      }
    }
    .isap{

      color: #606266;
      font-weight: 400;
       white-space: nowrap;      /* 确保文本在一行内显示 */
       overflow: hidden;         /* 隐藏溢出的内容 */
      text-overflow: ellipsis;
    }
    .ingwlka{
      display: flex;
      justify-content: space-between;
      .ogtwo{
        font-weight: bold;
        font-size: 14px;
        color: #161616;
      }
      .ignlq{
        font-weight: bold;
        font-size: 14px;
        color: #161616;
      }
      span{
        font-size: 14px;
        color: #161616;
        color: #606266;
        font-weight: 400;
      }

    }
  }
  .tonwbb{
    p{
      margin: 0;
      cursor: pointer;
    }
    height: 40px;
    line-height: 40px;
    border-top: 1px  solid #DADADA;
    display: flex;
    justify-content: space-around;
  }


	.bgtan{
		border-left: 3px solid #4775EA;
		padding-left: 10px;
	}

	.app-container{
		background-color: #f6f6f6;
		// height: 100vh;
	}
</style>
