<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="rpCode">
      <el-input v-model="dataForm.rpCode" placeholder="逻辑房型编码"></el-input>
    </el-form-item>
    <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="rpName">
      <el-input v-model="dataForm.rpName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="是否需要用户真实手机号" prop="isPhone">
      <el-input v-model="dataForm.isPhone" placeholder="是否需要用户真实手机号"></el-input>
    </el-form-item>
    <el-form-item label="房态" prop="roomStatus">
      <el-input v-model="dataForm.roomStatus" placeholder="房态"></el-input>
    </el-form-item>
    <el-form-item label="产品类型
            rp类型，1为小时房。目前只支持小时房。如果不是小时房rateplan,则不要填写。如果想要清空该字段可以传入none" prop="rpType">
      <el-input v-model="dataForm.rpType" placeholder="产品类型
            rp类型，1为小时房。目前只支持小时房。如果不是小时房rateplan,则不要填写。如果想要清空该字段可以传入none"></el-input>
    </el-form-item>
    <el-form-item label="确认类型" prop="verifyType">
      <el-input v-model="dataForm.verifyType" placeholder="确认类型"></el-input>
    </el-form-item>
    <el-form-item label="平均价格" prop="avgPrice">
      <el-input v-model="dataForm.avgPrice" placeholder="平均价格"></el-input>
    </el-form-item>
    <el-form-item label="市场价格" prop="marketPrice">
      <el-input v-model="dataForm.marketPrice" placeholder="市场价格"></el-input>
    </el-form-item>
    <el-form-item label="是否第三方产品" prop="isThree">
      <el-input v-model="dataForm.isThree" placeholder="是否第三方产品"></el-input>
    </el-form-item>
    <el-form-item label="早餐个数" prop="breakfastNum">
      <el-input v-model="dataForm.breakfastNum" placeholder="早餐个数"></el-input>
    </el-form-item>
    <el-form-item label="支付类型
            支付类型，只支持：1：预付5：现付6: 信用住7:在线预约8:在线预约信用住。其中5,6,7,8三种类型需要申请权限" prop="paymentType">
      <el-input v-model="dataForm.paymentType" placeholder="支付类型
            支付类型，只支持：1：预付5：现付6: 信用住7:在线预约8:在线预约信用住。其中5,6,7,8三种类型需要申请权限"></el-input>
    </el-form-item>
    <el-form-item label="最小连住" prop="minDays">
      <el-input v-model="dataForm.minDays" placeholder="最小连住"></el-input>
    </el-form-item>
    <el-form-item label="最大连住" prop="maxDays">
      <el-input v-model="dataForm.maxDays" placeholder="最大连住"></el-input>
    </el-form-item>
    <el-form-item label="最小提前预定(小时)" prop="minHours">
      <el-input v-model="dataForm.minHours" placeholder="最小提前预定(小时)"></el-input>
    </el-form-item>
    <el-form-item label="最大提前预定(小时)" prop="maxHours">
      <el-input v-model="dataForm.maxHours" placeholder="最大提前预定(小时)"></el-input>
    </el-form-item>
    <el-form-item label="设施服务" prop="services">
      <el-input v-model="dataForm.services" placeholder="设施服务"></el-input>
    </el-form-item>
    <el-form-item label="有效期开始" prop="startDate">
      <el-input v-model="dataForm.startDate" placeholder="有效期开始"></el-input>
    </el-form-item>
    <el-form-item label="有效期结束" prop="endDate">
      <el-input v-model="dataForm.endDate" placeholder="有效期结束"></el-input>
    </el-form-item>
    <el-form-item label="每天生效时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="每天生效时间"></el-input>
    </el-form-item>
    <el-form-item label="每天失效时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="每天失效时间"></el-input>
    </el-form-item>
    <el-form-item label="担保规则" prop="guaranteeRule">
      <el-input v-model="dataForm.guaranteeRule" placeholder="担保规则"></el-input>
    </el-form-item>
    <el-form-item label="退订政策" prop="cancelPolicy">
      <el-input v-model="dataForm.cancelPolicy" placeholder="退订政策"></el-input>
    </el-form-item>
    <el-form-item label="价格政策来源" prop="cancelPolicyFrom">
      <el-input v-model="dataForm.cancelPolicyFrom" 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="type">
      <el-input v-model="dataForm.type" placeholder="类型"></el-input>
    </el-form-item>
    <el-form-item label="" prop="minAmount">
      <el-input v-model="dataForm.minAmount" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="enName">
      <el-input v-model="dataForm.enName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="销售渠道。如需开通，需要申请权限。目前支持的渠道有 H:飞猪 O:钉钉商旅 A:集团内部商旅 M:无线专享价。如果只投放飞猪，改字段不用填写或者只填H；如果有多个用,分开。如果需要投放其他渠道，请联系飞猪运营或者技术支持" prop="channel">
      <el-input v-model="dataForm.channel" placeholder="销售渠道。如需开通，需要申请权限。目前支持的渠道有 H:飞猪 O:钉钉商旅 A:集团内部商旅 M:无线专享价。如果只投放飞猪，改字段不用填写或者只填H；如果有多个用,分开。如果需要投放其他渠道，请联系飞猪运营或者技术支持"></el-input>
    </el-form-item>
    <el-form-item label="" prop="breakfastCal">
      <el-input v-model="dataForm.breakfastCal" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="cancelPolicyCal">
      <el-input v-model="dataForm.cancelPolicyCal" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="最晚可选离店时间，小时房特有字段。格式为HH:mm" prop="canCheckoutEnd">
      <el-input v-model="dataForm.canCheckoutEnd" placeholder="最晚可选离店时间，小时房特有字段。格式为HH:mm"></el-input>
    </el-form-item>
    <el-form-item label="" prop="cancelPolicyType">
      <el-input v-model="dataForm.cancelPolicyType" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="cancelPolicyText">
      <el-input v-model="dataForm.cancelPolicyText" 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>
    <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,
          rpCode: '',
          hotelCode: '',
          roomCode: '',
          rpName: '',
          isPhone: '',
          roomStatus: '',
          rpType: '',
          verifyType: '',
          avgPrice: '',
          marketPrice: '',
          isThree: '',
          breakfastNum: '',
          paymentType: '',
          minDays: '',
          maxDays: '',
          minHours: '',
          maxHours: '',
          services: '',
          startDate: '',
          endDate: '',
          startTime: '',
          endTime: '',
          guaranteeRule: '',
          cancelPolicy: '',
          cancelPolicyFrom: '',
          status: '',
          type: '',
          minAmount: '',
          enName: '',
          channel: '',
          breakfastCal: '',
          cancelPolicyCal: '',
          canCheckoutEnd: '',
          cancelPolicyType: '',
          cancelPolicyText: '',
          isCorrect: '',
          isAutoOrder: ''
        },
        dataRule: {
          rpCode: [
            { required: true, message: '逻辑房型编码不能为空', trigger: 'blur' }
          ],
          hotelCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          roomCode: [
            { required: true, message: '物理房型编码不能为空', trigger: 'blur' }
          ],
          rpName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isPhone: [
            { required: true, message: '是否需要用户真实手机号不能为空', trigger: 'blur' }
          ],
          roomStatus: [
            { required: true, message: '房态不能为空', trigger: 'blur' }
          ],
          rpType: [
            { required: true, message: '产品类型rp类型，1为小时房。目前只支持小时房。如果不是小时房rateplan,则不要填写。如果想要清空该字段可以传入none不能为空', trigger: 'blur' }
          ],
          verifyType: [
            { required: true, message: '确认类型不能为空', trigger: 'blur' }
          ],
          avgPrice: [
            { required: true, message: '平均价格不能为空', trigger: 'blur' }
          ],
          marketPrice: [
            { required: true, message: '市场价格不能为空', trigger: 'blur' }
          ],
          isThree: [
            { required: true, message: '是否第三方产品不能为空', trigger: 'blur' }
          ],
          breakfastNum: [
            { required: true, message: '早餐个数不能为空', trigger: 'blur' }
          ],
          paymentType: [
            { required: true, message: '支付类型支付类型，只支持：1：预付5：现付6: 信用住7:在线预约8:在线预约信用住。其中5,6,7,8三种类型需要申请权限不能为空', trigger: 'blur' }
          ],
          minDays: [
            { required: true, message: '最小连住不能为空', trigger: 'blur' }
          ],
          maxDays: [
            { required: true, message: '最大连住不能为空', trigger: 'blur' }
          ],
          minHours: [
            { required: true, message: '最小提前预定(小时)不能为空', trigger: 'blur' }
          ],
          maxHours: [
            { required: true, message: '最大提前预定(小时)不能为空', trigger: 'blur' }
          ],
          services: [
            { required: true, message: '设施服务不能为空', trigger: 'blur' }
          ],
          startDate: [
            { required: true, message: '有效期开始不能为空', trigger: 'blur' }
          ],
          endDate: [
            { required: true, message: '有效期结束不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '每天生效时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '每天失效时间不能为空', trigger: 'blur' }
          ],
          guaranteeRule: [
            { required: true, message: '担保规则不能为空', trigger: 'blur' }
          ],
          cancelPolicy: [
            { required: true, message: '退订政策不能为空', trigger: 'blur' }
          ],
          cancelPolicyFrom: [
            { required: true, message: '价格政策来源不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类型不能为空', trigger: 'blur' }
          ],
          minAmount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          enName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          channel: [
            { required: true, message: '销售渠道。如需开通，需要申请权限。目前支持的渠道有 H:飞猪 O:钉钉商旅 A:集团内部商旅 M:无线专享价。如果只投放飞猪，改字段不用填写或者只填H；如果有多个用","分开。如果需要投放其他渠道，请联系飞猪运营或者技术支持不能为空', trigger: 'blur' }
          ],
          breakfastCal: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          cancelPolicyCal: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          canCheckoutEnd: [
            { required: true, message: '最晚可选离店时间，小时房特有字段。格式为HH:mm不能为空', trigger: 'blur' }
          ],
          cancelPolicyType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          cancelPolicyText: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isCorrect: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isAutoOrder: [
            { 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/htlogicroom/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.rpCode = data.htLogicRoom.rpCode
                this.dataForm.hotelCode = data.htLogicRoom.hotelCode
                this.dataForm.roomCode = data.htLogicRoom.roomCode
                this.dataForm.rpName = data.htLogicRoom.rpName
                this.dataForm.isPhone = data.htLogicRoom.isPhone
                this.dataForm.roomStatus = data.htLogicRoom.roomStatus
                this.dataForm.rpType = data.htLogicRoom.rpType
                this.dataForm.verifyType = data.htLogicRoom.verifyType
                this.dataForm.avgPrice = data.htLogicRoom.avgPrice
                this.dataForm.marketPrice = data.htLogicRoom.marketPrice
                this.dataForm.isThree = data.htLogicRoom.isThree
                this.dataForm.breakfastNum = data.htLogicRoom.breakfastNum
                this.dataForm.paymentType = data.htLogicRoom.paymentType
                this.dataForm.minDays = data.htLogicRoom.minDays
                this.dataForm.maxDays = data.htLogicRoom.maxDays
                this.dataForm.minHours = data.htLogicRoom.minHours
                this.dataForm.maxHours = data.htLogicRoom.maxHours
                this.dataForm.services = data.htLogicRoom.services
                this.dataForm.startDate = data.htLogicRoom.startDate
                this.dataForm.endDate = data.htLogicRoom.endDate
                this.dataForm.startTime = data.htLogicRoom.startTime
                this.dataForm.endTime = data.htLogicRoom.endTime
                this.dataForm.guaranteeRule = data.htLogicRoom.guaranteeRule
                this.dataForm.cancelPolicy = data.htLogicRoom.cancelPolicy
                this.dataForm.cancelPolicyFrom = data.htLogicRoom.cancelPolicyFrom
                this.dataForm.status = data.htLogicRoom.status
                this.dataForm.type = data.htLogicRoom.type
                this.dataForm.minAmount = data.htLogicRoom.minAmount
                this.dataForm.enName = data.htLogicRoom.enName
                this.dataForm.channel = data.htLogicRoom.channel
                this.dataForm.breakfastCal = data.htLogicRoom.breakfastCal
                this.dataForm.cancelPolicyCal = data.htLogicRoom.cancelPolicyCal
                this.dataForm.canCheckoutEnd = data.htLogicRoom.canCheckoutEnd
                this.dataForm.cancelPolicyType = data.htLogicRoom.cancelPolicyType
                this.dataForm.cancelPolicyText = data.htLogicRoom.cancelPolicyText
                this.dataForm.isCorrect = data.htLogicRoom.isCorrect
                this.dataForm.isAutoOrder = data.htLogicRoom.isAutoOrder
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/ht/htlogicroom/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'rpCode': this.dataForm.rpCode,
                'hotelCode': this.dataForm.hotelCode,
                'roomCode': this.dataForm.roomCode,
                'rpName': this.dataForm.rpName,
                'isPhone': this.dataForm.isPhone,
                'roomStatus': this.dataForm.roomStatus,
                'rpType': this.dataForm.rpType,
                'verifyType': this.dataForm.verifyType,
                'avgPrice': this.dataForm.avgPrice,
                'marketPrice': this.dataForm.marketPrice,
                'isThree': this.dataForm.isThree,
                'breakfastNum': this.dataForm.breakfastNum,
                'paymentType': this.dataForm.paymentType,
                'minDays': this.dataForm.minDays,
                'maxDays': this.dataForm.maxDays,
                'minHours': this.dataForm.minHours,
                'maxHours': this.dataForm.maxHours,
                'services': this.dataForm.services,
                'startDate': this.dataForm.startDate,
                'endDate': this.dataForm.endDate,
                'startTime': this.dataForm.startTime,
                'endTime': this.dataForm.endTime,
                'guaranteeRule': this.dataForm.guaranteeRule,
                'cancelPolicy': this.dataForm.cancelPolicy,
                'cancelPolicyFrom': this.dataForm.cancelPolicyFrom,
                'status': this.dataForm.status,
                'type': this.dataForm.type,
                'minAmount': this.dataForm.minAmount,
                'enName': this.dataForm.enName,
                'channel': this.dataForm.channel,
                'breakfastCal': this.dataForm.breakfastCal,
                'cancelPolicyCal': this.dataForm.cancelPolicyCal,
                'canCheckoutEnd': this.dataForm.canCheckoutEnd,
                'cancelPolicyType': this.dataForm.cancelPolicyType,
                'cancelPolicyText': this.dataForm.cancelPolicyText,
                'isCorrect': this.dataForm.isCorrect,
                'isAutoOrder': this.dataForm.isAutoOrder
              })
            }).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>
