<template>
  <div class="app-container">
    <div style="margin-left:16px;">
      <div v-show="viewState == 1">
        <button-bar ref="btnbar" :btndisabled="btndisabled" @btnhandle="btnHandle" />
        <div class="main-content">
          <div class="searchcon">
            <el-button size="small" class="searchbtn" @click="clicksearchShow">
              {{ searchxianshitit }}
            </el-button>
            <div v-show="isSearchShow" class="search">
              <el-form ref="queryParams" :inline="true" :model="queryParams" class="tab-header">
                <el-form-item label="消息类型">
                  <el-select v-model="queryParams.params.messageKey" filterable placeholder="请选择" clearable>
                    <el-option v-for="item in state_list" :key="item.dictKey" :label="item.dictValue"
                      :value="item.dictKey"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="消息来源">
                  <el-input v-model="queryParams.params.messageSource" placeholder="" clearable />
                </el-form-item>
                <el-form-item label="消息标题">
                  <el-input v-model="queryParams.params.messageTitle" placeholder="" clearable />
                </el-form-item>
                <el-form-item label="发送人">
                  <el-input v-model="queryParams.params.messageSender" placeholder="" clearable />
                </el-form-item>
                <el-form-item label="接收日期">
                  <el-date-picker v-model="queryParams.params.messagStartDate" type="date" clearable
                    value-format="yyyy-MM-dd" placeholder="选择日期" />
                  <span style="padding: 0 8px">至</span>
                  <el-date-picker v-model="queryParams.params.messagEndDate" type="date" clearable
                    value-format="yyyy-MM-dd" placeholder="选择日期" />
                </el-form-item>
              </el-form>
              <div class="btn" style="text-align: center;">
                <el-button type="primary" size="small" icon="el-icon-search" @click="dosearch">查询</el-button>
                <el-button type="primary" size="small" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              </div>
            </div>
          </div>
          <!-- Start 项目列表头部 -->
          <div class="listtop" style="margin-top: 30px;">
            <div class="tit" >消息列表</div>
          </div>
          <!-- End 项目列表头部 -->
          <!-- Start 项目列表 -->
          <div class="">
            <el-table v-loading="tableLoading" :data="dataList" border style="width: 100%"
              @selection-change="handleSelectionChange">
              <el-table-column width="50" type="selection" align="center" />
              <el-table-column width="60" label="序号" type="index" :index="indexMethod" align="center" />
              <el-table-column prop="messageSender"  width="180"  label="发送人" align="center" />
              <el-table-column prop="messageTitle" width="180" label="标题" align="center">
                <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="toInfo(scope.row)">查看</el-button>
                </template>
              </el-table-column>
              <el-table-column prop="messagStartDate" label="日期" align="center" />
              <el-table-column prop="messageType" label="消息类别" align="center"  />
              <el-table-column prop="messageSource" label="消息来源" align="center"  />
            </el-table>
          </div>
          <!-- End 项目列表 -->
          <div class="pages">
            <div class="tit" />
            <!--  翻页  -->
            <pagination v-show="dataList.length > 0" :total="queryParams.total" :page.sync="queryParams.current"
              :limit.sync="queryParams.size" @pagination="loadList" />
          </div>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import req from '@/api/supervise/thresholdanalysis'
  import ButtonBar from '@/components/ButtonBar'
  import Pagination from '@/components/pagination'
  import pageye from '@/components/pagination/pageye'
  import * as echarts from 'echarts';

  export default {
    components: {
      ButtonBar,
      Pagination,
      pageye
    },
    // components: {  },
    data() {
      return {
        btndisabled: false,
        viewState: 1, // 1、列表 2、添加 3、修改 4、查看
        isSearchShow: false,
        searchxianshitit: '显示查询条件',
        tableLoading: false,
        tableKey: 0,
        // 类型1.全部,2.常规商品3.烟草
        state_list: [{
            dictKey: 1,
            dictValue: '全部'
          },
          {
            dictKey: 2,
            dictValue: '常规商品'
          }, {
            dictKey: 3,
            dictValue: '烟草'
          }
        ],
        btnList: [ // 右上角按钮
          {
            type: 'danger',
            size: 'small',
            icon: 'del',
            btnKey: 'doDel',
            btnLabel: '删除'
          },
          {
            type: 'info',
            size: 'small',
            icon: 'cross',
            btnKey: 'doClose',
            btnLabel: '关闭'
          }
        ],
        queryParams: {
          current: 1,
          size: 10,
          total: 0,
          params: {
            customerSid: '',
            messageKey: "",
            messageSource: "",
            messageTitle: '',
            messageSender: "",
            messagStartDate: "",
            messagEndDate: ""
          }
        },
        nowDate: new Date().getFullYear() + "-" + (new Date().getMonth() + 1) + "-" + new Date().getDate(),
        dataList: [{
          sid: "1",
          messageSender: '发送人1',
          messageTitle: '标题1',
          messagStartDate: '开始日期1',
          messageType: '消息类型1',
          messageSource: '消息来源1',
        }, ],
      }
    },
    mounted() {
      this.$refs['btnbar'].setButtonList(this.btnList)
    },
    created() {
      // this.loadList()
    },
    methods: {
      // 搜索条件效果
      clicksearchShow() {
        this.isSearchShow = !this.isSearchShow
        if (this.isSearchShow) {
          this.searchxianshitit = '隐藏查询条件'
        } else {
          this.searchxianshitit = '显示查询条件'
        }
      },
      btnHandle(btnKey) {
        switch (btnKey) {
          case 'toAdd':
            this.toAdd()
            break
          case 'doDel':
            this.doDel()
            break
          case 'doClose':
            this.doClose()
            break
          default:
            break
        }
      },
      loadList() {
        this.tableLoading = true
        let _this = this
        req.listPage(_this.queryParams).then((resp) => {
          _this.tableLoading = false
          if (resp.success) {
            console.log('11111', resp.data)
            const data = resp.data
            _this.queryParams.total = data.total
            _this.thresholdAnalysisTable = data.thresholdAnalysisTable
            _this.tableLoading = false
          } else {
            // 根据resp.code进行异常情况处理
            _this.thresholdAnalysisTable = []
            _this.queryParams.total = 0
          }
        }).catch(() => {
          _this.tableLoading = false
        })
      },
      // 序号
      indexMethod(index) {
        var pagestart = (this.queryParams.current - 1) * this.queryParams.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },
      dosearch() {
        this.nowDate = this.queryParams.date;
        this.loadList();

      },
      resetQuery() {
        this.queryParams = {
          current: 1,
          size: 10,
          total: 0,
          params: {
            customerSid: '',
            customerSid: '',
            messageKey: "",
            messageSource: "",
            messageTitle: '',
            messageSender: "",
            messagStartDate: "",
            messagEndDate: ""
          }
        }
        this.loadList()
      },
      // 导出
      doBuild() {
        this.$message({
          showClose: true,
          type: 'success',
          message: '功能暂未完善...'
        })
      },
      // 返回
      doClose() {
        this.$store.dispatch('tagsView/delView', this.$route)
        this.$router.go(-1)
      }
    }
  }
</script>

<style>
  .current-data {
    width: 100%;
    height: 500px;
  }

  .current-data .upper {
    width: 100%;
    height: 100px;
  }

  .current-data .lower {
    width: 100%;
    height: 600px;
    float: left;
    margin-left: 10px;

  }
</style>
