<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-cascader
            v-model="ids"
            :options="options"
            :props="{ checkStrictly: true }"
            clearable
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="议题编号" prop="issueCode">
          <el-input
            v-model="dataForm.issueCode"
            placeholder="请输入议题编号"
          ></el-input>
        </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="issueContent"
          label="议题内容"
          header-align="center"
          width="185"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="issueCode"
          label="议题编号"
          header-align="center"
          width="142"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="createdTime"
          label="提交时间"
          header-align="center"
          width="152"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="nickName"
          label="提交人"
          header-align="center"
          width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="participateNum"
          label="参与人数"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="approveNum"
          label="支持人数"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="opposeNum"
          label="不支持人数"
          header-align="center"
          width="95"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="commentNum"
          label="评论人数"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="browseNum"
          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:issue:look')"
              type="text"
              size="small"
              @click="detailAction(scope.row.id)"
              >{{ $t('look') }}</el-button
            >
            <el-button
              v-if="$hasPermission('events:issue:deal')"
              type="text"
              size="small"
              @click="dealAction(scope.row.id)"
              >{{ $t('deal') }}</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>
      <!-- 弹窗, 新增 / 修改 -->
      <process-deal
        v-if="processDealVisible"
        ref="processDeal"
        @refreshDataList="getDataList"
      ></process-deal>
      <detail
        v-if="detailVisible"
        ref="detail"
        @refreshDataList="getDataList"
      ></detail>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import ProcessDeal from './issue-process-deal'
import Detail from './issue-close-detail-view'
export default {
  mixins: [mixinViewModule],
  name: 'processlist',
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/events/issue/page',
        getDataListIsPage: true
      },
      detailVisible: false,
      processDealVisible: false,
      dataForm: {
        startTime: '',
        endTime: '',
        streetId: '',
        communityId: '',
        gridId: '',
        state: '0',
        issueCode: ''
      },
      ids: [],
      options: [],
      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: {
    ProcessDeal,
    Detail
  },
  created: function () {
    this.getOptions()
  },
  watch: {
    ids: function (val) {
      if (val.length === 0) {
        this.dataForm.streetId = ''
        this.dataForm.communityId = ''
        this.dataForm.gridId = ''
      }
      if (val.length === 1) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = ''
        this.dataForm.gridId = ''
      }
      if (val.length === 2) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = this.ids[1]
        this.dataForm.gridId = ''
      }
      if (val.length === 3) {
        this.dataForm.streetId = this.ids[0]
        this.dataForm.communityId = this.ids[1]
        this.dataForm.gridId = this.ids[2]
      }
    }
  },
  methods: {
    detailAction (id) {
      this.$parent.selectComponent = 'IssueCloseDetailView'
      this.$router.push({ path: '/events-issue-process', query: { id: id } })
    },
    dealAction (id) {
      this.$parent.selectComponent = 'IssueProcessDetailView'
      this.$router.push({ path: '/events-issue-process', query: { id: id } })
    },
    getOptions () {
      this.$http
        .get(`/sys/user/deptOptions/getByLoginUser`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.options = res.data.options
        })
        .catch(() => {})
    }
  }
}
</script>
