<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-news__monthexcellentcase}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataListSearch()">
        <div>
        <el-form-item label="案例内容" prop="content" label-width="90px">
          <el-input v-model="dataForm.content" placeholder="案例内容" clearable maxlength="20" @keyup.native="btKeyUpContent" style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="发布人" prop="nickName" label-width="90px">
          <el-input v-model="dataForm.nickName" placeholder="发布人" clearable maxlength="10" @keyup.native="btKeyUpNickName" style="width:200px"></el-input>
        </el-form-item>
        </div>
        <el-form-item label="所属机构" label-width="90px">
          <el-cascader
            v-model="ids"
            :options="options"
            :props="{ checkStrictly: true }"
            clearable
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="发布时间" prop="startTime" label-width="90px">
          <el-date-picker v-model="dataForm.startTime"
                          type="date"
                          :picker-options="pickerBeginDateBefore"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间"
                          style="width:200px" @change="changeTime">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="至" prop="endTime">
          <el-date-picker v-model="dataForm.endTime"
                          type="date"
                          :picker-options="pickerBeginDateAfter"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间"
                          style="width:200px" @change="changeTime">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="getDataListSearch()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('news:monthexcellentcase:save')" type="success" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('news:monthexcellentcase:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column label="序号" header-align="center" align="center" width="50px">
            <template slot-scope="scope">
                {{scope.$index+1}}
            </template>
        </el-table-column>
        <el-table-column prop="month" label="月份" header-align="center" align="center" width="150"></el-table-column>
        <el-table-column prop="content" label="内容" header-align="center" align="left" min-width="400" show-overflow-tooltip></el-table-column>
        <el-table-column prop="nickName" label="发布人" header-align="center" align="center" width="250"></el-table-column>
        <el-table-column prop="createdTime" label="发布时间" header-align="center" align="center" width="250"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button :disabled="scope.row.isUpdate == '0'" type="text" size="small" @click="addHandle(scope.row.id,'0')">{{ $t('update') }}</el-button>
            <el-button type="text" size="small" @click="addHandle(scope.row.id,'1')">{{ '查看' }}</el-button>
            <el-button v-if="$hasPermission('news:monthexcellentcase:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('news:monthexcellentcase:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './monthexcellentcase-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/workRecord/monthexcellentcase/page',
        getDataListIsPage: true,
        deleteURL: '/workRecord/monthexcellentcase',
        deleteIsBatch: true,
        exportURL: '/workRecord/monthexcellentcase/export'
      },
      dataForm: {
        id: '',
        content: '',
        nickName: '',
        startTime: '',
        endTime: ''
      },
      pickerBeginDateBefore: {
        disabledDate: (time) => {
          let beginDateVal = this.dataForm.endTime
          if (beginDateVal) {
            return time.getTime() > new Date(beginDateVal + ' 00:00:00').getTime()
          }
        }
      },
      pickerBeginDateAfter: {
        disabledDate: (time) => {
          let EndDateVal = this.dataForm.startTime
          if (EndDateVal) {
            return time.getTime() < new Date(EndDateVal + ' 00:00:00').getTime()
          }
        }
      },
      ids: [],
      options: []
    }
  },
  components: {
    AddOrUpdate
  },
  watch: {
    ids: function (val) {
      if (val.length === 0) {
        this.dataForm.deptId = ''
      } else {
        this.dataForm.deptId = this.ids[val.length - 1]
      }
    }
  },
  created: function () {
    this.getDataList()
    this.getOptions()
  },
  methods: {
    addHandle (id, disabled) {
      this.$parent.selectComponent = 'MonthexcellentcaseDetail'
      this.$router.push({ path: '/workRecord-Monthexcellentcaseroute', query: { id: id, disabled: disabled } })
    },
    getOptions () {
      this.$http
        .get(`/sys/user/deptOptions/getDeptAuthByUser`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.options = res.data.options
        })
        .catch(() => {})
    },
    btKeyUpContent (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '')
      this.dataForm.content = e.target.value
    },
    btKeyUpNickName (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '')
      this.dataForm.nickName = e.target.value
    }
  }
}
</script>
<style>
.el-tooltip__popper {
  max-width: 80%;
  color: #353434 !important;
  background:#e6eaebf3 !important;
  word-break:break-all;
}
</style>
