<template>
  <!-- 销售订单详细页面 -->
  <div class="salePlan">
    <div class="main">
      <span class="text">新增销售计划物资信息</span>
      <span class="a"></span>
    </div>
    <!-- <div>
      <div class="form-box" style="margin-left: 5rem">
        <el-form><dil-form :formId="289" v-model="form"></dil-form></el-form>
      </div>
    </div>
    <div class="button-ins">
      <el-button type="primary" @click="makeSure">确定添加</el-button>
    </div> -->

    <dilTable v-bind.sync="option">
      <el-table-column fixed="right" label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button
            @click="editclick(scope.row.planMaterialId)"
            type="text"
            size="mini"
            >修改</el-button
          >
          <el-button
            type="text"
            size="mini"
            @click="deleteclick(scope.row.planMaterialId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </dilTable>
    <div class="button-box">
      <el-button @click="onClickCancel">返回</el-button>
    </div>
  </div>
</template>


<script>

export default {
  name: "salePlan",
  data() {
    return {
      option: {
        // 表格请求数据的地址
        requestUrl:
          "/api/v1/ams/getSalePlanMaterialInfo?apiId=228&planId=" +
          this.$route.params.planId,
      },
    };
  },
  methods: {
    // 新增
    makeSure() {
      let amsSalePlanMaterial = {
        salePlanId: this.$route.params.planId,
        materialId: this.form.materialId,
        materialNumber: this.form.materialNumber,
      };
      if (
        amsSalePlanMaterial.materialId == null ||
        amsSalePlanMaterial.materialNumber == null
      )
        this.$message.error("存在空值！");
      else
        this.axios
          .post(
            "/api/v1/ams/addAmsSalePlanMaterial",
            amsSalePlanMaterial
          )
          .then((res) => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
              this.$router.go(0);
            } else {
              this.$message.error("新增失败！");
            }
            this.$refs["table"].resetField();
          });
    },
    //修改
    editclick(planMaterialId) {
      this.$router.push("/editSalePalnDetail/" + planMaterialId);
    },
    //删除
    deleteclick(scope) {
      let planMaterialId = scope;
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.axios
            .post(
              "/api/v1/ams/deleteAmsSalePlanMaterial?planMaterialId=" +
                planMaterialId
            )
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>

</style>