<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px;">
      <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;">
        <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;">
       <span style="margin-left: 10px;">投诉建议</span>
      </p>
      <div style="background: #F3F3F3;padding: 20px 15px; padding-bottom: 0;margin-bottom: 20px;">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
        <el-col :span="8">
         <el-form-item label="标题" prop="title">
           <el-input
             v-model="queryParams.title"
             placeholder="请输入投诉建议标题，简要描述投诉或建议内容"
             clearable
             @keyup.enter.native="handleQuery"
           />
         </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="提交时间" prop="createdTime">
            <el-date-picker clearable
              v-model="queryParams.createdTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择投诉建议提交时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否公开" prop="isPublic">
            <el-select v-model="queryParams.isPublic" placeholder="请选择投诉建议是否公开" clearable>
              <el-option
                v-for="dict in dict.type.sys_yes_no"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择投诉建议状态" clearable>
              <el-option
                v-for="dict in dict.type.complaint_types"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item class="butt">
            <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
            <el-button  size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    </div>
    <div class="casr">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wuYe:suggestion:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wuYe:suggestion:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wuYe:suggestion:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['wuYe:suggestion:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table :max-height="tableMaxHeight" v-loading="loading" :data="suggestionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="内容" align="center" prop="content" width="180"show-overflow-tooltip/>
      <el-table-column label="投诉照片" align="center" prop="images" >
      <template slot-scope="scope">
         <image-preview :src="scope.row.images" :width="50" :height="50"/>
      </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.createdTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.complaint_types" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="回复内容" align="center" prop="replyContent" width="180" show-overflow-tooltip/>
      <!-- <el-table-column label="投诉建议类型：complaint" align="center" prop="type" /> -->
      <el-table-column label="是否公开" align="center" prop="isPublic">
        <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isPublic"
              active-value="Y"
              inactive-value="N"
              @change="handleStatusChange(scope.row)"
            ></el-switch>
          </template>
        </el-table-column>
      <el-table-column label="操作" align="center"  class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status == 1"
            @click="handleUpdateg(scope.row)"
            v-hasPermi="['wuYe:suggestion:edit']"
          >回复</el-button>
          <!-- v-if="scope.row.status == 1" -->
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status == 2"
            style="color: #28C529;"
            @click="handleUpdate(scope.row)"
          >查看回复</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wuYe:suggestion:remove']"
            style="color: red;"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>

    <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="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="回复内容" prop="replyContent">
              <!-- <editor v-model="form.replyContent" :min-height="192"/> -->
              <el-input v-model="form.replyContent" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="上传附件">
             <fileUploadh :limit="20" v-model="form.suggestionFjList" />
            </el-form-item>
          </el-col>
        </el-row>
      </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 { listSuggestion, getSuggestion, delSuggestion, addSuggestion, updateSuggestion } from "@/api/wuguan/suggestion";

export default {
  name: "Suggestion",
  dicts: ['sys_yes_no', 'complaint_types'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投诉建议表格数据
      suggestionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        content: null,
        images: null,
        createdTime: null,
        status: null,
        replyContent: null,
        type: null,
        isPublic: null,
        isDel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        replyContent: [
                  { required: true, message: "不能为空", trigger: "blur" }
                ],
      },
      tableMaxHeight:'200',
    };
  },
  created() {
    this.getList();
  window.onresize = () => {
  	      this.changeTableMaxHeight()
  	    }
  	    this.changeTableMaxHeight()
  },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  methods: {
    /** 查询投诉建议列表 */
    getList() {
      this.loading = true;
      listSuggestion(this.queryParams).then(response => {
        this.suggestionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        suggestionId: null,
        title: null,
        content: null,
        images: null,
        createdTime: null,
        status: null,
        replyContent: null,
        type: null,
        isPublic: null,
        isDel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: 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.suggestionId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "投诉建议回复";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const suggestionId = row.suggestionId || this.ids
      getSuggestion(suggestionId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看投诉建议回复";
      });
    },
    handleUpdateg(row){
       this.reset();
       getSuggestion( row.suggestionId).then(response => {
         this.form.suggestionId = response.data.suggestionId;
         this.form.status = 2
        this.open = true;
        this.title = "投诉建议回复";
       });

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.form)
          // return
          if (this.form.suggestionId != null) {
            if(this.form.suggestionFjList != null ){
              this.form.suggestionFjList.filter(rou=>{
                rou.suggestionId = this.form.suggestionId
              })
            }
            // this.form.status = 2
            updateSuggestion(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSuggestion(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    getti(row){
      updateSuggestion(row).then(response => {
        // this.$modal.msgSuccess("操作成功");
        // this.open = false;
        // this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const suggestionIds = row.suggestionId || this.ids;
      this.$modal.confirm('是否确认删除投诉建议编号为"' + suggestionIds + '"的数据项？').then(function() {
        return delSuggestion(suggestionIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuYe/suggestion/export', {
        ...this.queryParams
      }, `suggestion_${new Date().getTime()}.xlsx`)
    },
    handleStatusChange(row) {
      let text = row.isPublic === "Y" ? "启用" : "停用";
      var that = this
      this.$modal.confirm('确认要"' + text + '"吗？').then(function() {
         that.getti(row);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.isPublic = row.isPublic === "Y" ? "N" : "Y";
      });
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 150
          // }
          console.log(height)
        }
  }
};
</script>
<style  lang="scss">
  .butt{
    .el-button--small{
      padding: 9px 23px !important;
      font-size: 14px;
    }
  }
  .casr{
    .el-tabs__item.is-active{
      color: #196CFF;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item{
      padding: 0  30px !important;
    }
  }
  .el-table .el-table__header-wrapper th{
    background-color:#F5F6F8;
    color:#343434;
  }
  .el-table{
    color:#343434;
  }
</style>
<style scoped lang="scss">
  .goe{
    p{
      margin: 0;
      font-weight: 800;
      font-size: 16px;
      color: #161616;
      margin-top: 10px;
      margin-bottom: 3px;
      padding: 0 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      display:-webkit-box; //作为弹性伸缩盒子模型显示。
      -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
      -webkit-line-clamp:1; //显示的行
    }
    p:nth-child(2){
      // margin-bottom: 10px;
      margin-top: 0;
     font-weight: 400;
     font-size: 14px;
     color: #AAAAAA;
     display: flex;
     justify-content: space-between;
     align-items: center;
     padding-bottom: 10px;
     span:nth-child(2){
       padding: 3px 5px;
       background: #EDEDED;
       border-radius: 10px;
     }
    }
  }
  .ingwe{
    border: 2px solid #196CFF;
  }
  </style>
