<template>
  <div class="app-container">
    <el-form style="background-color: #fff; padding: 15px 5px; " :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="type">
        <el-select v-model="queryParams.type" placeholder="请选择就餐类型" clearable>
          <el-option
            v-for="dict in dict.type.dining_type"
            :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="  background-color: #fff;margin: 0;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="['system:opinion: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="['register:school: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="['register:school: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="['register:school:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div style="background-color: #fff;padding:20px 15px 15px 15px;" v-if="recipeList.length !=0">
      <el-row :gutter="20">
        <el-col :span="6" v-for="(item,index) in recipeList " :key="index" style="margin-bottom: 15px;">
          <div style="background: #FFFFFF;box-shadow: 0px 0px 10px 0px #CDCDCD;border-radius: 4px;">
            <div class="grid-content " style="padding: 15px;">
              <div style="border-radius: 5px; overflow: hidden;">
                <!-- <img src="../../../assets/images/pic_xyht_yjxx_normal.png" alt="" style="width: 100%; height: 164px;"> -->
                 <image-preview :src="item.urls" :width="100 + '%'" :height="164"/>
              </div>
              <el-tooltip class="item" effect="dark" :content="item.description" placement="top-start">
                   <div style="font-weight: 500;font-size: 14px;color: #606266;line-height: 24px;" class="lngw">
                    {{item.description}}
                   </div>
             </el-tooltip>

            </div>
            <div @click="handleDelete(item)" style="height: 40px; cursor: pointer; line-height: 40px;text-align: center;color: red; border-top: 1px solid #DADADA;">
              删除
            </div>
          </div>
        </el-col>

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

    <div v-if="recipeList.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="schoolList" @selection-change="handleSelectionChange">
		  <el-table-column type="selection" width="55" align="center" />
		  <el-table-column label="建议内容" align="center" prop="opinionDetails"  />
		  <el-table-column label="图片" align="center" prop="opinionPhoto" >
			  <template slot-scope="scope">
			      <image-preview :src="scope.row.opinionPhoto" :width="50" :height="50"/>
			    </template>
			  </el-table-column>
		<el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
		  <template slot-scope="scope">
		    <el-button
		      size="mini"
		      type="text"
		       style="background: red;color: #FFF;padding: 7px;"
		      @click="handleDelete(scope.row)"
		      v-hasPermi="['system:opinion:remove']"
		    >删除</el-button>
		  </template>
		</el-table-column>
		</el-table>


	</div> -->


    <!-- 添加或修改注册-学校对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item  label="建议内容" prop="opinionDetails">
          <el-input type="textarea"  v-model="form.opinionDetails" placeholder="请输入建议内容" />
        </el-form-item>
		<el-form-item label="图片" prop="opinionPhoto">
			<image-upload v-model="form.opinionPhoto"/>
		</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 { listLeave,addLeave,delLeave} from "@/api/zhihuixy/recipe";

export default {
  name: "School",
  dicts: ['shhjg','dining_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 注册-学校表格数据
      recipeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  tableMaxHeight:400,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        schoolName: null,
        userName: null,
        userPhone: null,
        isPass: null,
        createDate:null,
        type:null,
		params:{},

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        opinionDetails: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],

      }
    };
  },
  created() {
	  window.onresize = () => {
	            this.changeTableMaxHeight()
	          }
	          this.changeTableMaxHeight()
    this.getList();
  },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  methods: {
    /** 查询定位信息 */
    getList() {
      this.loading = true;
	  this.queryParams.params.role=this.roleqh()
      listLeave(this.queryParams).then(response => {
        this.recipeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        opinionId: null,
        opinionDetails: null,
		opinionPhoto: null,
        remark: 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.opinionId || this.ids
      getSchool(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) {
            updateSchool(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLeave(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
	  delLeave(ids).then(response => {
	      this.getList();
	      this.$modal.msgSuccess("删除成功");
	  });
      // this.$modal.confirm('是否确认删除注册-学校编号为"' + ids + '"的数据项？').then(function() {
      //   return delSchool(ids);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('register/school/export', {
        ...this.queryParams
      }, `school_${new Date().getTime()}.xlsx`)
    },
	getPass(row) {
	  const _this = this
	  this.$confirm('是否审核通过', "提醒", {
	    confirmButtonText: "确定",
	    cancelButtonText: "取消",
	    type: "warning"
	  }).then(function() {
	    return setPass({
	    type: 1,
	    dataId: row.id,
		shjg:2,
	    // 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({
	            shjg: 3,
	            type: 1,
	            dataId: row.id,
	            shyj:value
	          });

	      })
	      .then(({ value }) => {
	        _this.msgSuccess("驳回成功");
	        _this.getList();
	      });
	},
	// 获取屏幕高度
	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">
	.bgtan{
		border-left: 3px solid #4775EA;
		padding-left: 10px;
	}

	.app-container{
		background-color: #f6f6f6;
		// height: 100vh;
	}
  .lngw{
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    cursor: pointer;
  }
</style>
