<template>
  <el-dialog title="调整成本费用" :visible.sync="dialogVisible" width="500px" @close="cancelSubmit()">
    <div v-loading="loading">
      <el-input-number v-model="updateCostData.costPrice" precision="2" :min="0" :max="999999.99"  style="width:400px"></el-input-number>
      <el-input type="textarea" :rows="3" placeholder="请填入调整备注" v-model="updateCostData.textarea" :maxlength="240" show-word-limit></el-input>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelSubmit()">取消</el-button>
      <el-button type="primary" @click="submitProNanme()">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import request from '../service/request.js';
import api from '@/api/gift.js';
const { realCostUpdate } = api;
export default {
  props: {
    updateCostData: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      loading: false
    };
  },
  mounted() {
    this.dialogVisible = true;
  },
  methods: {
    submitProNanme() {
      if(this.loading) return;
      if(!this.updateCostData.costPrice){
        this.$message.error('请完善成本');
      }
      if(!this.updateCostData.textarea){
        this.$message.error('请完善备注');
      }
      this.loading = true;
      let params = {
        giftId: this.updateCostData.id,
        costPrice: this.updateCostData.costPrice,
        remark: this.updateCostData.textarea
      };
      realCostUpdate(params).then(res => {
        if(res.code === '000'){
          this.dialogVisible = false;
          setInterval(() => {
            this.$emit('closeUpdateCost');
          }, 10);
          this.$message.success('修改成功');
        }else{
          this.$message.error(res.message);
        }
      }).finally(() => this.loading = false);
    },
    // 取消修改
    cancelSubmit() {
      this.dialogVisible = false;
      setInterval(() => {
        this.$emit('closeUpdateCost');
      }, 10);
    }
  }
};
</script>
<style scoped></style>
