<template>
  <div>
    <el-dialog
      v-loading="loading"
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      :title="curObj.room + '-修改户型'"
      :fullscreen="false"
      width="700px"
      custom-class="xl-dialog"
      center
    >
      <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px">
      </base-form>
      <div class="xl-form">
        <div class="xl-form-footer">
          <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
          <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  components: { },
  mixins,
  props: {
    isShow: Boolean,
    curObj: Object,
    roomAreaList: Array,
  },
  inject: ['parentData'],
  data() {
    return {
      loading: false,
      formData: [],
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        // console.log(this.curObj)
        this.getDef()
      }
    },
  },
  methods: {
    getDef (str) {
      let params = {}
      this.formData = [
        { label: `户型`, key: 'ht', type: 'select', options: this.roomAreaList}
      ]
      this.setDefaultValue(params)
    },
    close (str) {
      if (str === 'confirm') {
        this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
          if (valid) {
            const oldform = this.$refs.ruleForm.baseForm
            let newForm = { ...oldform }
            let house_type = ''
            let house_img = ''
            this.roomAreaList.forEach(ra => {
              if (newForm['ht'] === ra.id) {
                house_type = ra.key2
                house_img = ra.pri_image
              }
            })
            this.$api.house.admestatelotterypriceedit({
              ...this.curObj,
              house_type,
              house_img,
            }).then(res => {
              this.$emit('close', house_type)
              this.$msgs('更新成功~')
            })
          }
        })
      } else {
        this.$emit('close')
      }
    },
  }
}
</script>
<style lang="scss" scoped>
@import '../../../../styles/libEdit.scss';
.lib-edit {
  padding-top: 0;
  ::v-deep .el-date-editor.el-input {
    width: 100%;
  }
  ::v-deep .el-textarea__inner {
    height: 300px;
  }
}

.scoped-img-area {
  padding-left: 40px;
  .sia-op {
    display: inline-block;
    vertical-align: middle;
    margin-right: 10px;
    margin-bottom: 10px;
    border: 1px solid #f2f2f2;
    width: 80px;
    height: 80px;
    position: relative;
    &:hover {
      .img-big {
        display: block;
      }
    }
    .img {
      width: 80px;
      height: 80px;
    }
    .close {
      position: absolute;
      width: 20px;
      height: 20px;
      top: -10px;
      right: -10px;
      background: url(../../../../assets/icon_g_close.png) no-repeat;
      background-size: 20px;
      cursor: pointer;
    }
    .img-big {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 400px;
      height: auto;
      display: none;
      box-shadow: 10px 10px 10px #ccc;
      z-index: 99;
    }
  }
  .sia-img {
    display: inline-block;
    vertical-align: middle;
    width: 80px;
    height: 80px;
    overflow: hidden;
    border: 1px dashed #999;
    margin-bottom: 10px;
    .el-icon-plus {
      color: #999;
      padding: 30px;
    }
  }
}
</style>
