<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-rent__rentDeath}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="姓名"
                      prop="name">
          <el-input v-model="dataForm.name"
                    size="small"
                    class="list_item_width_1"
                    clearable
                    placeholder="请输入姓名">
          </el-input>
        </el-form-item>
        <el-form-item label="身份证"
                      prop="idCard">
          <el-input v-model="dataForm.idCard"
                    size="small"
                    class="list_item_width_1"
                    clearable
                    placeholder="请输入身份证">
          </el-input>
        </el-form-item>
        <el-form-item label="手机"
                      prop="mobile">
          <el-input v-model="dataForm.mobile"
                    size="small"
                    class="list_item_width_1"
                    clearable
                    placeholder="请输入手机">
          </el-input>
        </el-form-item>
        <el-form-item label="迁入死亡名单时间"
                      prop="startTime">
          <el-date-picker v-model="timeRange"
                          type="daterange"
                          clearable
                          size="small"
                          range-separator="至"
                          start-placeholder="选择日期"
                          end-placeholder="选择日期"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <!--<el-form-item>-->
          <!--<el-button type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>-->
        <!--</el-form-item>-->
        <!--<el-form-item>-->
          <!--<el-button type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>-->
        <!--</el-form-item>-->
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
        <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="userId" label="epmet用户主键" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="name" label="姓名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="idCard" label="身份证" header-align="center" align="center"></el-table-column>
        <el-table-column prop="mobile" label="手机号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="gender" label="性别" header-align="center" align="center"></el-table-column>
        <el-table-column prop="type" label="类型" header-align="center" align="center"></el-table-column>
        <el-table-column prop="joinDate" label="加入时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="joinReason" label="加入原因" header-align="center" align="center"></el-table-column>
        <!--<el-table-column prop="removeDate" label="移除时间" header-align="center" align="center"></el-table-column>-->
        <!--<el-table-column prop="removeReason" 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="customerId" label="客户ID" 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 @click="handleLook(scope.row)" type="text" size="small" class="btn-color-look">查看</el-button>
            <!--<el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>-->
            <!--<el-button 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>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <people-more v-if="showedPeopleMoreInfo && lookInfo.userId"
                   :userId="lookInfo.userId"
                   :gridName="lookInfo.gridName"
                   @close="handleCancleLook" />
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './rentdeath-add-or-update'
import peopleMore from "@/views/modules/shequ/cpts/people-more";
import { requestPost } from "@/js/dai/request";
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/pli/power/rentDeath/page',
        getDataListIsPage: true,
        deleteURL: '/pli/power/rentDeath',
        deleteIsBatch: true
      },
        timeRange: '',
      dataForm: {
        id: ''
      },
        // 显示人员详情
        showedPeopleMoreInfo: false,
        lookInfo: {
            userId: '',
            gridName: ''
        }
    }
  },
    watch: {
        timeRange (val) {
            if (Array.isArray(val) && val.length == 2) {
                this.dataForm.startTime = val[0];
                this.dataForm.endTime = val[1];
            } else {
                this.dataForm.startTime = "";
                this.dataForm.endTime = "";
            }
        }
    },
  components: {
    AddOrUpdate,
      peopleMore
  },
    methods: {
        async handleLook (row) {
            if(row.gridId !== ''){
                const url = '/gov/org/grid/griddetail'
                let params = {
                    gridId : row.gridId,
                }
                const { data, code, msg } = await requestPost(url, params)
                if(code === 0){
                    this.lookInfo.gridName = data.gridName
                } else {
                    this.$message.error(msg)
                }
            }else{
                this.lookInfo.gridName = ''
            }
            this.lookInfo.userId = row.userId
            this.showedPeopleMoreInfo = true
        },
        handleCancleLook() {
            this.lookInfo.userId = ''
            this.lookInfo.gridName = ''
            this.showedPeopleMoreInfo = false
        }
  }
}
</script>
