<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-select v-model="dataForm.province" clearable @change="proChange" placeholder="请选择省份">
          <el-option
            v-for="item in provinces"
            :key="item.cityCode"
            :label="item.cityNameZh"
            :value="item.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.city" clearable @change="cityChange" placeholder="请选择城市">
          <el-option
            v-for="item in citys"
            :key="item.cityCode"
            :label="item.cityNameZh"
            :value="item.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.county" clearable placeholder="请选择区域">
          <el-option
            v-for="item in countys"
            :key="item.cityCode"
            :label="item.cityNameZh"
            :value="item.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.name" clearable placeholder="酒店名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="query()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" v-loading="dataListLoading" style="width: 100%;">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="hotelinfo-table-expand">
            <el-form-item label="酒店编码">
              <span>{{ props.row.hotelCode }}</span>
            </el-form-item>
            <el-form-item label="酒店地址">
              <span>{{ props.row.address }}</span>
            </el-form-item>
            <el-form-item label="联系电话">
              <span>{{ props.row.phone }}</span>
            </el-form-item>
            <el-form-item label="描述信息">
              <span>{{ props.row.hotelInfo }}</span>
            </el-form-item>
            <el-form-item label="经度">
              <span>{{ props.row.axesX }}</span>
            </el-form-item>
            <el-form-item label="纬度">
              <span>{{ props.row.axesY }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="hotelName" header-align="left" align="left" label="酒店名称" ></el-table-column>
      <el-table-column prop="cityNameZh" header-align="left" align="left" label="所在地区" ></el-table-column>
      <el-table-column prop="status" header-align="left" align="left" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="success">营业中</el-tag>
          <el-tag v-else size="small" type="warning">非营业中</el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center"  label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            v-if="isAuth('ht:hthotelinfo:update')"
            @click="addOrUpdateHandle(scope.row.id)"
          >下单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './order-ctrip-dealwith'
import { treeDataTranslate } from '@/utils'
export default {
  data() {
    return {
      dataForm: {
        province: null,
        city: null,
        county: null,
        brand: null,
        hotelName: ''
      },
      tier: 1,
      parentId: -1,
      provinces: [],
      citys: [],
      countys: [],
      brands: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  activated() {
    if(this.$route.params.hotelName != null && this.$route.params.hotelName != undefined){
      this.dataForm.name = this.$route.params.hotelName
    }
    this.getQuryCitys()
    this.getBrands()
  },
  methods: {
    // 获取区域查询条件
    getQuryCitys() {
      this.$http({
        url: this.$http.adornUrl('/ht/hthotelinfo/citys'),
        method: 'post',
        params: this.$http.adornParams({
          tier: this.tier,
          parentId: this.parentId
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          switch (this.tier) {
            case 1:
              this.provinces = data.list
              break
            case 2:
              this.citys = data.list
              break
            case 3:
              this.countys = data.list
              break
          }
        }
      })
    },
    // 选择省份
    proChange(value) {
      this.parentId = value
      this.tier = 2
      this.getQuryCitys()
    },
    // 选择城市
    cityChange(value) {
      this.parentId = value
      this.tier = 3
      this.getQuryCitys()
    },
    query() {
      this.pageIndex = 1
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/ht/hthotelinfo/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'city': this.dataForm.city,
          'county': this.dataForm.county,
          'brand': this.dataForm.brand,
          'name': this.dataForm.name
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 下单
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    }
  }
}
</script>
<style>
.hotelinfo-table-expand {
  font-size: 0;
}
.hotelinfo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.hotelinfo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
