<template>
  <el-dialog
    title="调价"
    :visible.sync="controlWindows.adjust"
    width="30%"
    :before-close="closeWindow"
    @opened="openDrawer"
  >
    <div class="adjust">
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">
        <el-form-item label="成本价" prop="floorPrice">
          <el-input
            maxlength="50"
            v-checkNum
            v-model="form.floorPrice"
            placeholder="请输入成本价"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业销售价" prop="salePrice2company">
          <el-input
            maxlength="50"
            v-checkNum
            v-model="form.salePrice2company"
            placeholder="请输入企业销售价"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeWindow">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import serve from "api/product.js";

export default {
  props: {
    controlWindows: Object,
  },
  data() {
    return {
      form: {},
      rules: {
        floorPrice: [
          { required: true, message: "请输入成本价", trigger: "blur" },
        ],
        salePrice2company: [
          { required: true, message: "请输入企业销售价", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    openDrawer() {},
    submit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          Object.assign(this.form, this.controlWindows.addInfo);
          serve.modifyPrice(this.form).then((res) => {
            this.$message.success(res.msg);
            this.closeWindow();
          });
        }
      });
    },
    closeWindow() {
      this.$emit("closeWindow");
      this.form = {};
      this.$nextTick(() => {
        this.$refs.form.clearValidate();
        this.controlWindows.adjust = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.adjust {
  .el-input {
    width: 200px;
  }
}
</style>
