<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-news__itemfusingdelay}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataListSearch()">
        <el-form-item label="所属机构" label-width="100px">
          <el-cascader
                  v-model="ids"
                  :options="options"
                  :props="{ checkStrictly: true }"
                  clearable
                  style="width:250px;"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="项目编号" prop="itemCode" label-width="100px">
          <el-input
                  v-model="dataForm.itemCode"
                  placeholder="请输入项目编号"
                  clearable
                  @keyup.native="btKeyUpItemCode"
                  style="width:250px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="项目内容" prop="itemCode">
          <el-input
                  v-model="dataForm.itemContent"
                  placeholder="请输入项目内容"
                  clearable
                  @keyup.native="btKeyUpItemContent"
                  style="width:200px;"
          ></el-input>
        </el-form-item>
        <br>
        <el-form-item label="提交人" prop="itemCode" label-width="100px">
          <el-input
                  v-model="dataForm.nickName"
                  placeholder="请输入提交人"
                  clearable
                  @keyup.native="btKeyUpNickName"
                  style="width:250px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="提交人手机号" prop="itemCode">
          <el-input
                  v-model="dataForm.mobile"
                  placeholder="请输入提交人手机号"
                  clearable
                  @keyup.native="btKeyUpMobile"
                  style="width:250px;"
          ></el-input>
        </el-form-item>
        <br>
        <div>
          <el-form-item label="转成项目时间" prop="startTime" label-width="100px">
            <el-date-picker
                    v-model="dataForm.startTime"
                    type="date"
                    :picker-options="pickerBeginDateBefore"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    placeholder="选择日期时间"
                    style="width:250px;" @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:250px;" @change="changeTime"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="success" @click="getDataListSearch()" class="custom-button-default">{{ $t('query') }}</el-button>
          </el-form-item>
        </div>

      </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"
                min-width="400"
                align="left"
                show-overflow-tooltip
        ></el-table-column>
        <el-table-column
                prop="itemCode"
                label="项目编号"
                header-align="center"
                width="150"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="stateName"
                label="申请项"
                header-align="center"
                width="150"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="handleStateName"
                label="审核状态"
                header-align="center"
                width="150"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="handleReason"
                label="审核理由"
                header-align="center"
                width="150"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="createdTime"
                label="转成项目时间"
                header-align="center"
                width="180"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="nickName"
                label="提交人"
                header-align="center"
                min-width="200"
                align="center"
                show-overflow-tooltip
        ></el-table-column>
        <el-table-column
                prop="mobile"
                label="提交人手机号"
                header-align="center"
                min-width="200"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="participantsNum"
                label="参与人数"
                header-align="center"
                width="100"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="approveNum"
                label="支持人数"
                header-align="center"
                width="100"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="opposeNum"
                label="不支持人数"
                header-align="center"
                width="100"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="commentNum"
                label="评论人数"
                header-align="center"
                width="100"
                align="center"
        ></el-table-column>
        <el-table-column
                prop="browseNum"
                label="浏览数"
                header-align="center"
                width="100"
                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:item:deal')"
                    type="text"
                    size="small"
                    class="custom-table-button-default"
                    @click="dealAction(scope.row.id)"
            >{{ '查看' }}
            </el-button
            >
            <el-button type="text" size="small" @click="openHandle(scope.row.delayId)" class="custom-table-button-default">{{ '审核' }}</el-button>
          </template>
        </el-table-column>
<!--        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
<!--        <el-table-column prop="id" label="主键" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="itemId" label="项目ID" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="state" label="申请状态：0-延期，5-熔断" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="reason" label="申请理由" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="handleState" label="审核状态：10-审核通过，15-驳回" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="handleReason" label="审批理由" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="delayStartTime" label="延期开始时间" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="delayEndTime" label="延期结束时间" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="revision" label="乐观锁" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="createdBy" 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="updatedBy" label="更新人" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="updatedTime" label="更新时间" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="delFlag" 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('news:itemfusingdelay:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>-->
<!--            <el-button v-if="$hasPermission('news:itemfusingdelay:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</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>
      <!-- 审核弹窗 -->
      <itemfusingdelay-audit v-if="handleVisible" ref="itemfusingdelayAudit" @refreshDataList="getDataList"></itemfusingdelay-audit>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import Detail from './itemfusingdelay-detail-view'
import ItemfusingdelayAudit from './itemfusingdelay-audit'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/events/itemfusingdelay/page',
        getDataListIsPage: true,
        exportURL: '/events/item/unexport'
      },
      detailVisible: false,
      dataForm: {
        id: '',
        itemState: '0',
        startTime: '',
        endTime: '',
        streetId: '',
        communityId: '',
        gridId: '',
        itemCode: '',
        itemContent: '',
        nickName: '',
        mobile: '',
        stateName:'',
        handleStateName:'',
        handleReason:''
      },
      handleVisible:false,
      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: {
    Detail,
    ItemfusingdelayAudit
  },
  created: function () {
    this.getOptions()
    this.getDataList()
  },
  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: {
    dealAction(id) {
      this.$parent.selectComponent = 'ItemfusingdelayDetailView'
      this.$router.push({path: '/events-itemfusingdelay', 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(() => {
              })
    },
    btKeyUpItemCode (e) {
      e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
      this.dataForm.itemCode = e.target.value
    },
    btKeyUpItemContent (e) {
      e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
      this.dataForm.itemContent = e.target.value
    },
    btKeyUpNickName (e) {
      e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
      this.dataForm.nickName = e.target.value
    },
    btKeyUpMobile (e) {
      e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
      this.dataForm.mobile = e.target.value
    },
    openHandle (id) {
      this.handleVisible = true
      this.$nextTick(() => {
        this.$refs.itemfusingdelayAudit.dataForm.id = id
        this.$refs.itemfusingdelayAudit.init()
      })
    }
  }
}
</script>
