<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="roomCode">
      <el-input v-model="dataForm.roomCode" placeholder="房型编码"></el-input>
    </el-form-item>
    <el-form-item label="房型名称" prop="roomName">
      <el-input v-model="dataForm.roomName" placeholder="房型名称"></el-input>
    </el-form-item>
    <el-form-item label="最大入住人数" prop="maxNum">
      <el-input v-model="dataForm.maxNum" placeholder="最大入住人数"></el-input>
    </el-form-item>
    <el-form-item label="房间大小" prop="roomSize">
      <el-input v-model="dataForm.roomSize" placeholder="房间大小"></el-input>
    </el-form-item>
    <el-form-item label="房间所在楼层" prop="roomFloor">
      <el-input v-model="dataForm.roomFloor" placeholder="房间所在楼层"></el-input>
    </el-form-item>
    <el-form-item label="床型" prop="bedPad">
      <el-input v-model="dataForm.bedPad" placeholder="床型"></el-input>
    </el-form-item>
    <el-form-item label="床宽" prop="bedWidth">
      <el-input v-model="dataForm.bedWidth" placeholder="床宽"></el-input>
    </el-form-item>
    <el-form-item label="房间描述" prop="roomContent">
      <el-input v-model="dataForm.roomContent" placeholder="房间描述"></el-input>
    </el-form-item>
    <el-form-item label="房间窗户情况
            0:无窗/1:有窗/2:部分有窗/3:暗窗/4:部分暗窗" prop="windows">
      <el-input v-model="dataForm.windows" placeholder="房间窗户情况
            0:无窗/1:有窗/2:部分有窗/3:暗窗/4:部分暗窗"></el-input>
    </el-form-item>
    <el-form-item label="窗景描述" prop="windowInfo">
      <el-input v-model="dataForm.windowInfo" placeholder="窗景描述"></el-input>
    </el-form-item>
    <el-form-item label="房间上网方式
            宽带服务。A,B,C,D。分别代表： A：无宽带，B：免费宽带，C：收费宽带，D：部分收费宽带" prop="internet">
      <el-input v-model="dataForm.internet" placeholder="房间上网方式
            宽带服务。A,B,C,D。分别代表： A：无宽带，B：免费宽带，C：收费宽带，D：部分收费宽带"></el-input>
    </el-form-item>
    <el-form-item label="窗户不利因素" prop="windowBad">
      <el-input v-model="dataForm.windowBad" placeholder="窗户不利因素"></el-input>
    </el-form-item>
    <el-form-item label="加床情况" prop="upBed">
      <el-input v-model="dataForm.upBed" placeholder="加床情况"></el-input>
    </el-form-item>
    <el-form-item label="房型状态
            房型状态。0:正常，-1:删除，-2:停售" prop="roomStatus">
      <el-input v-model="dataForm.roomStatus" placeholder="房型状态
            房型状态。0:正常，-1:删除，-2:停售"></el-input>
    </el-form-item>
    <el-form-item label="房间最大容纳儿童人数" prop="maxChild">
      <el-input v-model="dataForm.maxChild" placeholder="房间最大容纳儿童人数"></el-input>
    </el-form-item>
    <el-form-item label="房型设施" prop="houseType">
      <el-input v-model="dataForm.houseType" placeholder="房型设施"></el-input>
    </el-form-item>
    <el-form-item label="是否人工已校准" prop="isCorrect">
      <el-input v-model="dataForm.isCorrect" placeholder="是否人工已校准"></el-input>
    </el-form-item>
    <el-form-item label="是否自动下单" prop="isAutoOrder">
      <el-input v-model="dataForm.isAutoOrder" placeholder="是否自动下单"></el-input>
    </el-form-item>
    <el-form-item label="1、携程
            2、美团
            3、爬虫
            4、自购
            5、其他" prop="dataFrom">
      <el-input v-model="dataForm.dataFrom" placeholder="1、携程
            2、美团
            3、爬虫
            4、自购
            5、其他"></el-input>
    </el-form-item>
    <el-form-item label="匹配状态: 0：待系统匹配 1：已系统匹配，匹配成功，待卖家确认 2：已系统匹配，匹配失败，待人工匹配 3：已人工匹配，匹配成功，待卖家确认 4：已人工匹配，匹配失败 5：卖家已确认，确认“YES” 6：卖家已确认，确认“NO” 7:已系统匹配，但是匹配重复，待人工确认" prop="matchStatus">
      <el-input v-model="dataForm.matchStatus" placeholder="匹配状态: 0：待系统匹配 1：已系统匹配，匹配成功，待卖家确认 2：已系统匹配，匹配失败，待人工匹配 3：已人工匹配，匹配成功，待卖家确认 4：已人工匹配，匹配失败 5：卖家已确认，确认“YES” 6：卖家已确认，确认“NO” 7:已系统匹配，但是匹配重复，待人工确认"></el-input>
    </el-form-item>
    <el-form-item label="房间设施" prop="facility">
      <el-input v-model="dataForm.facility" placeholder="房间设施"></el-input>
    </el-form-item>
    <el-form-item label="" prop="srid">
      <el-input v-model="dataForm.srid" 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: '',
          roomCode: '',
          roomName: '',
          maxNum: '',
          roomSize: '',
          roomFloor: '',
          bedPad: '',
          bedWidth: '',
          roomContent: '',
          windows: '',
          windowInfo: '',
          internet: '',
          windowBad: '',
          upBed: '',
          roomStatus: '',
          maxChild: '',
          houseType: '',
          isCorrect: '',
          isAutoOrder: '',
          dataFrom: '',
          matchStatus: '',
          facility: '',
          srid: ''
        },
        dataRule: {
          hotelCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          roomCode: [
            { required: true, message: '房型编码不能为空', trigger: 'blur' }
          ],
          roomName: [
            { required: true, message: '房型名称不能为空', trigger: 'blur' }
          ],
          maxNum: [
            { required: true, message: '最大入住人数不能为空', trigger: 'blur' }
          ],
          roomSize: [
            { required: true, message: '房间大小不能为空', trigger: 'blur' }
          ],
          roomFloor: [
            { required: true, message: '房间所在楼层不能为空', trigger: 'blur' }
          ],
          bedPad: [
            { required: true, message: '床型不能为空', trigger: 'blur' }
          ],
          bedWidth: [
            { required: true, message: '床宽不能为空', trigger: 'blur' }
          ],
          roomContent: [
            { required: true, message: '房间描述不能为空', trigger: 'blur' }
          ],
          windows: [
            { required: true, message: '房间窗户情况0:无窗/1:有窗/2:部分有窗/3:暗窗/4:部分暗窗不能为空', trigger: 'blur' }
          ],
          windowInfo: [
            { required: true, message: '窗景描述不能为空', trigger: 'blur' }
          ],
          internet: [
            { required: true, message: '房间上网方式宽带服务。A,B,C,D。分别代表： A：无宽带，B：免费宽带，C：收费宽带，D：部分收费宽带不能为空', trigger: 'blur' }
          ],
          windowBad: [
            { required: true, message: '窗户不利因素不能为空', trigger: 'blur' }
          ],
          upBed: [
            { required: true, message: '加床情况不能为空', trigger: 'blur' }
          ],
          roomStatus: [
            { required: true, message: '房型状态房型状态。0:正常，-1:删除，-2:停售不能为空', trigger: 'blur' }
          ],
          maxChild: [
            { required: true, message: '房间最大容纳儿童人数不能为空', trigger: 'blur' }
          ],
          houseType: [
            { required: true, message: '房型设施不能为空', trigger: 'blur' }
          ],
          isCorrect: [
            { required: true, message: '是否人工已校准不能为空', trigger: 'blur' }
          ],
          isAutoOrder: [
            { required: true, message: '是否自动下单不能为空', trigger: 'blur' }
          ],
          dataFrom: [
            { required: true, message: '1、携程2、美团3、爬虫4、自购5、其他不能为空', trigger: 'blur' }
          ],
          matchStatus: [
            { required: true, message: '匹配状态: 0：待系统匹配 1：已系统匹配，匹配成功，待卖家确认 2：已系统匹配，匹配失败，待人工匹配 3：已人工匹配，匹配成功，待卖家确认 4：已人工匹配，匹配失败 5：卖家已确认，确认“YES” 6：卖家已确认，确认“NO” 7:已系统匹配，但是匹配重复，待人工确认不能为空', trigger: 'blur' }
          ],
          facility: [
            { required: true, message: '房间设施不能为空', trigger: 'blur' }
          ],
          srid: [
            { 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(`/ht/htphysicalroom/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.hotelCode = data.htPhysicalRoom.hotelCode
                this.dataForm.roomCode = data.htPhysicalRoom.roomCode
                this.dataForm.roomName = data.htPhysicalRoom.roomName
                this.dataForm.maxNum = data.htPhysicalRoom.maxNum
                this.dataForm.roomSize = data.htPhysicalRoom.roomSize
                this.dataForm.roomFloor = data.htPhysicalRoom.roomFloor
                this.dataForm.bedPad = data.htPhysicalRoom.bedPad
                this.dataForm.bedWidth = data.htPhysicalRoom.bedWidth
                this.dataForm.roomContent = data.htPhysicalRoom.roomContent
                this.dataForm.windows = data.htPhysicalRoom.windows
                this.dataForm.windowInfo = data.htPhysicalRoom.windowInfo
                this.dataForm.internet = data.htPhysicalRoom.internet
                this.dataForm.windowBad = data.htPhysicalRoom.windowBad
                this.dataForm.upBed = data.htPhysicalRoom.upBed
                this.dataForm.roomStatus = data.htPhysicalRoom.roomStatus
                this.dataForm.maxChild = data.htPhysicalRoom.maxChild
                this.dataForm.houseType = data.htPhysicalRoom.houseType
                this.dataForm.isCorrect = data.htPhysicalRoom.isCorrect
                this.dataForm.isAutoOrder = data.htPhysicalRoom.isAutoOrder
                this.dataForm.dataFrom = data.htPhysicalRoom.dataFrom
                this.dataForm.matchStatus = data.htPhysicalRoom.matchStatus
                this.dataForm.facility = data.htPhysicalRoom.facility
                this.dataForm.srid = data.htPhysicalRoom.srid
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/ht/htphysicalroom/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'hotelCode': this.dataForm.hotelCode,
                'roomCode': this.dataForm.roomCode,
                'roomName': this.dataForm.roomName,
                'maxNum': this.dataForm.maxNum,
                'roomSize': this.dataForm.roomSize,
                'roomFloor': this.dataForm.roomFloor,
                'bedPad': this.dataForm.bedPad,
                'bedWidth': this.dataForm.bedWidth,
                'roomContent': this.dataForm.roomContent,
                'windows': this.dataForm.windows,
                'windowInfo': this.dataForm.windowInfo,
                'internet': this.dataForm.internet,
                'windowBad': this.dataForm.windowBad,
                'upBed': this.dataForm.upBed,
                'roomStatus': this.dataForm.roomStatus,
                'maxChild': this.dataForm.maxChild,
                'houseType': this.dataForm.houseType,
                'isCorrect': this.dataForm.isCorrect,
                'isAutoOrder': this.dataForm.isAutoOrder,
                'dataFrom': this.dataForm.dataFrom,
                'matchStatus': this.dataForm.matchStatus,
                'facility': this.dataForm.facility,
                'srid': this.dataForm.srid
              })
            }).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>
