<template>
  <div>
    <el-dialog
      v-loading="loading"
      :show-close="false"
      :close-on-click-modal="false"
      :visible.sync="isShow"
      :title="this.curObj && this.curObj.id ? '编辑积分' : '添加积分'"
      :fullscreen="false"
      width="470px"
      custom-class="xl-dialog"
      center
    >
      <base-form ref="ruleForm" :data="formData" :is-inline="false" label-width="110px">
        <div slot="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>
      </base-form>
    </el-dialog>
  </div>
</template>
<script>
export default {
  components: {},
  mixins: [...mixins],
  props: {
    isShow: Boolean,
    curObj: Object
  },
  inject: ['parentData'],
  data() {
    return {
      formData: [],
      loading: true,
      cObj: {},
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        this.getDef()
      }
    },
  },
  methods: {
    getDef() {
      const params = { ...this.curObj }
      this.formData = [
        { label: '成长值', key: 'point', rules: 1 },
        { label: '备注', key: 'remark', 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
            let newForm = { ...oldform }
            let apiStr = 'admwechatuserintegraledit'
            if (this.curObj.id) {
              apiStr = 'admwechatuserintegraledit'
              newForm.id = this.curObj.id
            }
            this.$api.user[apiStr](newForm).then(data => {
              this.$msgs(this.curObj.id ? '编辑成功' : '新增成功')
              this.$emit('close', newForm)
            })
          }
        })
      } else {
        this.$emit('close')
        this.setDefaultValue()
      }
    },
  }
}
</script>
<style lang="scss" scoped>
</style>
