<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="283" 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="addclick(scope.row.saleOrderMaterialId)"
            type="text"
            size="mini"
            >新增车次物资信息</el-button
          >
          <el-button
            @click="editclick(scope.row.saleOrderMaterialId)"
            type="text"
            size="mini"
            >修改</el-button
          >
          <el-button
            type="text"
            size="mini"
            @click="deleteclick(scope.row.saleOrderMaterialId)"
            >删除</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/getSaleOrderDetail?apiId=231&saleOrderId=" +
          this.$route.params.saleOrderId,
      },
    };
  },
  methods: {
    // 新增
    makeSure() {
      let amsSaleOrderMaterial = {
        saleOrderId: this.$route.params.saleOrderId,
        saleShippingAddressId: this.form.saleShippingAddressId,
        saleDateOfReceipt: sjTime(this.form.saleDateOfReceipt),
        saleOrderConsignee: this.form.saleOrderConsignee,
        saleOrderConsigneeTel: this.form.saleOrderConsigneeTel,
      };
      if (
        amsSaleOrderMaterial.saleShippingAddressId == null ||
        amsSaleOrderMaterial.saleDateOfReceipt == null ||
        amsSaleOrderMaterial.saleOrderConsignee == null ||
        amsSaleOrderMaterial.saleOrderConsigneeTel == null
      )
        this.$message.error("存在空值！");
      else
        this.axios
          .post(
            "/api/v1/ams/addAmsSaleOrderMaterial",
            amsSaleOrderMaterial
          )
          .then((res) => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
              this.$router.go(0);
            } else {
              this.$message.error("新增失败！");
            }
            this.$refs["table"].resetField();
          });
    },
    //新增车次物资信息
    addclick(saleOrderMaterialId){
      this.$router.push("/addTruckNoDetail/" + saleOrderMaterialId);
    },
    //修改
    editclick(saleOrderMaterialId) {
      this.$router.push("/editSaleOrderDetail/" + saleOrderMaterialId);
    },
    //删除
    deleteclick(scope) {
      let saleOrderMaterialId = scope;
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.axios
            .post(
              "/api/v1/ams/deleteAmsSaleOrderMaterialBySaleOrderMaterialId?saleOrderMaterialId=" +
                saleOrderMaterialId
            )
            .then(() => {
              this.$router.go(0);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消删除!",
          });
        });
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>
.form-box,
.from {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 5px;
  margin-bottom: 20px;
}
.button-box{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 0.3125rem;
  margin-bottom: 1.25rem;
}
</style>