<template>
  <el-dialog
    :title="!dataForm.assistRecordId ? this.$i18n.t('crud.addTitle') : this.$i18n.t('temp.modify')"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="助力产品" prop="assistName">
        <el-input v-model="dataForm.assistName" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="dataForm.nickName" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="助力电量" prop="assistPower">
        <el-input v-model="dataForm.assistPower" :disabled="true"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button class="default-btn" @click="visible = false">{{$t("crud.filter.cancelBtn")}}</el-button>
      <el-button class="default-btn primary-btn" type="primary" @click="dataFormSubmit()">{{$t("crud.filter.submitBtn")}}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        assistName: null,
        nickName: null,
        assistPower: null,
        createTime: null,
      },
      dataRule: {
      }
    }
  },
  methods: {
    init (assistRecordId) {
      this.dataForm.assistRecordId = assistRecordId || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.assistRecordId) {
          this.$http({
            url: this.$http.adornUrl('/assist/prodAssistRecord/info/' + this.dataForm.assistRecordId),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            this.dataForm = data
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/assist/prodAssistRecord'),
            method: this.dataForm.assistRecordId ? 'put' : 'post',
            data: this.$http.adornData(this.dataForm)
          }).then(({data}) => {
            this.$message({
              message: this.$i18n.t('publics.operation'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          })
        }
      })
    }
  }
}
</script>
