<template>
  <el-card shadow="never"
           class="aui-card--fill">
    <div class="mod-demo__epdcevents}">
      <el-form :inline="true"
               :model="dataForm"
               @keyup.enter.native="getDataList()">
        <el-form-item label="街道">
          <el-select v-model="dataForm.streetId"
                     placeholder="请选择"
                     clearable
                     @change="getCommunityList">
            <el-option v-for="item in streetOptions"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="社区">
          <el-select v-model="dataForm.communityId"
                     placeholder="请选择"
                     clearable
                     @change="getGridList">
            <el-option v-for="item in communityOptions"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="网格">
          <el-select v-model="dataForm.gridId"
          clearable placeholder="请选择">
            <el-option v-for="item in gridOptions"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间"
                      prop="startTime">
          <el-date-picker v-model="dataForm.startTime"
                          type="date"
                          :picker-options="pickerBeginDateBefore"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间">
          </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="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $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"
                         width="520"
                         align="center"></el-table-column>
        <el-table-column prop="createdTime"
                         label="提交时间"
                         header-align="center"
                         align="center"></el-table-column>
        <el-table-column prop="nickName"
                         label="提交人"
                         header-align="center"
                         align="center"></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: '',
        gridId: ''
      },
      streetOptions: [],
      communityOptions: [],
      gridOptions: [],
      pickerBeginDateBefore: {
        disabledDate: (time) => {
          let beginDateVal = this.dataForm.startTime
          if (beginDateVal) {
            return time.getTime() > new Date(beginDateVal).getTime()
          }
        }
      },
      pickerBeginDateAfter: {
        disabledDate: (time) => {
          let EndDateVal = this.dataForm.endTime
          if (EndDateVal) {
            return time.getTime() < new Date(EndDateVal).getTime()
          }
        }
      }
    }
  },
  components: {
    ReviewDetail
  },
  created: function () {
    this.getStreetList()
  },
  methods: {
    detailAction (id) {
      this.$parent.selectComponent = 'IssueReviewDetailView'
      this.$router.push({ path: '/events-issue-review', query: { id: id } })
    },
    getStreetList () {
      this.$http.get(`/sys/dept/sublist/` + (localStorage.getItem('street') === null ? '1169154711480528897' : localStorage.getItem('street'))).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.streetOptions = res.data
      }).catch(() => { })
    },
    getCommunityList () {
      if (this.dataForm.streetId === '') {
        this.communityOptions = []
        this.gridOptions = []
        this.dataForm.communityId = ''
        this.dataForm.gridId = ''
        return
      }
      this.dataForm.communityId = ''
      this.dataForm.gridId = ''
      this.$http.get(`/sys/dept/sublist/` + this.dataForm.streetId).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.communityOptions = res.data
      }).catch(() => { })
    },
    getGridList () {
      if (this.dataForm.communityId === '') {
        this.gridOptions = []
        this.dataForm.gridId = ''
        return
      }
      this.dataForm.gridId = ''
      this.$http.get(`/sys/dept/sublist/` + this.dataForm.communityId).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.gridOptions = res.data
      }).catch(() => { })
    }
  }
}
</script>
