<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="酒店编码" prop="hotelCode">
      <el-input v-model="dataForm.hotelCode" placeholder="酒店编码"></el-input>
    </el-form-item>
    <el-form-item label="酒店名称" prop="hotelName">
      <el-input v-model="dataForm.hotelName" placeholder="酒店名称"></el-input>
    </el-form-item>
    <el-form-item label="卖家酒店英文名称" prop="hotelNameEn">
      <el-input v-model="dataForm.hotelNameEn" placeholder="卖家酒店英文名称"></el-input>
    </el-form-item>
    <el-form-item label="酒店地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="酒店地址"></el-input>
    </el-form-item>
    <el-form-item label="" prop="country">
      <el-input v-model="dataForm.country" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="所属城市" prop="province">
      <el-input v-model="dataForm.province" placeholder="所属城市"></el-input>
    </el-form-item>
    <el-form-item label="" prop="district">
      <el-input v-model="dataForm.district" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="酒店所在城市" prop="city">
      <el-input v-model="dataForm.city" placeholder="酒店所在城市"></el-input>
    </el-form-item>
    <el-form-item label="酒店所在城市区县" prop="county">
      <el-input v-model="dataForm.county" placeholder="酒店所在城市区县"></el-input>
    </el-form-item>
    <el-form-item label="酒店所在商圈名" prop="area">
      <el-input v-model="dataForm.area" placeholder="酒店所在商圈名"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="酒店描述信息" prop="hotelInfo">
      <el-input v-model="dataForm.hotelInfo" placeholder="酒店描述信息"></el-input>
    </el-form-item>
    <el-form-item label="坐标类型G – Google、B – 百度、A – 高德、M – 灵图" prop="axes">
      <el-input v-model="dataForm.axes" placeholder="坐标类型G – Google、B – 百度、A – 高德、M – 灵图"></el-input>
    </el-form-item>
    <el-form-item label="经度" prop="axesX">
      <el-input v-model="dataForm.axesX" placeholder="经度"></el-input>
    </el-form-item>
    <el-form-item label="纬度" prop="axesY">
      <el-input v-model="dataForm.axesY" placeholder="纬度"></el-input>
    </el-form-item>
    <el-form-item label="星级" prop="starLevel">
      <el-input v-model="dataForm.starLevel" placeholder="星级"></el-input>
    </el-form-item>
    <el-form-item label="酒店类型
            商旅酒店、休闲度假（情侣、亲子）" prop="hotelType">
      <el-input v-model="dataForm.hotelType" placeholder="酒店类型
            商旅酒店、休闲度假（情侣、亲子）"></el-input>
    </el-form-item>
    <el-form-item label="酒店设施
            会议室、咖啡厅、健身房、餐厅、西式餐厅、自动取款机、酒吧、收费停车场、桑拿、室内游泳池、中式餐厅、残疾人设施、室外游泳池、ATM取款机、商务中心" prop="hotelFacilities">
      <el-input v-model="dataForm.hotelFacilities" placeholder="酒店设施
            会议室、咖啡厅、健身房、餐厅、西式餐厅、自动取款机、酒吧、收费停车场、桑拿、室内游泳池、中式餐厅、残疾人设施、室外游泳池、ATM取款机、商务中心"></el-input>
    </el-form-item>
    <el-form-item label="酒店服务
            运通、万事达、洗衣服务、接站服务、行李寄存、携带宠物、威士、JCB卡、早餐服务、大来、接受银行卡、接机服务、叫醒服务" prop="service">
      <el-input v-model="dataForm.service" placeholder="酒店服务
            运通、万事达、洗衣服务、接站服务、行李寄存、携带宠物、威士、JCB卡、早餐服务、大来、接受银行卡、接机服务、叫醒服务"></el-input>
    </el-form-item>
    <el-form-item label="起价
            单位：分" prop="sp">
      <el-input v-model="dataForm.sp" placeholder="起价
            单位：分"></el-input>
    </el-form-item>
    <el-form-item label="开业时间
            酒店填写的营业时间，无固定格式，如取值可以为“24小时”。" prop="openTime">
      <el-input v-model="dataForm.openTime" placeholder="开业时间
            酒店填写的营业时间，无固定格式，如取值可以为“24小时”。"></el-input>
    </el-form-item>
    <el-form-item label="装修时间" prop="decorateTime">
      <el-input v-model="dataForm.decorateTime" placeholder="装修时间"></el-input>
    </el-form-item>
    <el-form-item label="楼层信息" prop="floor">
      <el-input v-model="dataForm.floor" placeholder="楼层信息"></el-input>
    </el-form-item>
    <el-form-item label="是否国内酒店" prop="chinaHotel">
      <el-input v-model="dataForm.chinaHotel" placeholder="是否国内酒店"></el-input>
    </el-form-item>
    <el-form-item label="酒店营业状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="酒店营业状态"></el-input>
    </el-form-item>
    <el-form-item label="首图信息" prop="pictureurl">
      <el-input v-model="dataForm.pictureurl" placeholder="首图信息"></el-input>
    </el-form-item>
    <el-form-item label="品牌 " prop="brand">
      <el-input v-model="dataForm.brand" placeholder="品牌 "></el-input>
    </el-form-item>
    <el-form-item label="数据来源
            1:携程
            2：美团
            3：美团商旅     4：携程美团商旅   5：携程商旅美团   6：携程商旅美团商旅" prop="dataFrom">
      <el-input v-model="dataForm.dataFrom" placeholder="数据来源
            1:携程
            2：美团
            3：美团商旅     4：携程美团商旅   5：携程商旅美团   6：携程商旅美团商旅"></el-input>
    </el-form-item>
    <el-form-item label="是否人工已校准" prop="manualVerify">
      <el-input v-model="dataForm.manualVerify" placeholder="是否人工已校准"></el-input>
    </el-form-item>
    <el-form-item label="是否自动下单" prop="automaticOrder">
      <el-input v-model="dataForm.automaticOrder" placeholder="是否自动下单"></el-input>
    </el-form-item>
    <el-form-item label="是否已经匹配" prop="isMatch">
      <el-input v-model="dataForm.isMatch" placeholder="是否已经匹配"></el-input>
    </el-form-item>
    <el-form-item label="" prop="htgroup">
      <el-input v-model="dataForm.htgroup" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="isDel">
      <el-input v-model="dataForm.isDel" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="aliCode">
      <el-input v-model="dataForm.aliCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="brandName">
      <el-input v-model="dataForm.brandName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="shid">
      <el-input v-model="dataForm.shid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="连锁品牌，家庭旅馆" prop="atype">
      <el-input v-model="dataForm.atype" placeholder="连锁品牌，家庭旅馆"></el-input>
    </el-form-item>
    <el-form-item label="" prop="poiType">
      <el-input v-model="dataForm.poiType" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="阿里酒店名称" prop="hotelNameAli">
      <el-input v-model="dataForm.hotelNameAli" placeholder="阿里酒店名称"></el-input>
    </el-form-item>
    <el-form-item label="酒店编码组合 不同数据来源酒店编码以逗号分隔 例如（123,456,789）" prop="compositeHotelCode">
      <el-input v-model="dataForm.compositeHotelCode" placeholder="酒店编码组合 不同数据来源酒店编码以逗号分隔 例如（123,456,789）"></el-input>
    </el-form-item>
    <el-form-item label="美团账号" prop="partnerId">
      <el-input v-model="dataForm.partnerId" placeholder="美团账号"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          hotelCode: '',
          hotelName: '',
          hotelNameEn: '',
          address: '',
          country: '',
          province: '',
          district: '',
          city: '',
          county: '',
          area: '',
          phone: '',
          hotelInfo: '',
          axes: '',
          axesX: '',
          axesY: '',
          starLevel: '',
          hotelType: '',
          hotelFacilities: '',
          service: '',
          sp: '',
          openTime: '',
          decorateTime: '',
          floor: '',
          chinaHotel: '',
          status: '',
          pictureurl: '',
          brand: '',
          dataFrom: '',
          manualVerify: '',
          automaticOrder: '',
          isMatch: '',
          htgroup: '',
          isDel: '',
          aliCode: '',
          brandName: '',
          shid: '',
          atype: '',
          poiType: '',
          hotelNameAli: '',
          compositeHotelCode: '',
          partnerId: ''
        },
        dataRule: {
          hotelCode: [
            { required: true, message: '酒店编码不能为空', trigger: 'blur' }
          ],
          hotelName: [
            { required: true, message: '酒店名称不能为空', trigger: 'blur' }
          ],
          hotelNameEn: [
            { required: true, message: '卖家酒店英文名称不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '酒店地址不能为空', trigger: 'blur' }
          ],
          country: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '所属城市不能为空', trigger: 'blur' }
          ],
          district: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '酒店所在城市不能为空', trigger: 'blur' }
          ],
          county: [
            { required: true, message: '酒店所在城市区县不能为空', trigger: 'blur' }
          ],
          area: [
            { required: true, message: '酒店所在商圈名不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          hotelInfo: [
            { required: true, message: '酒店描述信息不能为空', trigger: 'blur' }
          ],
          axes: [
            { required: true, message: '坐标类型', trigger: 'blur' }
          ],
          axesX: [
            { required: true, message: '经度不能为空', trigger: 'blur' }
          ],
          axesY: [
            { required: true, message: '纬度不能为空', trigger: 'blur' }
          ],
          starLevel: [
            { required: true, message: '星级不能为空', trigger: 'blur' }
          ],
          hotelType: [
            { required: true, message: '酒店类型', trigger: 'blur' }
          ],
          hotelFacilities: [
            { required: true, message: '酒店设施会议室、咖啡厅、健身房、餐厅、西式餐厅、自动取款机、酒吧、收费停车场、桑拿、室内游泳池、中式餐厅、残疾人设施、室外游泳池、ATM取款机、商务中心不能为空', trigger: 'blur' }
          ],
          service: [
            { required: true, message: '酒店服务运通、万事达、洗衣服务、接站服务、行李寄存、携带宠物、威士、JCB卡、早餐服务、大来、接受银行卡、接机服务、叫醒服务不能为空', trigger: 'blur' }
          ],
          sp: [
            { required: true, message: '起价单位：分不能为空', trigger: 'blur' }
          ],
          openTime: [
            { required: true, message: '开业时间酒店填写的营业时间，无固定格式，如取值可以为“24小时”。不能为空', trigger: 'blur' }
          ],
          decorateTime: [
            { required: true, message: '装修时间不能为空', trigger: 'blur' }
          ],
          floor: [
            { required: true, message: '楼层信息不能为空', trigger: 'blur' }
          ],
          chinaHotel: [
            { required: true, message: '是否国内酒店不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '酒店营业状态不能为空', trigger: 'blur' }
          ],
          pictureurl: [
            { required: true, message: '首图信息不能为空', trigger: 'blur' }
          ],
          brand: [
            { required: true, message: '品牌 不能为空', trigger: 'blur' }
          ],
          dataFrom: [
            { required: true, message: '数据来源1:携程2：美团3：美团商旅     4：携程美团商旅   5：携程商旅美团   6：携程商旅美团商旅不能为空', trigger: 'blur' }
          ],
          manualVerify: [
            { required: true, message: '是否人工已校准不能为空', trigger: 'blur' }
          ],
          automaticOrder: [
            { required: true, message: '是否自动下单不能为空', trigger: 'blur' }
          ],
          isMatch: [
            { required: true, message: '是否已经匹配不能为空', trigger: 'blur' }
          ],
          htgroup: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isDel: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          aliCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          brandName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          shid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          atype: [
            { required: true, message: '连锁品牌，家庭旅馆不能为空', trigger: 'blur' }
          ],
          poiType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          hotelNameAli: [
            { required: true, message: '阿里酒店名称不能为空', trigger: 'blur' }
          ],
          compositeHotelCode: [
            { required: true, message: '酒店编码组合 不同数据来源酒店编码以逗号分隔 例如（123,456,789）不能为空', trigger: 'blur' }
          ],
          partnerId: [
            { required: true, message: '美团账号不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/hthotelinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.hotelCode = data.htHotelinfo.hotelCode
                this.dataForm.hotelName = data.htHotelinfo.hotelName
                this.dataForm.hotelNameEn = data.htHotelinfo.hotelNameEn
                this.dataForm.address = data.htHotelinfo.address
                this.dataForm.country = data.htHotelinfo.country
                this.dataForm.province = data.htHotelinfo.province
                this.dataForm.district = data.htHotelinfo.district
                this.dataForm.city = data.htHotelinfo.city
                this.dataForm.county = data.htHotelinfo.county
                this.dataForm.area = data.htHotelinfo.area
                this.dataForm.phone = data.htHotelinfo.phone
                this.dataForm.hotelInfo = data.htHotelinfo.hotelInfo
                this.dataForm.axes = data.htHotelinfo.axes
                this.dataForm.axesX = data.htHotelinfo.axesX
                this.dataForm.axesY = data.htHotelinfo.axesY
                this.dataForm.starLevel = data.htHotelinfo.starLevel
                this.dataForm.hotelType = data.htHotelinfo.hotelType
                this.dataForm.hotelFacilities = data.htHotelinfo.hotelFacilities
                this.dataForm.service = data.htHotelinfo.service
                this.dataForm.sp = data.htHotelinfo.sp
                this.dataForm.openTime = data.htHotelinfo.openTime
                this.dataForm.decorateTime = data.htHotelinfo.decorateTime
                this.dataForm.floor = data.htHotelinfo.floor
                this.dataForm.chinaHotel = data.htHotelinfo.chinaHotel
                this.dataForm.status = data.htHotelinfo.status
                this.dataForm.pictureurl = data.htHotelinfo.pictureurl
                this.dataForm.brand = data.htHotelinfo.brand
                this.dataForm.dataFrom = data.htHotelinfo.dataFrom
                this.dataForm.manualVerify = data.htHotelinfo.manualVerify
                this.dataForm.automaticOrder = data.htHotelinfo.automaticOrder
                this.dataForm.isMatch = data.htHotelinfo.isMatch
                this.dataForm.htgroup = data.htHotelinfo.htgroup
                this.dataForm.isDel = data.htHotelinfo.isDel
                this.dataForm.aliCode = data.htHotelinfo.aliCode
                this.dataForm.brandName = data.htHotelinfo.brandName
                this.dataForm.shid = data.htHotelinfo.shid
                this.dataForm.atype = data.htHotelinfo.atype
                this.dataForm.poiType = data.htHotelinfo.poiType
                this.dataForm.hotelNameAli = data.htHotelinfo.hotelNameAli
                this.dataForm.compositeHotelCode = data.htHotelinfo.compositeHotelCode
                this.dataForm.partnerId = data.htHotelinfo.partnerId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/hthotelinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'hotelCode': this.dataForm.hotelCode,
                'hotelName': this.dataForm.hotelName,
                'hotelNameEn': this.dataForm.hotelNameEn,
                'address': this.dataForm.address,
                'country': this.dataForm.country,
                'province': this.dataForm.province,
                'district': this.dataForm.district,
                'city': this.dataForm.city,
                'county': this.dataForm.county,
                'area': this.dataForm.area,
                'phone': this.dataForm.phone,
                'hotelInfo': this.dataForm.hotelInfo,
                'axes': this.dataForm.axes,
                'axesX': this.dataForm.axesX,
                'axesY': this.dataForm.axesY,
                'starLevel': this.dataForm.starLevel,
                'hotelType': this.dataForm.hotelType,
                'hotelFacilities': this.dataForm.hotelFacilities,
                'service': this.dataForm.service,
                'sp': this.dataForm.sp,
                'openTime': this.dataForm.openTime,
                'decorateTime': this.dataForm.decorateTime,
                'floor': this.dataForm.floor,
                'chinaHotel': this.dataForm.chinaHotel,
                'status': this.dataForm.status,
                'pictureurl': this.dataForm.pictureurl,
                'brand': this.dataForm.brand,
                'dataFrom': this.dataForm.dataFrom,
                'manualVerify': this.dataForm.manualVerify,
                'automaticOrder': this.dataForm.automaticOrder,
                'isMatch': this.dataForm.isMatch,
                'htgroup': this.dataForm.htgroup,
                'isDel': this.dataForm.isDel,
                'aliCode': this.dataForm.aliCode,
                'brandName': this.dataForm.brandName,
                'shid': this.dataForm.shid,
                'atype': this.dataForm.atype,
                'poiType': this.dataForm.poiType,
                'hotelNameAli': this.dataForm.hotelNameAli,
                'compositeHotelCode': this.dataForm.compositeHotelCode,
                'partnerId': this.dataForm.partnerId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
