<template>
  <div>
    <el-dialog
      v-loading="loading"
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      :title="curObj.id ? '编辑成交进度' : '更新成交进度'"
      :fullscreen="false"
      width="330px"
      custom-class="xl-dialog"
      center
    >
      <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="90px">
        <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>
        </div>
      </base-form>
    </el-dialog>
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
export default {
  components: { },
  mixins,
  props: {
    isShow: Boolean,
    curObj: Object,
    pObj: Object,
  },
  inject: ['parentData'],
  data() {
    return {
      formData: [],
      loading: true,
      cObj: {},
      curEstateObj: {},
    }
  },
  computed: {},
  watch: {
    isShow: function(val) {
      if (val) {
        this.getDef()
      }
    },
  },
  methods: {
    getDef() {
      let params = { ...this.curObj }
      this.formData = [
        { label: '佣金到款日', key: 'info1', type: 'datePicker', type2: 'date'},
        { label: '回款比例', key: 'info2', type: 'inputFont', appendFont: '%' },
        { label: '是否开票', key: 'info3', type: 'select', options: this.$dictData.sys_yesno },
        { label: '上传凭证', key: 'info4', type: 'uploads'},
        { label: '备注', key: 'remark', 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 }
            let apiStr = 'admtraderecordadd'
            this.$api.cust[apiStr](newForm).then(data => {
              this.$msgs(newForm.id ? '编辑成功' : '新增成功')
              this.$emit('close', newForm)
            })
          }
        })
      } else {
        this.$emit('close')
        this.setDefaultValue()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.scoped-tips {
  padding-bottom: 6px;
  text-align: center;
  .t {
    font-size: 18px;
    font-weight: bold;
    color: #0c78b1;
  }
}
</style>
