<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class="mod-demo__epdcevents}">
      <el-form :inline="true"
               :model="dataForm"
               @keyup.enter.native="getDataListSearch()">
        <el-form-item label="所属机构" label-width="72px">
          <el-cascader v-model="ids" :options="options" :props="{ checkStrictly: true }" clearable style="width:200px;">
          </el-cascader>
        </el-form-item>
        <el-form-item label="议题内容">
          <el-input
                  v-model="dataForm.eventContent"
                  placeholder="请输入议题内容"
                  clearable
                  @keyup.native="btKeyUpEventContent"
                  style="width:200px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="提交人">
          <el-input
                  v-model="dataForm.nickName"
                  placeholder="请输入议题提交人"
                  clearable
                  @keyup.native="btKeyUpNickName"
                  style="width:200px;"
          ></el-input>
        </el-form-item>
        <br>
        <el-form-item label="提交时间"
                      prop="expirationDate" label-width="72px">
          <el-date-picker v-model="dataForm.expirationDate"
                          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="至"
                      label-width="25px"
                      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>
      <el-table v-loading="dataListLoading"
                :data="dataList"
                border
                @selection-change="dataListSelectionChangeHandle"
                style="width: 100%;">
        <el-table-column label="序号"
                         type="index"
                         show-overflow-tooltip
                         align="center"
                         width="50"></el-table-column>
        <el-table-column prop="eventContent"
                         label="议题内容"
                         header-align="center"
                         min-width="400"
                         align="left"
                         show-overflow-tooltip></el-table-column>
        <el-table-column prop="createdTime"
                         label="提交时间"
                         header-align="center"
                         width="180px"
                         align="center"></el-table-column>
        <el-table-column prop="nickName"
                         label="提交人"
                         header-align="center"
                         min-width="120"
                         align="center"
                         show-overflow-tooltip></el-table-column>
        <el-table-column :label="$t('handle')"
                         fixed="right"
                         header-align="center"
                         align="center"
                         width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('events:epdcevents:verify')"
                       type="text"
                       size="small"
                       @click="detailAction(scope.row.id)">{{ $t('verify') }}</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>
      <!-- 弹窗, 新增 / 修改 -->
      <review-detail v-if="reviewDetailVisible"
                     ref="reviewDetail"
                     @refreshDataList="getDataList"></review-detail>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import ReviewDetail from './issue-review-detail'
export default {
  mixins: [mixinViewModule],
  name: 'issueReviewList',
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/events/epdcevents/page',
        getDataListIsPage: true,
        deleteURL: '/events/epdcevents',
        deleteIsBatch: true
      },
      reviewDetailVisible: false,
      dataForm: {
        startTime: '',
        endTime: '',
        streetId: '',
        communityId: '',
        deptId: '',
        eventContent: '',
        nickName: ''
      },
      ids: [],
      options: [],
      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()
          }
        }
      }
    }
  },
  components: {
    ReviewDetail
  },
  created: function () {
    this.getOptions()
  },
  watch: {
    'ids': function (val) {
      if (val.length === 0) {
        this.dataForm.streetId = ''
        this.dataForm.communityId = ''
        this.dataForm.deptId = ''
      }
      if (val.length === 1) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = ''
        this.dataForm.deptId = ''
      }
      if (val.length === 2) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = this.ids[1]
        this.dataForm.deptId = ''
      }
      if (val.length === 3) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = this.ids[1]
        this.dataForm.deptId = this.ids[2]
      }
    }
  },
  methods: {
    detailAction (id) {
      this.$parent.selectComponent = 'IssueReviewDetailView'
      this.$router.push({ path: '/events-issue-review', query: { id: id } })
    },
    getOptions () {
      var paa = {deptType:'party'}
      this.$http.post(`/sys/user/deptOptions/getByLoginUserNew`,paa).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.options = res.data.options
      }).catch(() => {})
    },
    btKeyUpEventContent (e) {
        e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
        this.dataForm.eventContent = e.target.value
    },
    btKeyUpNickName (e) {
        e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
        this.dataForm.nickName = e.target.value
    }
  }
}
</script>
