<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-change__changeRelocation} resi-container">
      <el-card ref="searchCard" class="search-card">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" label-width="70px">
        <el-form-item label="所属网格"
                      prop="gridId">
          <el-select
                  v-model.trim="dataForm.gridId"
                  placeholder="请选择"
                  clearable
                  @change="handleChangeGrid"
          >
            <el-option
                    v-for="item in optionsG"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="迁往何地" >
          <div class="resi-cell-value">
            <div class="resi-cell-col">
              <el-form-item prop="villageId">
                <el-select
                        v-model.trim="dataForm.villageId"
                        placeholder="请选择小区"
                        clearable
                        @clear="handleClearVillage"
                        @change="handleChangeV"
                >
                  <el-option
                          v-for="item in optionsV"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="buildId">
                <el-select
                        v-model.trim="dataForm.buildId"
                        placeholder="楼号"
                        clearable
                        style="width: 120px;"
                        :disabled="changeVDisabled"
                        @clear="handleClearBuild"
                        @change="handleChangeB"
                >
                  <el-option
                          v-for="item in optionsB"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="unitId">
                <el-select
                        v-model.trim="dataForm.unitId"
                        :disabled="changeBDisabled"
                        placeholder="单元"
                        clearable
                        style="width: 120px;"
                        @click="handleClearDan"
                        @change="handleChangeD"
                >
                  <el-option
                          v-for="item in optionsD"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="homeId">
                <el-select
                        v-model.trim="dataForm.homeId"
                        :disabled="changeDDisabled"
                        placeholder="房号"
                        clearable
                        style="width: 120px;"
                >
                  <el-option
                          v-for="item in optionsH"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </div>
        </el-form-item>

        <br/>
        <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>
        <br/>
        <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 type="primary" size="small" @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button class="diy-button--reset" size="small" @click="resetForm">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="warning" size="small" @click="exportHandle()">{{ $t('export') }}</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-card>
      <el-card class="resi-card-table">
      <el-table class="resi-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 label="序号"
                         type="index"
                         fixed="left"
                         align="center"
                         width="50">
        </el-table-column>
        <el-table-column prop="name" label="姓名" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="agencyName" label="所属网格" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="oldAddress" label="所属房屋" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mobile" label="手机号" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="idCard" label="身份证号" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="gender" label="性别" header-align="center" align="center" min-width="70" show-overflow-tooltip></el-table-column>
        <el-table-column prop="age" label="年龄" header-align="center" align="center" min-width="90" show-overflow-tooltip></el-table-column>
        <el-table-column prop="outOfTime" label="迁出时间" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="reason" label="迁出原因" header-align="center" align="center" min-width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="address" label="迁往何地" header-align="center" align="center" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="ownerName" label="户主姓名" header-align="center" align="center" min-width="100" show-overflow-tooltip></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>
      </el-card>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './changerelocation-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/pli/power/changeRelocation/page',
        getDataListIsPage: true,
        deleteURL: '/pli/power/changeRelocation',
        deleteIsBatch: true,
        exportURL: '/pli/power/changeRelocation/export'
      },
        timeRange: '',
        optionsV: [],
        optionsB: [],
        optionsH: [],
        optionsD: [],
        optionsG: [],
      dataForm: {
        id: '',
          name: '',
          mobile: '',
          idCard: '',
          gridId: '',
          villageId: '',
          buildId: '',
          unitId: '',
          homeId: '',
      }
    }
  },
  components: {
    AddOrUpdate
  },
    computed: {
        changeVDisabled() {
            return !this.dataForm.villageId
        },
        changeBDisabled() {
            return !this.dataForm.buildId
        },
        changeDDisabled() {
            return !this.dataForm.unitId
        }
    },
    created () {
        this.getGridList()
        this.getValiheList()
    },
    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 = '';
            }
        }
    },
    methods: {
        resetForm(formName) {
            for(const n in this.dataForm) {
                this.dataForm[n] = ''
            }
            this.timeRange = ''
            this.getDataList()
        },
        handleClearVillage() {
            this.dataForm.buildId = ''
            this.dataForm.homeId = ''
        },
        handleClearBuild() {
            this.dataForm.buildId = ''
            this.dataForm.unitId = ''
            this.dataForm.homeId = ''
        },
        handleClearDan() {
            this.dataForm.unitId = ''
            this.dataForm.homeId = ''
        },
        handleChangeGrid(val) {
            console.log('val', val)
            this.dataForm.villageId = ''
            this.dataForm.buildId = ''
            this.dataForm.unitId = ''
            this.dataForm.homeId = ''
            this.getValiheList()
        },
        getGridList() {
            const { user } = this.$store.state
            this.$http
                .post('/gov/org/customergrid/gridoption', { agencyId: user.agencyId, purpose: 'query' })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    } else {
                        console.log('获取查询详情成功', res.data)
                        this.optionsG = res.data
                    }
                })
                .catch(() => {
                    return this.$message.error('网络错误')
                })
        },
        getValiheList() {
            const { user } = this.$store.state
            this.$http
                .post('/gov/org/icneighborhood/neighborhoodoption', {
                    gridId: this.dataForm.gridId,
                    agencyId: ''
                    // agencyId: user.agencyId
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    } else {
                        console.log('获取查询详情成功', res.data)
                        this.optionsV = res.data
                    }
                })
                .catch(() => {
                    return this.$message.error('网络错误')
                })
        },
        getBuildList() {
            this.$http
                .post('/gov/org/icbuilding/buildingoption', {
                    neighborHoodId: this.dataForm.villageId
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    } else {
                        console.log('获取查询详情成功', res.data)
                        this.optionsB = res.data
                    }
                })
                .catch(() => {
                    return this.$message.error('网络错误')
                })
        },
        getUniList() {
            this.$http
                .post('/gov/org/icbuildingunit/unitoption', {
                    buildingId: this.dataForm.buildId
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    } else {
                        console.log('获取查询详情成功', res.data)
                        this.optionsD = res.data
                    }
                })
                .catch(() => {
                    return this.$message.error('网络错误')
                })
        },
        getHouseList() {
            this.$http
                .post('/gov/org/ichouse/houseoption', { unitId: this.dataForm.unitId })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg)
                    } else {
                        console.log('获取查询详情成功', res.data)
                        this.optionsH = res.data
                    }
                })
                .catch(() => {
                    return this.$message.error('网络错误')
                })
        },
        handleChangeV(val) {
            console.log('val', val)
            this.dataForm.buildId = ''
            this.dataForm.unitId = ''
            this.dataForm.homeId = ''
            this.getBuildList()
        },
        handleChangeB(val) {
            console.log('val', val)
            this.dataForm.unitId = ''
            this.dataForm.homeId = ''
            this.getUniList()
        },
        handleChangeD(val) {
            console.log('val', val)
            this.dataForm.homeId = ''
            this.getHouseList()
        },
    }
}
</script>
<style lang="scss" scoped>
  @import "@/assets/scss/buttonstyle.scss";

  .resi-container .resi-card-table {
    ::v-deep .el-table th {
      color: #fff;
      background-color: rgba(33, 149, 254, 1);
      // border-right: 1px solid rgba(33, 149, 254, 1);
    }
  }
  .resi-table {
    ::v-deep .el-button--text {
      text-decoration: underline;
    }
    ::v-deep .btn-color-del {
      margin-left: 10px;
      color: rgba(213, 16, 16, 1);
    }
    ::v-deep .btn-color-edit {
      color: rgba(0, 167, 169, 1);
    }
  }
  .form-wr {
    .input-width {
      width: 260px;

    }
    .input-width-textarea {
      width: 500px;
    }
    .imsg-list {
      display: flex;
      align-items: center;
      .imgs-item {
        position: relative;
        margin-right: 10px;
        .el-icon-delete {
          position: absolute;
          top: 0;
          right: 0;
          font-size: 18px;
          color: red;
          z-index: 3;
          cursor: pointer;
        }
      }
    }
  }
  .div-content {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
</style>
