<template>
  <div v-loading="loading">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="发货总单数" prop="date">
            <el-input v-model="ruleForm.F_SendTotleNumber" placeholder="请输入发货总单数" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发货总金额" prop="date">
            <el-input v-model="ruleForm.F_TotleMoney" placeholder="请输入发货总金额" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="签收总单数" prop="date">
            <el-input v-model="ruleForm.F_SignNumber" placeholder="请输入签收总单数" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="签收总金额" prop="date">
            <el-input v-model="ruleForm.F_SignMoney" placeholder="请输入签收总金额" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="未签收单数" prop="date">
            <el-input v-model="ruleForm.F_NoSignNumber" placeholder="请输入未签收单数" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="未签收金额" prop="date">
            <el-input v-model="ruleForm.F_NoSignMoney" placeholder="请输入未签收金额" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="拒收单数" prop="date">
            <el-input v-model="ruleForm.F_RefuseNumber" placeholder="请输入拒收单数" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="拒收金额" prop="date">
            <el-input v-model="ruleForm.F_RefuseMoney" placeholder="请输入拒收金额" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="录错金额" prop="date">
            <el-input v-model="ruleForm.F_ErrorMoney" placeholder="请输入录错金额" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="补签收金额" prop="date">
            <el-input v-model.number="ruleForm.F_ErrorMoney" placeholder="请输入补签收金额" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="售后退款" prop="date">
            <el-input v-model.number="ruleForm.F_AfterMoney" placeholder="请输入售后退款" type="number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="特殊金额" prop="date">
            <el-input v-model="ruleForm.F_AlongMoney" placeholder="请输入特殊金额" onkeyup="value=value.replace(/[^\d.]/g,'')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item>
            <el-button type="primary" @click="submitForm">保存</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import {
  editTeamPerformance,
  getTeamPerformanceDetail,
} from "@/api/reportFormManagement/teamPerformance/teamPerformance";
import { filterContent } from "@/utils";

export default {
  name: "AddOrEdit",
  props: {
    rowid: {
      type: String,
      default: "",
    },
    layerid: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      ruleForm: {
        F_Id: "",
        F_SendTotleNumber: 0,
        F_TotleMoney: 0,
        F_SignNumber: 0,
        F_SignMoney: 0,
        F_NoSignNumber: 0,
        F_NoSignMoney: 0,
        F_RefuseNumber: 0,
        F_RefuseMoney: 0,
        F_ErrorMoney: 0,
        F_AfterMoney: 0,
        F_AlongMoney: 0,
      },
      rules: {
      },
      loading: false,
    };
  },
  created() {
    if (this.rowid) {
      this.ruleForm.F_Id = this.rowid;
      this.getDetail(this.rowid);
    }
  },
  methods: {
    submitForm() {
      console.log(JSON.stringify(this.ruleForm))
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          // 编辑
          editTeamPerformance(this.ruleForm)
            .then((response) => {
              this.loading = false;
              if (response.state.toLowerCase() === "success") {
                this.$parent.$layer.close(this.layerid);
                this.$parent.getList(); // 重新加载父级数据
                this.$message.success("恭喜你，团队绩效编辑成功!");
              }
            })
            .catch(() => {
              this.loading = false;
            });
        } else {
          this.$message.error("请输入有效的必填项信息!");
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
    // 获取详情
    getDetail(rid) {
      getTeamPerformanceDetail(rid).then((response) => {
        if (response.state.toLowerCase() === "success") {
          const res = response.data;
          this.ruleForm = res
          // this.ruleForm.F_SendTotleNumber = res.F_SendTotleNumber;
          // this.ruleForm.F_TotleMoney = res.F_TotleMoney;
          // this.ruleForm.F_SignNumber = res.F_SignNumber;
          // this.ruleForm.F_SignMoney = res.F_SignMoney;
          // this.ruleForm.F_NoSignNumber = res.F_NoSignNumber;
          // this.ruleForm.F_NoSignMoney = res.F_NoSignMoney;
          // this.ruleForm.F_RefuseNumber = res.F_RefuseNumber;
          // this.ruleForm.F_RefuseMoney = res.F_RefuseMoney;
          // this.ruleForm.F_ErrorMoney = res.F_ErrorMoney;
          // this.ruleForm.F_AfterMoney = res.F_AfterMoney;
          // this.ruleForm.F_AlongMoney = res.F_AlongMoney;
        }
      });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.date_picker {
  width: 100%;
}
div.date_picker input.el-range-input {
  width: 46%;
}
</style>
