<template>
  <div>
    <el-dialog
      v-loading="loading"
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      :title="curObj.id ? '编辑渠道佣金' : '新增渠道佣金'"
      :fullscreen="false"
      width="400px"
      custom-class="xl-dialog"
      center
    >
      <base-form ref="ruleForm" :data="formData" :is-inline="false" label-width="80px">
      </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>
import { arrToObj } from '@/utils'
export default {
  components: { },
  mixins,
  props: {
    isShow: Boolean,
    curObj: Object
  },
  inject: ['parentData'],
  data() {
    return {
      loading: false,
      formData: [],
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        this.getDef()
      }
    },
  },
  methods: {
    getDef (str) {
      let params = { ...this.curObj }
      this.formData = [
        { label: '渠道平台', key: 'company', type: 'select', options: this.$dictData.brokerage_company, rules: 1 },
        { label: '佣金描述', key: 'brokerage', type: 'textarea', rules: 1 },
        { label: '带看材料', key: 'report_visit', type: 'textarea' },
      ]
      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 }
            newForm.estate_lib_id = this.parentData.searchForm.estate_lib_id
            let apiStr = 'admbrokerageadd'
            if (this.curObj.id) {
              newForm.id = this.curObj.id
              apiStr = 'admbrokerageedit'
            }
            this.$api.house[apiStr](newForm).then(data => {
              this.$msgs('操作成功')
              this.$emit('close', newForm)
            })
          }
        })
      } else {
        this.$emit('close')
        this.setDefaultValue()
      }
    },
  }
}
</script>
<style lang="scss" scoped>
</style>
