大大的豆芽 hai 3 meses
pai
achega
77b1155b47
Modificáronse 1 ficheiros con 90 adicións e 25 borrados
  1. 90 25
      src/views/goods/commonGoods/index.vue

+ 90 - 25
src/views/goods/commonGoods/index.vue

@@ -129,24 +129,30 @@
                     <!-- 规格设置 tab -->
                     <el-tab-pane label="规格设置" name="sku">
                         <el-form-item label="规格类型">
-                            <el-radio-group v-model="skuType" @change="handleSkuTypeChange">
+                            <el-radio-group v-model="form.skuType" @change="handleSkuTypeChange">
                                 <el-radio :label="0">单规格</el-radio>
                                 <el-radio :label="1">多规格</el-radio>
                             </el-radio-group>
                         </el-form-item>
 
                         <!-- 单规格设置 -->
-                        <template v-if="skuType === 0">
+                        <template v-if="form.skuType === 0">
                             <el-form-item label="销售价格" prop="singleSkuPrice">
                                 <el-input-number v-model="form.singleSkuPrice" :precision="2" :step="0.1" :min="0" />
                             </el-form-item>
+                            <el-form-item label="批发价格" prop="singleSkuWholesalePrice">
+                                <el-input-number v-model="form.singleSkuWholesalePrice" :precision="2" :step="0.1" :min="0" />
+                            </el-form-item>
+                            <el-form-item label="进货价格" prop="singleSkuPurchasePrice">
+                                <el-input-number v-model="form.singleSkuPurchasePrice" :precision="2" :step="0.1" :min="0" />
+                            </el-form-item>
                             <el-form-item label="库存数量" prop="singleSkuStock">
                                 <el-input-number v-model="form.singleSkuStock" :min="0" :step="1" />
                             </el-form-item>
                         </template>
 
                         <!-- 多规格设置 -->
-                        <template v-if="skuType === 1">
+                        <template v-if="form.skuType === 1">
                             <!-- 规格项设置 -->
                             <div class="spec-group" v-for="(spec, index) in form.specList" :key="index">
                                 <el-row :gutter="10">
@@ -159,22 +165,22 @@
                                         <el-form-item label="规格值">
                                             <el-tag
                                                 :key="tag"
-                                                v-for="tag in spec.values"
+                                                v-for="tag in spec.specValues"
                                                 closable
                                                 :disable-transitions="false"
-                                                @close="handleRemoveSpecValue(spec.values, tag)">
+                                                @close="handleRemoveSpecValue(spec.specValues, tag)">
                                                 {{tag}}
                                             </el-tag>
                                             <el-input
                                                 class="input-new-tag"
                                                 v-if="spec.inputVisible"
                                                 v-model="spec.inputValue"
-                                                ref="saveTagInput"
+                                                :ref="'saveTagInput' + index"
                                                 size="small"
-                                                @keyup.enter.native="handleInputConfirm(spec)"
-                                                @blur="handleInputConfirm(spec)">
+                                                @keyup.enter.native="handleInputConfirm(spec, index)"
+                                                @blur="handleInputConfirm(spec, index)">
                                             </el-input>
-                                            <el-button v-else class="button-new-tag" size="small" @click="showInput(spec)">
+                                            <el-button v-else class="button-new-tag" size="small" @click="showInput(spec, index)">
                                                 + 添加规格值
                                             </el-button>
                                         </el-form-item>
@@ -195,13 +201,35 @@
                                     :label="spec.name"
                                     align="center">
                                     <template slot-scope="scope">
-                                        {{scope.row.specs[index]}}
+                                        {{scope.row.specValLists[index]}}
                                     </template>
                                 </el-table-column>
                                 <el-table-column label="销售价格" align="center" width="150">
                                     <template slot-scope="scope">
                                         <el-input-number 
-                                            v-model="scope.row.price" 
+                                            v-model="scope.row.salePrice" 
+                                            :precision="2" 
+                                            :step="0.1"
+                                            :min="0"
+                                            controls-position="right"
+                                            size="mini" />
+                                    </template>
+                                </el-table-column>
+                                <el-table-column label="批发价格" align="center" width="150">
+                                    <template slot-scope="scope">
+                                        <el-input-number 
+                                            v-model="scope.row.wholesalePrice" 
+                                            :precision="2" 
+                                            :step="0.1"
+                                            :min="0"
+                                            controls-position="right"
+                                            size="mini" />
+                                    </template>
+                                </el-table-column>
+                                <el-table-column label="进货价格" align="center" width="150">
+                                    <template slot-scope="scope">
+                                        <el-input-number 
+                                            v-model="scope.row.purchasePrice" 
                                             :precision="2" 
                                             :step="0.1"
                                             :min="0"
@@ -260,6 +288,7 @@
 import { listGoods, getGoods, delGoods, addGoods, updateGoods, updateGoodsStatus } from '@/api/core/goods'
 import { listCategory } from '@/api/core/category'
 import { listBrand } from '@/api/core/brand'
+import { status } from 'nprogress'
 
 export default {
     name: 'appGoods',
@@ -323,9 +352,14 @@ export default {
                 updateById: null,
                 updateTime: null,
                 remark: null,
+                skuType: 0,
+                status: '0',
                 specList: [],
                 skuList: [],
+                sort: '0',
                 singleSkuPrice: 0,
+                singleSkuWholesalePrice: 0,
+                singleSkuPurchasePrice: 0,
                 singleSkuStock: 0
             },
             // 表单校验
@@ -454,6 +488,7 @@ export default {
         reset() {
             this.form = {
                 id: null,
+                goodsType: this.goodsType,
                 goodsName: null,
                 goodsCategoryId: null,
                 goodsSynopsis: null,
@@ -462,6 +497,7 @@ export default {
                 goodsImgs: [],
                 goodsCode: null,
                 isSell: 'N',
+                skuType: 0,
                 isCashPay: 'Y',
                 cashMoney: null,
                 isBalancePay: 'Y',
@@ -472,9 +508,13 @@ export default {
                 updateById: null,
                 updateTime: null,
                 remark: null,
+                status: '0',
+                sort: '0',
                 specList: [],
                 skuList: [],
                 singleSkuPrice: 0,
+                singleSkuWholesalePrice: 0,
+                singleSkuPurchasePrice: 0,
                 singleSkuStock: 0
             }
             this.resetForm('form')
@@ -527,10 +567,12 @@ export default {
                     const formData = { ...this.form }
                     
                     // 处理SKU数据
-                    if (this.skuType === 0) {
+                    if (this.form.skuType === 0) {
                         formData.skuList = [{
-                            specs: [],
-                            price: this.form.singleSkuPrice,
+                            specValLists: [],
+                            salePrice: this.form.singleSkuPrice,
+                            wholesalePrice: this.form.singleSkuWholesalePrice,
+                            purchasePrice: this.form.singleSkuPurchasePrice,
                             stock: this.form.singleSkuStock
                         }]
                     } else {
@@ -676,9 +718,12 @@ export default {
             }
         },
         addSpec() {
+            if (!this.form.specList) {
+                this.form.specList = []
+            }
             this.form.specList.push({
                 name: '',
-                values: [],
+                specValues: [],
                 inputVisible: false,
                 inputValue: ''
             })
@@ -695,16 +740,19 @@ export default {
                 this.generateSkuList()
             })
         },
-        showInput(spec) {
+        showInput(spec, index) {
             spec.inputVisible = true
             this.$nextTick(_ => {
-                this.$refs.saveTagInput.$refs.input.focus()
+                this.$refs['saveTagInput' + index][0].$refs.input.focus()
             })
         },
-        handleInputConfirm(spec) {
+        handleInputConfirm(spec, index) {
             let inputValue = spec.inputValue
-            if (inputValue && spec.values.indexOf(inputValue) === -1) {
-                spec.values.push(inputValue)
+            if (inputValue && spec.specValues.indexOf(inputValue) === -1) {
+                if (!spec.specValues) {
+                    spec.specValues = []
+                }
+                spec.specValues.push(inputValue)
                 this.$nextTick(() => {
                     this.generateSkuList()
                 })
@@ -714,13 +762,13 @@ export default {
         },
         generateSkuList() {
             const specs = this.form.specList
-            if (specs.length === 0 || specs.some(spec => spec.values.length === 0)) {
+            if (specs.length === 0 || specs.some(spec => spec.specValues.length === 0)) {
                 this.form.skuList = []
                 return
             }
             
             // 获取所有规格值的组合
-            const values = specs.map(spec => spec.values)
+            const values = specs.map(spec => spec.specValues)
             const combinations = this.cartesianProduct(values)
             
             // 保存现有的价格和库存数据
@@ -730,12 +778,14 @@ export default {
             this.form.skuList = combinations.map(specs => {
                 // 查找是否存在相同规格的旧数据
                 const existingSku = existingSkus.find(old => 
-                    JSON.stringify(old.specs) === JSON.stringify(specs)
+                    JSON.stringify(old.specValLists) === JSON.stringify(specs)
                 )
                 
                 return {
-                    specs,
-                    price: existingSku ? existingSku.price : 0,
+                    specValLists: specs,
+                    salePrice: existingSku ? existingSku.salePrice : 0,
+                    wholesalePrice: existingSku ? existingSku.wholesalePrice : 0,
+                    purchasePrice: existingSku ? existingSku.purchasePrice : 0,
                     stock: existingSku ? existingSku.stock : 0
                 }
             })
@@ -748,6 +798,21 @@ export default {
                     })
                 }).flat()
             }, [[]])
+        },
+        /**
+         * @description 添加规格值
+         * @param {number} index 规格索引
+         */
+        addSpecValue(index) {
+            // 确保规格值数组已初始化
+            if (!this.form.specList[index].specValueList) {
+                this.$set(this.form.specList[index], 'specValueList', [])
+            }
+            
+            this.form.specList[index].specValueList.push({
+                specValue: '',
+                image: ''
+            })
         }
     }
 }