<template>
  <div>
    <el-row class="handle-box" style="margin-bottom: 10px">
      <el-col :span="2">
        <div style="text-align: center"><span>楼盘</span></div>
      </el-col>
      <el-col :span="4">
        <el-select
          v-model="search.groupId"
          style="width: 100%"
          clearable
          filterable
          @change="groupChange"
        >
          <el-option
            v-for="item in groupOption"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-col>
      <el-col :span="2">
        <div style="text-align: center"><span>分期</span></div>
      </el-col>
      <el-col :span="4">
        <el-select
          v-model="search.discId"
          style="width: 100%"
          clearable
          filterable
          @change="discChange"
        >
          <el-option
            v-for="item in discOption"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-col>
      <el-col :span="2">
        <div style="text-align: center"><span>关键字</span></div>
      </el-col>
      <el-col :span="4">
        <el-input v-model="search.roomNo" />
      </el-col>
    </el-row>
    <el-row class="handle-box" style="margin-bottom: 10px">
      <el-col :span="24" style="margin-top: 20px">
        <el-button class="ch-button-warning" size="small" style="float: right" @click="handleReset()"><i class="el-icon-search" />&nbsp;重置</el-button>
        <el-button class="ch-button" size="small" style="float: right" @click="handleSearch()"><i class="el-icon-search" />&nbsp;查询</el-button>
      </el-col>
    </el-row>
    <el-row class="handle-box">
      <el-col :span="24">
        <el-table
          v-loading="loading"
          :data="AllData"
          row-class-name="g_table_row"
          border
          :header-cell-style="{background:'#f2f2f2'}"
        >
          <el-table-column label="序号" type="index" width="60" />
          <el-table-column label="楼盘" prop="groupName" />
          <el-table-column label="分期" prop="discName" />
          <el-table-column label="楼栋数" prop="buildCount" />
          <el-table-column label="房屋总数" prop="roomCount" />
          <el-table-column label="待签约" prop="waitSigningCount" />
          <el-table-column label="已签约" prop="signingCount" />
          <el-table-column label="已结清数" prop="settledCount" />
          <el-table-column label="已入户数" prop="enteredCount" />
          <el-table-column header-align="center" label="操作">
            <template scope="scope">
              <el-button size="mini" type="text" @click="handleView(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="table-page">
          <el-pagination
            :current-page.sync="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="allpage"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </el-col>
    </el-row>

    <!-- 详情页面 -->
    <el-dialog
      :title="'项目详情'"
      :visible.sync="dialogVisible"
      width="75%"
      top="50px"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      append-to-body
    >
      <project-detail
        v-if="dialogVisible"
        ref="projectDetail"
      />
    </el-dialog>

  </div>
</template>
<script>
import Base from '@/views/base/base'
import BaseData from '@/views/base/baseData'
import projectDetail from '@/views/reportForms/components/projectDetail.vue'

export default {
    name: 'ProjectArchivesVue',
    components: { projectDetail },
    mixins: [Base, BaseData],
    data() {
        return {
            dc_key: ['INTENTIONAL_DEPOSIT_STATUS'],
            // 列表相关
            search: {
            },
            AllData: [],
            loading: false,
            options: [],
            dialogVisible: false,
            groupOption: [],
            discOption: [],
            buildOption: []
        }
    },
    mounted() {
        this.getGroupOption()
        // this.getDiscOption()
        this.initDict(this.dc_key).then((res) => {
            this.getData()
        })
    },
    methods: {
        groupChange() {
            this.discOption = []
            this.search.discId = ''
            this.search.roomNo = ''
            this.handleSearch()
            const data = {
                groupId: this.search.groupId
            }
            this.getDiscOption(data)
        },
        discChange() {
            this.search.roomNo = ''
            this.handleSearch()
        },
        getGroupOption() {
            this.baseGroupRequest('listAll', {}).then((res) => {
                const data = res.data
                this.groupOption = []
                data.forEach(item => {
                    const obj = {
                        value: item.groupId,
                        label: item.groupName,
                        key: item.groupId
                    }
                    this.groupOption.push(obj)
                })
            })
        },
        getDiscOption(data) {
            this.baseDiscRequest('listAll', data).then((res) => {
                const data = res.data
                this.discOption = []
                data.forEach(item => {
                    const obj = {
                        value: item.id,
                        label: item.name,
                        key: item.id
                    }
                    this.discOption.push(obj)
                })
            })
        },
        getData: function() {
            const _this = this
            _this.loading = true
            _this.AllData = []

            this.search.pageNum = this.currentPage
            this.search.pageSize = this.pageSize
            this.baseRequest('reportList', this.search).then((res) => {
                if (res.data.rows) {
                    res.data.rows.forEach(function(item) {
                        const json = _this.getItemJson(item)
                        _this.AllData.push(json)
                    })
                    _this.allpage = res.data.total
                }
                _this.loading = false
            }).catch((e) => {
                // console.log(e)
            })
            // this.initOutData()
        },
        handleSearch: function() {
            this.getData()
        },
        handleReset: function() {
            for (const i in this.search) {
                if (i !== 'pageNum' && i !== 'pageSize') {
                    this.search[i] = ''
                }
            }
            this.handleSearch()
        },
        getItemJson: function(item) {
            return item
        },
        handleView(val) {
            this.dialogVisible = true
            this.dialogTitle = '查看'
            // 新vue时调用的方法
            this.$nextTick(() => {
                this.$refs.projectDetail.initData(val)
            })
        },
        cancel: function() {
            this.dialogVisible = false
        },
        baseRequest(opUrl, postData) {
            return this.$channel.globeRequest('CustomerManagementController', opUrl, postData, '')
        },
        baseGroupRequest(opUrl, postData) {
            return this.$channel.globeRequest('ParkInfoController', opUrl, postData, 'project')
        },
        baseDiscRequest(opUrl, postData) {
            return this.$channel.globeRequest('ParkFloorDiscController', opUrl, postData, 'project')
        }
    }
}
</script>

<style scoped>
  .ch-input .el-input__inner {
      border-color: #32323A;
  }
  .ch-input-size {
      width: 150px;
  }
  .ch-button {
      border-color: #32323A;
      background-color: #32323A;
      color: #fff;
  }
  .ch-button-warning {
      margin-left: 10px;
      border-color: #E6A23C;
      background-color: #E6A23C;
      color: #fff;
  }
  .ch-button-export {
      margin-left: 10px;
      border-color: #98CC1F;
      background-color: #98CC1F;
      color: #fff;
  }
  /deep/.el-dialog__header {
      padding: 10px 20px;
  }
  /deep/.el-dialog__body {
      padding: 10px 20px;
  }
</style>
