<template>
  <div class="container">
    <!-- 查询配置 -->
    <div style="padding: 0px 20px">
      <div ref="lxHeader">
        <LxHeader icon="md-apps" text="投诉建议" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content"></div>
          <slot>
            <div>
              <Input style="width: 200px; margin-right: 10px" v-model="searchFields.KeyWord" placeholder="关键字搜索" />
              <Button type="primary" @click="load" style="margin-left: 10px">查询</Button>

            </div>
          </slot>
        </LxHeader>
      </div>
      <div class="table-tree">
        <el-table :data="tableData" :height="tableHeight" style="width: 100%">
          <el-table-column type="index" width="50" align="center" label="序号"> </el-table-column>
          <el-table-column :prop="column.field" :align="column.align" v-for="(column,index) in columns"
            :label="column.title" :width="column.width">
            <template slot-scope="scope">
              <div v-if="column.type=='opt'">
                <Button ghost size="small" @click="show(scope.row)" type="primary"
                  style="margin-left: 10px;">查看</Button>
                  <Button ghost size="small" type="error" @click="del(scope.row)" style="margin-left: 10px;">删除</Button>
              </div>
              <div v-else>{{scope.row[column.field]}}</div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination @current-change="handleCurrentChange" :current-page="paginations.page"
            :page-size="paginations.page_size" background layout="prev, pager, next" :total="paginations.total">
          </el-pagination>
        </div>
      </div>
    </div>
    <el-dialog title="内容查看" :visible.sync="dialogFormVisible" fullscreen>
       <div class="dialogConcent" :style="{height:clientHeight+'px'}">
         <el-scrollbar style="flex: 1">
           <el-form :model="form" ref="form" label-position="right" :label-width="formLabelWidth">
             <el-form-item label="标题" prop="name">
               <div>
                 {{form.name}}
               </div>
             </el-form-item>
             <el-form-item label="内容" prop="content">
               <div style="width: 99.9%;" v-html="form.content">
               </div>
             </el-form-item>
           </el-form>
         </el-scrollbar>
       </div>
       <div slot="footer" class="dialog-footer">
         <el-button @click="resetForm('form')">关 闭</el-button>
       </div>
     </el-dialog>
  </div>
</template>
<script>
  import LxHeader from "@/components/LxHeader/index.vue";
  import {
    listtip,
    get,
    del
  } from "../../../api/resource/complaint.js";
  export default {
    components: {
      LxHeader
    },
    data() {
      return {
        dialogFormVisible: false,
        formLabelWidth: "120px",
        tableHeight: 0,
        clientHeight:0,
        //查询条件字段
        searchFields: {
          KeyWord: ""
        },
        paginations: {
          page: 1,
          page_size: 15,
          total: 0
        },
        tableData: [],
        form: {
          name:"",
          content:""
        },
        columns: [{
            field: "name",
            title: "标题",
            type: "string",
          },
          {
            field: "操作",
            title: "操作",
            width: 220,
            type: "opt",
          }
        ],
      }
    },
    created() {
      this.initLoad();
      this.load();
    },
    mounted() {},
    methods: {
      initLoad() {
        var that = this;
        var clientHeight = document.documentElement.clientHeight
        var lxHeader_height = 96.5; //查询 头部
        var paginationHeight = 37; //分页的高度
        var topHeight = 50; //页面 头部
        let tableHeight = clientHeight - lxHeader_height - topHeight - paginationHeight - 20;
        that.tableHeight = tableHeight;
      },
      load() {
        var that = this;
        listtip({
          page: this.paginations.page,
          page_size: this.paginations.page_size,
          name:this.searchFields.name
        }).then(res => {
          this.tableData = res.data;
          this.paginations.total = res.total
        }).catch(error => {

        })

      },
      info(obj) {
        var that = this;
        get(obj.id).then(res => {
          let result = Object.assign(that.form, res);
          that.form = result;
          this.$refs.tiny.setContent(result.content);
        }).catch(error => {
          //reject(error)
        })
      },
      show(obj) {
        this.form = this.$options.data().form;
        this.clientHeight = document.documentElement.clientHeight - 84 - 110;
        if (obj) {
          var that = this;
          that.info(obj);
        }
        this.dialogFormVisible = true;
      },
      del(obj) {
        var that = this;
        if (obj) {
          this.$Modal.confirm({
            title: '确认要删除数据？',
            onOk: () => {
              del(obj.id).then(response => {
                this.$Message.success('操作成功');
                that.load();
              }).catch(error => {
                console.log(error)
                reject(error)
              })
            },
            onCancel: () => {
              //this.$Message.info('Clicked cancel');
            }
          });
        }
      },
      resetForm(formName) {
        var that = this;
        this.$refs[formName].resetFields();
        that.dialogFormVisible = false;
      },
      handleCurrentChange(page) {
        this.paginations.page = page;
        this.load();
      }
    }
  };
</script>
