<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="291" 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.trucknoMaterialId)"
            type="text"
            size="mini"
            >修改</el-button
          >
          <el-button
            type="text"
            size="mini"
            @click="deleteclick(scope.row.trucknoMaterialId)"
            >删除</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/getTruckNoDetail?apiId=229&saleOrderMaterialId=" +
          this.$route.params.saleOrderMaterialId,
      },
    };
  },
  methods: {
    // 新增
    makeSure() {
      let amsSaleTrucknoMaterial = {
        saleOrderMaterialId: this.$route.params.saleOrderMaterialId,
        materialId: this.form.materialId,
        saleOrderMaterialNumber: this.form.saleOrderMaterialNumber,
        materialTheoreticalWeight: this.form.materialTheoreticalWeight,
      };
      if (
        amsSaleTrucknoMaterial.materialId == null ||
        amsSaleTrucknoMaterial.saleOrderMaterialNumber == null ||
        amsSaleTrucknoMaterial.materialTheoreticalWeight == null
      )
        this.$message.error("存在空值！");
      else
        this.axios
          .post(
            "/api/v1/ams/addAmsSaleTrucknoMaterial",
            amsSaleTrucknoMaterial
          )
          .then((res) => {
            if (res.data.code == 200&& res.data.data!=0) {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
              this.$router.go(0);
            } else {
              this.$message.error("物资件数超过该片区销售计划物资件数，新增失败！");
            }
            this.$refs["table"].resetField();
          });
    },
    //修改
    editclick(trucknoMaterialId) {
      this.$router.push("/editTruckNoDetail/" + trucknoMaterialId);
    },
    //删除
    deleteclick(scope) {
      let trucknoMaterialId = scope;
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.axios
            .post(
              "/api/v1/ams/deleteAmsSaleTrucknoMaterial?trucknoMaterialId=" +
                trucknoMaterialId
            )
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>

</style>