<template>
  <div>
    <el-dialog
      v-loading="loading"
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      :title="`${curObj.estate_name}更新佣金`"
      :fullscreen="false"
      width="700px"
      custom-class="xl-dialog"
      center
    >
      <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px">
        <div slot="footer" style="padding-top: 20px;">
          <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
          <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
          <el-button class="xl-form-btn t3" @click="linkPriceLog">查看历史佣金</el-button>
        </div>
      </base-form>
    </el-dialog>
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
export default {
  components: {
  },
  mixins,
  props: {
    isShow: Boolean,
    curObj: Object
  },
  inject: ['parentData'],
  data() {
    const token = window.sessionStorage.getItem('fp_token')
    let domainUrl = process.env.VUE_APP_BASE_API
    return {
      domainUrl,
      token,
      loading: false,
      formData: [],
      cObj: {},
      isShowMap: false,
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        if (this.curObj.id) {
          this.$api.house.admestatedetail({id: this.curObj.id}).then(res => {
            this.cObj = res || {}
            this.getDef()
          })
        } else {
          this.cObj = this.curObj
          this.getDef()
        }
      }
    },
  },
  methods: {
    linkPriceLog () {
      this.$emit('close')
      this.$router.push(`/house/indexPriceLog?id=${this.cObj.id}&t=${this.cObj.estate_name}`)
    },
    getDef () {
      let params = {...this.cObj}
      this.formData = [
        { label: '佣金标准', key: 'brokerage', type: 'textarea', rules: 1 },
      ]
      this.setDefaultValue(params)
    },
    close (str) {
      if (str === 'confirm') {
        this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
          if (valid) {
            const oldform = this.$refs.ruleForm.baseForm
            const newForm = { ...oldform }
            let apiStr = 'admestatebrokerageupdate'
            if (this.curObj.id) {
              newForm.id = this.curObj.id
              apiStr = 'admestatebrokerageupdate'
            }
            this.$api.house[apiStr](newForm).then(data => {
              this.$msgs(newForm.id ? '编辑成功' : '新增成功')
              this.$emit('close', newForm)
            })
          }
        })
      } else {
        this.$emit('close')
        this.setDefaultValue()
      }
    },
  }
}
</script>
<style lang="scss" scoped>
@import '../../../../styles/libEdit.scss';
.lib-edit {
  width: 600px;
  padding-top: 0;
  padding-left: 0;
  padding-bottom: 40px;
  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }
  ::v-deep .el-date-editor.el-input {
    width: 100%;
  }
}
.scoped-other-form {
  .scoped-item-two {
    .el-input {
      display: inline-block;
      width: 120px;
      margin: 0 10px;
    }
  }
}
.map-btn{
  height: 36px;
}
::v-deep .el-drawer__header {
  margin-bottom: 10px;
}

::v-deep .img-upload {
  width: 120px;
  height: 80px;
  .icon {
    width: 120px;
    height: 80px;
    line-height: 80px;
  }
  .img {
    width: 120px;
    height: 80px;
  }
}

</style>
