<template>
  <div class="app-content">
    <div class="search">
      <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="操作模块" class="filter-item" style="width: 120px;" clearable>
        <el-option v-for="item in operationModuleList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-input v-model="table.getdataListParm.parammaps.rolename" placeholder="操作内容" style="width: 180px;" class="filter-item" clearable />
      <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="操作人" class="filter-item" style="width: 120px;" clearable>
        <el-option v-for="item in operationModuleList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-date-picker ref="inputDatetime" v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
      <el-button class="successBorder" @click="handleSearch">查询</el-button>
      <el-button class="successBorder" @click="handleRefresh">重置</el-button>
    </div>
    <div class="table">
      <el-table
        :key="table.tableKey"
        v-loading="table.listLoading"
        element-loading-text="给我一点时间"
        :data="table.list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
      >
        <el-table-column label="序号" align="center" type="index" width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作模块" min-width="130px" align="center" prop="rolename" />
        <el-table-column label="操作内容" min-width="130px" align="center" prop="rolename" />
        <el-table-column label="操作人" min-width="130px" align="center" prop="rolename" />
        <el-table-column label="操作时间" min-width="130px" align="center" prop="rolename" />
        <el-table-column label="操作" align="center" width="50px" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">
            <el-button class="miniSuccess" icon="el-icon-search" @click="handleSee(row)" />
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
    </div>

    <el-dialog :title="textMap[see.dialogStatus]" :visible.sync="see.dialogFormVisible" :close-on-click-modal="false" width="30%">
      <div class="app-add">
        <el-form :model="see.temp" label-position="right" label-width="110px" style="width: 90%;margin:0 auto 50px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="操作模块:" prop="rolename">
                <span>{{ see.temp.rolename }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="操作内容:" prop="rolename">
                <span>{{ see.temp.rolename }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="操作人:" prop="rolename">
                <span>{{ see.temp.rolename }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="操作时间:" prop="rolename">
                <span>{{ see.temp.rolename }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="操作详情:" prop="rolename">
                <span>{{ see.temp.rolename }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose cancelClose1" @click="see.dialogFormVisible = false; ">关闭</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { GetDataByName } from '@/api/common'
import Cookies from 'js-cookie'
import { parseTime } from '@/utils/index.js'
import Pagination from '@/components/Pagination'
export default {
  name: 'Operation',
  components: { Pagination },
  data() {
    return {
      operationModuleList: [], // 操作模块
      table: {
        getdataListParm: {
          name: 'getRoleList',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pageCount')),
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            rolename: '',
            createmp: '',
            enable: '',
            startTime: '',
            stopTime: '',
            inputDatetime: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },
      see: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: {}
      },
      textMap: {
        see: '操作详情'
      },
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },
  created() {
    this.getList()
  },

  methods: {
    getList() {
      this.table.listLoading = true
      GetDataByName(this.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.table.list = response.data.list
          this.table.pageNum = response.data.pageNum
          this.table.pageSize = response.data.pageSize
          this.table.total = response.data.total
        } else {
          this.table.list = []
        }
        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    },
    handleSearch() {
      if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
        this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
        this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      } else {
        this.table.getdataListParm.parammaps.inputDatetime = ''
        this.table.getdataListParm.parammaps.startTime = ''
        this.table.getdataListParm.parammaps.stopTime = ''
      }
      this.table.getdataListParm.offset = 1
      this.getList()
    },
    handleRefresh() {
      console.log('点击了重置')
    },
    handleSee(row) {
      this.see.dialogStatus = 'see'
      this.see.dialogFormVisible = true
      this.see.temp = Object.assign({}, row)
    }
  }
}
</script>
<style lang="scss" scoped>
  .search{margin-top:10px;}
  .table{margin-top:10px;}
</style>
