haoxuan
2023-08-28 40acca0d395e1271522fc2695b37065697021d7d
src/views/supplierManage/supplier/AddNewProduct.vue
@@ -15,10 +15,12 @@
        <div class="basic-info-view">
          <CommonFormTableView
            :product-table-list="productTableList"
            :detail-enter="detailEnter"
            @inputContent="inputContent"
            @addProductClick="addProductClick"
            @emptyProductClick="emptyProductClick"
            @clearupProduct="clearupProduct"
            @selCommonName="selCommonName"
          />
        </div>
      </div>
@@ -31,7 +33,7 @@
</template>
<script>
// import { createProduct, updateProduct } from "@/api/productManage/product"
import { createProduct, updateProduct } from "@/api/productManage/product"
import CommonFormTableView from "@/components/makepager/CommonFormTableView"
export default {
  name: "AddNewProduct",
@@ -56,7 +58,9 @@
      productTableList: {},
      tableData: [],
      productId: 1,
      isNoProduct: true
      isNoProduct: true,
      supplierId: this.addCommonConfig.infomation.supplierId,
      detailEnter: true
    }
  },
  created() {
@@ -72,49 +76,52 @@
    // 保存
    saveClick() {
      console.log(this.editConfig.infomation)
      const params = this.saveParams()
      console.log(params)
      if (this.editConfig.title === "添加") {
        // createProduct(params).then((res) => {
        //   console.log(res)
        //   this.editConfig.visible = false
        //   if (res.code === 200) {
        //     this.$message.success("添加成功")
        //     this.$parent.getData()
        //   }
        // })
        createProduct({
          list: this.tableData
        }).then((res) => {
          console.log(res)
          this.editConfig.visible = false
          if (res.code === 200) {
            this.$message.success("添加成功")
            this.$parent.getProductList()
          }
        })
      } else {
        // updateProduct(params).then((res) => {
        //   console.log(res)
        //   this.editConfig.visible = false
        //   if (res.code === 200) {
        //     this.$message.success("编辑成功")
        //     this.$parent.getData()
        //   }
        // })
        const params = this.saveParams()
        updateProduct(params).then((res) => {
          console.log(res)
          this.editConfig.visible = false
          if (res.code === 200) {
            this.$message.success("编辑成功")
            this.$parent.getProductList()
          }
        })
      }
    },
    saveParams() {
      // let data = this.editConfig.infomation
      let data = this.editConfig.infomation
      let params = {
        deliveryTime: 0,
        id: 0,
        maximumStock: 0,
        minimumStock: 0,
        name: "string",
        number: "string",
        productType: "string",
        purchasePrice: 0,
        remark: "string",
        shippingDuration: 0,
        specifications: "string",
        supplierId: 0,
        unit: "string"
        deliveryTime: data.deliveryTime || 0,
        id: data.ID || 0,
        maximumStock: data.maximumStock || 0,
        minimumStock: data.minimumStock || 0,
        modelNumber: data.modelNumber || "",
        name: data.name || "",
        number: data.number || "",
        productType: data.productType || "",
        purchasePrice: data.purchasePrice || 0,
        remark: data.remark || "",
        shippingDuration: data.shippingDuration || 0,
        specifications: data.specifications || "",
        supplierId: this.supplierId || 0,
        unit: data.unit || ""
      }
      return params
    },
    setTableForm() {
      if (this.editConfig.title === "添加" || this.editConfig.infomation.products.length === 0) {
      if (this.editConfig.title === "添加") {
        this.detailEnter = false
        this.tableData = [
          {
            productId: this.productId,
@@ -124,14 +131,13 @@
            name: "",
            number: "",
            price: 0,
            total: 0
            total: 0,
            supplierId: this.supplierId
          }
        ]
      } else {
        this.tableData = this.editConfig.infomation.products
        this.tableData.map((item, index) => {
          item.productId = index + 1
        })
        this.tableData = [{ ...this.editConfig.infomation }]
        this.detailEnter = true
      }
      this.productTableList = {
        tableData: this.tableData,
@@ -152,6 +158,7 @@
      this.tableData.map((item) => {
        if (item.productId === row.productId) {
          item[prop] = val
          item.supplierId = this.supplierId
        }
      })
    },
@@ -166,7 +173,8 @@
        name: "",
        number: "",
        price: 0,
        total: 0
        total: 0,
        supplierId: this.supplierId
      })
    },
    //  产品清空
@@ -181,7 +189,8 @@
          name: "",
          number: "",
          price: 0,
          total: 0
          total: 0,
          supplierId: this.supplierId
        }
      ]
      this.productTableList.tableData = this.tableData
@@ -190,6 +199,11 @@
    clearupProduct(data) {
      this.tableData = data
      this.productTableList.tableData = this.tableData
    },
    selCommonName(row) {
      console.log("1133")
      console.log(row)
      this.editConfig.infomation = row
    }
  }
}