<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-news__topic}">
      <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="排序规则">
          <el-select v-model="dataForm.orderType" placeholder="请选择">
            <el-option
              v-for="item in sortOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转项目时间"
                      prop="startTime">
          <el-date-picker v-model="dataForm.changeItemStartTime"
                          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.changeItemEndTime"
                          type="date"
                          :picker-options="pickerBeginDateAfter"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目状态">
          <el-select v-model="dataForm.itemState" placeholder="全部" clearable >
            <el-option
              v-for="item in itemStateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理完毕时间"
                      prop="startTime">
          <el-date-picker v-model="dataForm.processedStartTime"
                          type="date"
                          :picker-options="pickerBeginDateBefore1"
                          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.processedEndTime"
                          type="date"
                          :picker-options="pickerBeginDateAfter1"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="满意度">
          <el-select v-model="dataForm.evaluationScore" placeholder="全部" clearable >
            <el-option
              v-for="item in evaluationScoreOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否流转网格化平台">
          <el-select v-model="dataForm.reportFlag" placeholder="全部" clearable >
            <el-option
              v-for="item in reportFlagOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('epdc:topic:export')" type="primary" @click="exportHandle()">{{ $t('export') }}</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="itemContent" label="项目内容" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createdTime" label="转项目时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="operatNum" label="处理次数" header-align="center" align="center" Y ></el-table-column>
        <el-table-column prop="reportFlag" label="是否流转网格化平台" header-align="center" align="center" :formatter="showReportFlagFormatter"></el-table-column>
        <el-table-column prop="deptNum" label="涉及部门数量" header-align="center" align="center" ></el-table-column>
        <el-table-column prop="itemState" label="项目状态" header-align="center" align="center" :formatter="showItemStateNameFormatter"></el-table-column>
        <el-table-column prop="processedTime" label="处理完毕时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="takeTime" label="处理时长(h)" header-align="center" align="center" ></el-table-column>
        <el-table-column prop="allDeptNames" label="项目来源网格" header-align="center" align="center"></el-table-column>
        <el-table-column prop="evaluationScore" label="居民满意度评价" header-align="center" align="center" :formatter="showEvaluationScoreNameFormatter"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150" v-if="false">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="look(scope.row.id)">{{ $t('look') }}</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>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/analysis/item/pageDifficultItem',
        getDataListIsPage: true
      },
      sortOptions: [{
        value: '0',
        label: '耗时最长'
      }, {
        value: '1',
        label: '涉及部门最多'
      },
      {
        value: '2',
        label: '处理次数最多'
      }],
      itemStateOptions: [{
        value: '0',
        label: '处理中'
      },
      {
        value: '5',
        label: '已关闭'
      }, {
        value: '10',
        label: '已结案'
      }],
      evaluationScoreOptions: [{
        value: '0',
        label: '不满意'
      },
      {
        value: '1',
        label: '基本满意'
      }, {
        value: '2',
        label: '非常满意'
      }],
      reportFlagOptions: [{
        value: '0',
        label: '否'
      },
      {
        value: '1',
        label: '是'
      }],
      closeVisible: false,
      dataForm: {
        id: '',
        streetId: '',
        communityId: '',
        gridId: '',
        orderType: '0',
        changeItemStartTime: '',
        changeItemEndTime: '',
        itemState: '',
        processedStartTime: '',
        processedEndTime: '',
        evaluationScore: '',
        reportFlag: ''
      },
      pickerBeginDateBefore: {
        disabledDate: (time) => {
          let beginDateVal = this.dataForm.changeItemStartTime
          if (beginDateVal) {
            return time.getTime() > new Date(beginDateVal).getTime()
          }
        }
      },
      pickerBeginDateAfter: {
        disabledDate: (time) => {
          let EndDateVal = this.dataForm.changeItemEndTime
          if (EndDateVal) {
            return time.getTime() < new Date(EndDateVal).getTime()
          }
        }
      },
      pickerBeginDateBefore1: {
        disabledDate: (time) => {
          let beginDateVal = this.dataForm.processedStartTime
          if (beginDateVal) {
            return time.getTime() > new Date(beginDateVal).getTime()
          }
        }
      },
      pickerBeginDateAfter1: {
        disabledDate: (time) => {
          let EndDateVal = this.dataForm.processedEndTime
          if (EndDateVal) {
            return time.getTime() < new Date(EndDateVal).getTime()
          }
        }
      },
      ids: [],
      options: []
    }
  },
  components: {
  },
  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: {
    showReportFlagFormatter: function (row, column) {
      if (row.reportFlag) {
        let dict = this.reportFlagOptions.filter(item => item.value === row.reportFlag)[0]
        if (dict) {
          return dict.label
        }
      }
      return ''
    },
    showItemStateNameFormatter: function (row, column) {
      if (row.itemState) {
        let dict = this.itemStateOptions.filter(item => item.value === row.itemState)[0]
        if (dict) {
          return dict.label
        }
      }
      return ''
    },
    showEvaluationScoreNameFormatter: function (row, column) {
      if (row.evaluationScore) {
        let dict = this.evaluationScoreOptions.filter(item => item.value === row.evaluationScore)[0]
        if (dict) {
          return dict.label
        }
      }
      return ''
    },
    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(() => {})
    },
    look (id) {
      // this.$parent.selectComponent = 'TopicDetail'
      // this.$router.push({ path: '/group-topic', query: { id: id } })
    }
  }
}
</script>
