<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-item__item}">
      <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="itemContent">
          <el-input
            v-model="dataForm.itemContent"
            placeholder="请输入项目内容"
            clearable
          ></el-input>
        </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="grid"
          label="所属网格"
          header-align="center"
          min-width="400"
          align="left"
        ></el-table-column>
        <el-table-column
          prop="itemState"
          label="项目状态"
          header-align="center"
          min-width="400"
          align="left"
          :formatter="showItemStateNameFormatter"
        ></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="itemContent"
          label="项目内容"
          header-align="center"
          min-width="400"
          align="left"
        ></el-table-column>
        <el-table-column
          prop="nickName"
          label="提交人"
          header-align="center"
          width="150"
          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
              type="text"
              size="small"
              @click="editAction(scope.row.id)"
              >编辑处理进展</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>
      <edit-process-progress
        v-if="editVisible"
        ref="editProcessProgress"
        @refreshDataList="getDataList"
      ></edit-process-progress>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import editProcessProgress from './edit-process-progress'
export default {
  mixins: [mixinViewModule],
  name: 'ItemCloseList',
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/events/item/page',
        getDataListIsPage: true
      },
      dataForm: {
        id: '',
        itemState: '',
        startTime: '',
        endTime: '',
        streetId: '',
        communityId: '',
        gridId: '',
        itemCode: '',
        itemContent: ''
      },
      ids: [],
      options: [],
      editVisible: false,
      itemStateOptions: [{
        value: '0',
        label: '处理中'
      },
      {
        value: '5',
        label: '已关闭'
      }, {
        value: '10',
        label: '已结案'
      }]
    }
  },
  components: {
    editProcessProgress
  },
  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: {
    showItemStateNameFormatter: function (row, column) {
      if (row.itemState) {
        let dict = this.itemStateOptions.filter(item => item.value === row.itemState)[0]
        if (dict) {
          return dict.label
        }
      }
      return ''
    },
    editAction (id) {
      this.editVisible = true
      this.$nextTick(() => {
        this.$refs.editProcessProgress.dataForm.id = id
        this.$refs.editProcessProgress.init()
      })
    },
    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>
