Bladeren bron

采购优惠券 采购商品

lsx 2 jaren geleden
bovenliggende
commit
7ff088b7fa

+ 9 - 0
src/api/business/coupon.js

@@ -42,3 +42,12 @@ export function setCouponStatus(data) {
     data
   })
 }
+
+//获取全部优惠券 不分页
+export function getCouponAllList(data) {
+  return request({
+    url: '/api/v1/mp/admin/coupon/list',
+    method: 'post',
+    data
+  })
+}

+ 17 - 6
src/views/business/coupon/add.vue

@@ -11,9 +11,10 @@
             <el-radio-group v-model="addData.type" :disabled="readonly || addData.status === 'on' || addData.status === 'off'">
               <el-radio :label="2">门店消费</el-radio>
               <el-radio :label="1">盲票购买</el-radio>
+              <el-radio :label="4">采购商品核销</el-radio>
             </el-radio-group>
           </el-form-item>
-          <el-form-item v-if="addData.type === 1" label="是否新用户注册发放:">
+          <el-form-item v-if="addData.type != 2 && addData.type != 4" label="是否新用户注册发放:">
             <el-switch :disabled="readonly" v-model="addData.isNewUserCoupon" :active-value="1" :inactive-value="0" />
           </el-form-item>
           <el-form-item label="券金额:" prop="discount">
@@ -29,14 +30,14 @@
           <!-- <el-form-item label="图片:" prop="picUrl">
             <Upload :value="addData.picUrl ? [{ fileName: addData.picUrl }] : []" @input="addData.picUrl = $event[0] ? $event[0].fileName : ''" :limit="1" />
           </el-form-item> -->
-          <el-form-item v-if="addData.type === 2" label="门店默认承担比例:" prop="channelSharedRate">
+          <el-form-item v-if="addData.type != 1" label="门店默认承担比例:" prop="channelSharedRate">
             <el-input v-model="addData.channelSharedRate" :readonly="readonly" type="number" placeholder="请输入门店默认承担比例">
               <template slot="append">%</template>
             </el-input>
             <div class="tip">若门店承担100%,则核销后公司不需要打款给门店,依此类推。</div>
           </el-form-item>
 
-          <el-form-item label="最低消费金额:" prop="minOrderAmt">
+          <el-form-item label="最低消费金额:" v-if="addData.type != 4" prop="minOrderAmt">
             <el-input v-model="addData.minOrderAmt" :readonly="readonly" type="number" placeholder="请输入可使用的最低消费金额">
               <template slot="append">元</template>
             </el-input>
@@ -62,7 +63,7 @@
           <el-form-item label="使用说明:" prop="description">
             <el-input type="textarea" rows="4" :readonly="readonly" v-model="addData.description" placeholder="请输入使用说明 对用户可见" />
           </el-form-item>
-          <el-form-item v-if="addData.type === 2" label="使用范围:" prop="useArea">
+          <el-form-item v-if="addData.type != 1" label="使用范围:" prop="useArea">
             <el-radio-group v-model="addData.useArea" :disabled="readonly || addData.status === 'on' || addData.status === 'off'">
               <el-radio :label="2">进票门店</el-radio>
               <el-radio :label="1">指定门店</el-radio>
@@ -82,7 +83,7 @@
     </el-row>
     <el-row :gutter="18">
       <el-col :span="18" :offset="2">
-        <div v-if="addData.useArea === 1 && addData.type === 1" style="padding: 0 20px">
+        <div v-if="addData.useArea === 1 && addData.type != 2" style="padding: 0 20px">
           <el-table :data="addData.ticketBoxList" height="300px">
             <el-table-column label="盲票ID" prop="boxId" min-width="90" />
             <el-table-column label="盲票图片" prop="picUrl" align="center">
@@ -116,7 +117,7 @@
           <br>
           <el-button v-if="!readonly" type="primary" size="small" plain @click="funSelectShow">选择盲票</el-button> <span style="margin-left: 10px">已选盲票({{ addData.ticketBoxList.length }})</span>
         </div>
-        <div v-if="addData.useArea === 1 && addData.type === 2" style="padding: 0 20px">
+        <div v-if="addData.useArea === 1 && addData.type != 1" style="padding: 0 20px">
           <el-table :data="channelList" height="300px">
             <el-table-column label="门店编号" prop="channelId" min-width="90" />
             <el-table-column label="门店名称" prop="name" />
@@ -279,6 +280,16 @@ export default {
           })
           return
         }
+      } else if (this.addData.type == 4) {
+        this.addData.minOrderAmt = null
+        this.addData.isNewUserCoupon = null
+        if (this.addData.useArea !== 2 && this.addData.useArea !== 0 && this.addData.useArea !== 1) {
+          this.$message({
+            message: '请选择使用范围!',
+            type: 'warning'
+          })
+          return
+        }
       }
       this.$refs.addItem.validate((valid, items) => {
         if (valid) {

+ 1 - 0
src/views/business/coupon/index.vue

@@ -14,6 +14,7 @@
           <el-option label="全部" value="" />
           <el-option label="盲票购买" :value="1" />
           <el-option label="门店消费" :value="2" />
+          <el-option label="采购商品核销" :value="4" />
         </el-select>
       </el-form-item>
       <el-form-item label="是否新用户注册发放">

+ 106 - 10
src/views/business/goods/add.vue

@@ -1,13 +1,14 @@
 <template>
   <div class="app-container goods-add">
     <el-divider content-position="left">商品信息</el-divider>
-    <el-form ref="addItem" :rules="rules" :model="addData" label-width="120px">
+    <el-form ref="addItem" :rules="rules" :model="addData" label-width="130px">
       <el-row :gutter="40" style="width: 500px">
         <el-col :span="23">
           <el-form-item label="商品类型:" prop="type">
-            <el-radio-group v-model="addData.type" :disabled="addData.goodsId ? true : false">
+            <el-radio-group v-model="addData.type" :disabled="addData.goodsId ? true : false" @input="typeChange">
               <el-radio :label="1">实物商品</el-radio>
               <el-radio :label="2">卡密商品</el-radio>
+              <el-radio :label="3">采购商品</el-radio>
             </el-radio-group>
           </el-form-item>
         </el-col>
@@ -36,8 +37,8 @@
             <!--            <div class="tip">关闭则不再兑换大厅显示,不支持盲豆兑换。</div>-->
             <el-radio-group v-model="addData.exchangeShow">
               <el-radio :label="0">不支持</el-radio>
-              <el-radio :label="1">支持</el-radio>
-              <el-radio :label="2">盲票商品</el-radio>
+              <el-radio :label="1" :disabled="addData.type == '3'">支持</el-radio>
+              <el-radio :label="2" :disabled="addData.type == '3'">盲票商品</el-radio>
             </el-radio-group>
           </el-form-item>
         </el-col>
@@ -68,6 +69,27 @@
 
         </el-col>
       </el-row>
+      <el-row :gutter="40" style="width: 600px" v-if="addData.type == '3'">
+        <el-col :span="23">
+          <el-form-item label="关联采购优惠券:" prop="refId">
+            <el-select
+              v-model="addData.refId"
+              placeholder="请选择采购优惠券"
+              filterable
+              clearable>
+              <el-option :label="item.title" :value="item.couponId" v-for="(item, index) in CouponList" :key="index">
+                <div>
+                  <span style="float: left; width: 130px; overflow: hidden; text-overflow: ellipsis;">{{ item.title }} </span>
+                  <span style="float: left; width: 110px; overflow: hidden; text-overflow: ellipsis;">¥{{ $numberFormat(item.discount) }}</span>
+                  <span style="float: right;">{{ item.channelSharedRate }}%</span>
+                </div>
+              </el-option>
+            </el-select>
+            <div class="tip">根据优惠券名称查询(优惠券名称--价格--门店承担比例)</div>
+          </el-form-item>
+        </el-col>
+      </el-row>
+
       <el-row :gutter="40" style="width: 500px">
         <el-col :span="23">
           <el-form-item label="商品采购链接:">
@@ -100,7 +122,7 @@
       <el-divider content-position="left">价格库存</el-divider>
       <el-row>
         <el-col :span="23">
-          <el-form-item label="启用多SKU:" v-if="addData.type == '1'">
+          <el-form-item label="启用多SKU:" v-if="addData.type == '1' || addData.type == '3'">
             <el-switch
               v-model="addData.multiSku"
               :active-value="1"
@@ -110,11 +132,16 @@
         </el-col>
       </el-row>
       <el-row>
-        <el-col :span="22">
+        <el-col :span="22" v-if="addData.type != 3">
           <el-form-item prop="skuList">
             <Spec ref="spec" @valid="update" :multiSku="addData.multiSku"/>
           </el-form-item>
         </el-col>
+        <el-col :span="22" v-else>
+          <el-form-item prop="skuList">
+            <SpeTwo ref="spec" @valid="update" :multiSku="addData.multiSku"/>
+          </el-form-item>
+        </el-col>
       </el-row>
 
       <el-row v-if="addData.multiSku === 0" :gutter="40" style="width: 600px">
@@ -125,6 +152,22 @@
             </el-input>
           </el-form-item>
         </el-col>
+        <el-col :span="23">
+          <el-form-item label="采购成本:" prop="purchaseCost" v-if="addData.type == '3'">
+            <el-input v-model="addData.purchaseCost" type="number" placeholder="请输入采购成本">
+              <template slot="append">元</template>
+            </el-input>
+            <div class="tip">注:指展示给经销商采购的成本,即商品的结算价格</div>
+          </el-form-item>
+        </el-col>
+        <el-col :span="23">
+          <el-form-item label="零售价:" prop="purchasePrice" v-if="addData.type == '3'">
+            <el-input v-model="addData.purchasePrice" type="number" placeholder="请输入零售价">
+              <template slot="append">元</template>
+            </el-input>
+            <div class="tip">注:指商品铺设给经销商的价格,仅作记录</div>
+          </el-form-item>
+        </el-col>
         <el-col :span="23">
           <el-form-item label="盲豆兑换数量:" prop="exchangePrice">
             <el-input v-model="addData.exchangePrice" type="number" placeholder="请输入盲豆数量">
@@ -160,7 +203,7 @@
           </el-form-item>
         </el-col>
         <el-col :span="23">
-          <el-form-item label="库存:" prop="quantity" v-if="addData.type == '1'">
+          <el-form-item label="库存:" prop="quantity" v-if="addData.type == '1' || addData.type == '3'">
             <el-input v-model="addData.quantity" type="number" placeholder="请输入商品库存">
               <template slot="append">件</template>
             </el-input>
@@ -199,8 +242,10 @@
 import Upload from '@/components/DragImageUpload'
 import WangEditor from '@/components/WangEditor'
 import Spec from './components/spec'
+import SpeTwo from './components/spec2'
 import TinyEditor from '@/components/TinyEditor'
 import {getGoodsDetail, addGoods} from '@/api/business/goods'
+import {getCouponAllList} from '@/api/business/coupon'
 import {goodsCategoryListTree} from '@/api/business/category'
 import {getSupplierList} from '@/api/business/supplier'
 import {goodsTagItems} from '@/api/business/tag'
@@ -214,6 +259,7 @@ export default {
     WangEditor,
     Upload,
     Spec,
+    SpeTwo,
     AddSupplier,
   },
   data() {
@@ -222,6 +268,7 @@ export default {
       id: this.$route.query.id,
       goodsCategoryItemsList: [],
       SupplierList: [],
+      CouponList: [],
       goodsTagItemsList: [],
       addData: {
         type: 1,
@@ -238,8 +285,25 @@ export default {
         supplierId: [{required: true, message: '请选择供应商', trigger: 'change'}],
         exchangeShow: [{required: true, message: '请选择是否支持盲豆兑换', trigger: 'change'}],
         multiSku: [{required: true, message: '请选择SKU类型', trigger: 'change'}],
+        refId: [{required: true, message: '请选择关联采购优惠券', trigger: 'change'}],
         value: [
-          {required: true, message: '请输商品入价格', trigger: 'blur'},
+          {required: true, message: '请输入商品价格', trigger: 'blur'},
+          {
+            pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/,
+            message: "请输入正确的金额,最多两位小数",
+            trigger: ["blur", "change"]
+          }
+        ],
+        purchaseCost: [
+        {required: true, message: '请输入采购成本', trigger: 'blur'},
+          {
+            pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/,
+            message: "请输入正确的金额,最多两位小数",
+            trigger: ["blur", "change"]
+          }
+        ],
+        purchasePrice: [
+          {required: true, message: '请输入零售价', trigger: 'blur'},
           {
             pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/,
             message: "请输入正确的金额,最多两位小数",
@@ -273,7 +337,6 @@ export default {
         ],
         description: [{required: true, message: '请输入商品详情', trigger: 'blur'}]
       },
-
     }
   },
   computed: {
@@ -310,6 +373,7 @@ export default {
     this.getGoodsCategoryItems()
     this.getSupplierItems()
     this.getGoodsTagItems()
+    this.getCouponList()
     if (this.id) {
       getGoodsDetail(this.id).then(res => {
         const {
@@ -322,7 +386,10 @@ export default {
           exchangeShow,
           multiSku,
           value,
+          refId,
           exchangePrice,
+          purchaseCost,
+          purchasePrice,
           originPrice,
           discountRate,
           cost,
@@ -337,10 +404,13 @@ export default {
         } = res.data
         this.addData = {
           value: accDiv(value, 100),
+          purchaseCost: type == '3' ? accDiv(purchaseCost, 100) : '',
+          purchasePrice: type == '3' ? accDiv(purchasePrice, 100) : '',
           cost: cost == '' || cost == null ? '' : accDiv(cost, 100),
           goodsId,
           title,
           type,
+          refId: refId ? Number(refId): '',
           goodsCode,
           picUrl,
           merchantInfo,
@@ -370,6 +440,30 @@ export default {
     }
   },
   methods: {
+    typeChange(e) {
+      if(e == 2) {
+        this.addData.quantity = ''
+        this.addData.multiSku = 0
+        this.addData.purchaseCost = ''
+        this.addData.purchasePrice = ''
+        this.addData.refId = ''
+      }else if(e == 1){
+        this.addData.useLink = ''
+        this.addData.purchaseCost = ''
+        this.addData.purchasePrice = ''
+        this.addData.refId = ''
+      }else if(e == 3){
+        this.addData.useLink = ''
+        this.addData.exchangeShow = 0
+      }
+    },
+    // 获取采购优惠券下拉列表
+    getCouponList() {
+      getCouponAllList({type: 4}).then(response => {
+        this.CouponList = response.rows || [];
+      });
+    },
+
     getGoodsCategoryItems() {
       goodsCategoryListTree("", {}).then(res => {
         this.goodsCategoryItemsList = res && res.rows
@@ -405,10 +499,12 @@ export default {
       this.$refs.addItem.validate((valid, items) => {
         if (valid) {
           this.addData.skuList = skuList
-          const {value, categoryId, cost, exchangePrice, description, ...rest} = this.addData
+          const {value, type, categoryId, purchaseCost, purchasePrice, cost, exchangePrice, description, ...rest} = this.addData
           addGoods({
             ...rest, ...{
               value: accMul(value, 100),
+              purchaseCost: type == '3' ? accMul(purchaseCost, 100) : '',
+              purchasePrice: type == '3' ? accMul(purchasePrice, 100) : '',
               cost: cost == '' || cost == null ? '' : accMul(cost, 100),
               exchangePrice: accMul(exchangePrice, 1),
               description: encodeURI(description),

+ 2 - 2
src/views/business/goods/components/spec.vue

@@ -70,14 +70,14 @@
               <el-input v-model="sku.valueY" />
             </el-form-item>
           </td>
-          <td>
+          <td class="pd">
             <el-form-item :prop="`skuList.${index}.exchange`" :rules="exchangeRules">
 <!--              <p>{{ (sku.valueY * 10).toFixed(0) }}</p>-->
               <el-input v-model="sku.exchange" />
             </el-form-item>
           </td>
 <!--          1111111111111111111111-->
-          <td>
+          <td class="pd">
             <el-form-item :prop="`skuList.${index}.discountRate`" :rules="discountRateRules">
               <!--              <p>{{ (sku.valueY * 10).toFixed(0) }}</p>-->
               <el-input v-model="sku.discountRate" />

+ 399 - 0
src/views/business/goods/components/spec2.vue

@@ -0,0 +1,399 @@
+<template>
+  <div v-if="multiSku === 1" style="padding: 16px 0px">
+    <el-form ref="spec" :model="{ specList }" :inline="false" label-width="80px" @submit.native.prevent>
+      <div v-for="(spec, index) in specList" :key="index" style="margin-bottom: 20px">
+        <el-row style="margin-bottom: 10px">
+          <el-col :span="8">
+            <el-form-item :label="`规格项${index + 1}`" :prop="`specList.${index}.name`" :rules="{ required: true, message: '请输入规格名称', trigger: 'blur' }">
+              <el-input v-model="spec.name" :disabled="!spec.edit" @keyup.enter.native="checkSpecName(spec)" />
+            </el-form-item>
+          </el-col>
+          <el-col :span="16">
+            <el-button v-if="spec.edit" type="text" style="margin-left: 10px" @click="checkSpecName(spec)">确定</el-button>
+            <template v-else>
+              <el-button type="text" style="margin-left: 10px" @click="spec.edit = true">编辑</el-button>
+              <el-button type="text" class="del" style="margin-left: 10px" @click="specList.splice(index, 1)">删除</el-button>
+            </template>
+          </el-col>
+        </el-row>
+        <el-row>
+          <el-form-item :prop="`specList.${index}.vals`">
+            <el-col :span="24">
+              <el-tag v-for="(tag, index) in spec.vals" :key="index" closable style="margin-right: 10px" @close="spec.vals.splice(index, 1)">{{ tag }}</el-tag>
+              <el-input v-if="spec.editVals" v-model="specValTmp" v-focus style="display: inline-block;width: 120px; margin-right: 10px" size="mini" @keyup.enter.native="checkSpecVal(spec, `specList.${index}.vals`)" />
+              <el-button v-if="!spec.edit&&!spec.editVals" type="text" style="margin-left: 10px" icon="el-icon-plus" size="small" @click="spec.editVals = true">添加规格值</el-button>
+              <el-button v-if="spec.editVals" type="text" @click="checkSpecVal(spec, `specList.${index}.vals`)">确认</el-button>
+              <el-button v-if="spec.editVals" type="text" @click="spec.editVals = false;specValTmp = ''">取消</el-button>
+            </el-col>
+          </el-form-item>
+        </el-row>
+      </div>
+    </el-form>
+    <el-button type="primary" size="small" plain @click="specList.push({ name: '', vals: [], edit: true, editVals: false })" :disabled="!!specList.find(item => item.edit)" style="margin-bottom: 10px">添加规格</el-button>
+    <el-button type="primary" size="small" style="margin-bottom: 10px;margin-left: 10px" :disabled="specList.length === 0 || !!specList.find(item => item.edit)" @click="genSku">{{ skuList.length > 0 ? '重新生成SKU表格' : '生成SKU表格' }}</el-button>
+    <br>
+    <el-form ref="sku" :model="{ skuList }" :inline="false">
+      <table v-if="skuList instanceof Array && skuList.length > 0" class="spec-table" border="1" bordercolor="#CCC">
+        <tr>
+          <th :colspan="specListTmp.length">商品规格</th>
+          <th rowspan="2" class="required"><span>*</span>SKU主图</th>
+          <th rowspan="2" class="required"><span>*</span>名称</th>
+          <th rowspan="2" class="required"><span>*</span>价格(元)</th>
+          <th rowspan="2" class="required"><span>*</span>采购成本(元)</th>
+          <th rowspan="2" class="required"><span>*</span>零售价(元)</th>
+          <th rowspan="2" class="required"><span>*</span>兑换盲豆数量</th>
+          <th rowspan="2" class="required"><span>*</span>回收折扣(%)</th>
+          <th rowspan="2">盲豆划线价</th>
+          <th rowspan="2">商品成本(元)</th>
+          <th rowspan="2">SKU编码</th>
+          <th rowspan="2" class="required"><span>*</span>库存</th>
+          <th rowspan="2">启用</th>
+        </tr>
+        <tr>
+          <th v-for="(spec, index) in specListTmp" :key="index" style="width: 80px">{{ spec.name }}</th>
+        </tr>
+        <!-- k1:v1;k2:v2 -->
+        <tr v-for="(sku, index) in skuList" :key="index">
+          <td v-for="(spec, i) in specListTmp" :key="i" style="min-width: 50px">
+            {{ formatObj(sku.properties)[spec.name] }}
+          </td>
+          <td>
+            <el-form-item :prop="`skuList.${index}.picUrlArr`" :rules="{ required: true, message: '请上传SKU图片', trigger: ['blur', 'change'] }" style="display:flex ;width: 76px;height: 80px">
+              <Upload v-model="sku.picUrlArr" :limit="1" style="width: 100%" @change="$refs.sku.validateField([`skuList.${index}.picUrlArr`])" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.name`" :rules="{ required: true, message: '名称不能为空', trigger: 'blur' }">
+              <el-input v-model="sku.name" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.valueY`" :rules="valueYRules">
+              <el-input v-model="sku.valueY" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.purchaseCostY`" :rules="purchaseCostYRules">
+              <el-input v-model="sku.purchaseCostY" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.purchasePriceY`" :rules="purchasePriceYRules">
+              <el-input v-model="sku.purchasePriceY" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.exchange`" :rules="exchangeRules">
+<!--              <p>{{ (sku.valueY * 10).toFixed(0) }}</p>-->
+              <el-input v-model="sku.exchange" />
+            </el-form-item>
+          </td>
+<!--          1111111111111111111111-->
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.discountRate`" :rules="discountRateRules">
+              <!--              <p>{{ (sku.valueY * 10).toFixed(0) }}</p>-->
+              <el-input v-model="sku.discountRate" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.originPrice`">
+              <el-input v-model="sku.originPrice" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.costY`" :rules="costYRules">
+              <el-input v-model="sku.costY" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.skuCode`">
+              <el-input v-model="sku.skuCode" />
+            </el-form-item>
+          </td>
+          <td class="pd">
+            <el-form-item :prop="`skuList.${index}.quantity`" :rules="{ required: true, message: '请输入库存', trigger: 'blur' }">
+              <el-input-number style="width: 130px;" v-model="sku.quantity" :min="0" @change="$event === 0 ? sku.status = false : sku.status = true" />
+            </el-form-item>
+          </td>
+          <td style="padding: 0px 10px">
+            <el-form-item :prop="`skuList.${index}.status`">
+              <el-switch v-model="sku.status" active-color="#13ce66" inactive-color="#ff4949" @change="!$event ? sku.quantity = 0 : sku.quantity = 1" />
+            </el-form-item>
+          </td>
+        </tr>
+      </table>
+    </el-form>
+  </div>
+</template>
+<script>
+import Upload from '@/components/ImageUpload'
+import { accMul, accDiv } from '@/utils/util'
+export default {
+  name: 'Spec',
+  components: {
+    Upload
+  },
+  props: {
+    multiSku: {
+      type: Number,
+      default: 0
+    },
+    sku: {
+      type: Array,
+      default: () => []
+    }
+  },
+  data() {
+    return {
+      specList: [],
+      specListTmp: [],
+      skuList: [],
+      specValTmp: '',
+      specifications: [],
+      valueYRules: [
+        { required: true, message: '请输入价格', trigger: 'blur' },
+        { pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的金额,最多两位小数", trigger: ["blur", "change"]}],
+      purchaseCostYRules: [
+        { required: true, message: '请输入采购成本', trigger: 'blur' },
+        { pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的金额,最多两位小数", trigger: ["blur", "change"]}],
+      purchasePriceYRules: [
+        { required: true, message: '请输入零售价', trigger: 'blur' },
+        { pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的金额,最多两位小数", trigger: ["blur", "change"]}],
+      costYRules: [
+        { required: false, message: '请输入商品成本', trigger: 'blur' },
+        { pattern: /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的金额,最多两位小数", trigger: ["blur", "change"] }],
+      exchangeRules: [
+        { required: true,message:'请输入盲豆数量', trigger: 'blur' },
+        { pattern: /^([1-9]\d*)$/, message: "请输入正确的盲豆数量", trigger: ["blur", "change"] }
+      ],
+      discountRateRules: [
+        { required: true,message:'请输入回收折扣', trigger: 'blur' },
+        { pattern: /^([0-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/, message: "请输入正确的折扣,最多两位小数", trigger: ["blur", "change"] }
+      ]
+    }
+  },
+  directives: {
+    focus: {
+      inserted: function (el) {
+        el.querySelector('input').focus()
+      }
+    }
+  },
+  methods: {
+    setSkuList(sku) {
+      let specObj = {}
+      sku.forEach(item => {
+        item.properties.split(';').forEach(p => {
+          const key = p.split(':')[0]
+          // console.log(specObj[key] instanceof Array)
+          if (!specObj[key]) {
+            specObj[key] = []
+            // console.log(specObj[key])
+          }
+          specObj[key].push(p.split(':')[1])
+        })
+      })
+      this.specList = Object.keys(specObj).map(key => {
+        return {
+          name: key,
+          vals: [...new Set(specObj[key])],
+          edit: false,
+          editVals: false
+        }
+      })
+      this.specListTmp = JSON.parse(JSON.stringify(this.specList))
+      this.skuList = sku.map(item => {
+        this.$set(item, 'valueY', accDiv(item.value, 100))
+        this.$set(item, 'purchaseCostY', accDiv(item.purchaseCost,100))
+        this.$set(item, 'purchasePriceY', accDiv(item.purchasePrice,100))
+        this.$set(item, 'exchange', accDiv(item.exchangePrice,1))
+        this.$set(item, 'originPrice', accDiv(item.originPrice,1))
+        this.$set(item, 'discountRate', accDiv(item.discountRate,1))
+        this.$set(item, 'costY', item.cost == null ? '' : accDiv(item.cost, 100) )
+        this.$set(item, 'picUrlArr', item.picUrl.split(',').map(item => { return { fileName: item }}))
+        this.$set(item, 'status', !!item.quantity)
+        return item
+      })
+    },
+    formatObj(properties) {
+      if (properties) {
+        let obj = {}
+        properties.split(';').forEach(item => {
+          obj[item.split(':')[0]] = item.split(':')[1]
+        })
+        return obj
+      }
+      return {}
+    },
+    checkSpecVal(spec, prop) {
+      if (!this.specValTmp) {
+        this.$message.warning('请输入规格值')
+        return
+      }
+      if (spec.vals.find(item => item === this.specValTmp)) {
+        this.$message.warning('规格值已存在')
+        return
+      }
+      spec.vals.push(this.specValTmp)
+      this.specValTmp = ''
+      spec.editVals = false
+      this.$refs.spec.validateField([prop])
+    },
+    checkSpecName(spec) {
+      if (this.specList.filter(item => item.name === spec.name).length > 1) {
+        this.$message.warning('规格名已存在')
+      } else {
+        spec.edit = false
+      }
+    },
+    genSku() {
+      this.$refs.spec.validate((valid, items) => {
+        if (valid) {
+          this.genSkuList()
+        }
+      })
+    },
+    genSkuList() {
+      let specificationsTmp = []
+      this.specList.forEach(spec => {
+        spec.vals.forEach(val => {
+          specificationsTmp.push({
+            specification: spec.name,
+            value: val
+          })
+        })
+      })
+      var specValues = []
+      var spec = specificationsTmp[0].specification
+      var values = []
+      values.push(0)
+
+      for (var i = 1; i < specificationsTmp.length; i++) {
+        const aspec = specificationsTmp[i].specification
+
+        if (aspec === spec) {
+          values.push(i)
+        } else {
+          specValues.push(values)
+          spec = aspec
+          values = []
+          values.push(i)
+        }
+      }
+      specValues.push(values)
+      var productsIndex = 0
+      var skuList = []
+      var combination = []
+      var n = specValues.length
+      for (var s = 0; s < n; s++) {
+        combination[s] = 0
+      }
+      var index = 0
+      var isContinue = false
+      do {
+        var specifications = []
+        var properties = ''
+        for (var x = 0; x < n; x++) {
+          var z = specValues[x][combination[x]]
+          specifications.push(specificationsTmp[z].value)
+          properties = `${properties ? (properties + ';') : ''}${specificationsTmp[z].specification}:${specificationsTmp[z].value}`
+        }
+        skuList[productsIndex] = {
+          idx: productsIndex,
+          name: specifications.toString(),
+          picUrlArr: [],
+          valueY: 0.00,
+          purchaseCostY: 0.00,
+          purchasePriceY: 0.00,
+          costY: '',
+          skuCode:'',
+          originPrice: 0,
+          discountRate: '',
+          quantity: 0,
+          status: true,
+          properties
+        }
+        productsIndex++
+
+        index++
+        combination[n - 1] = index
+        for (var j = n - 1; j >= 0; j--) {
+          if (combination[j] >= specValues[j].length) {
+            combination[j] = 0
+            index = 0
+            if (j - 1 >= 0) {
+              combination[j - 1] = combination[j - 1] + 1
+            }
+          }
+        }
+        isContinue = false
+        for (var p = 0; p < n; p++) {
+          if (combination[p] !== 0) {
+            isContinue = true
+          }
+        }
+      } while (isContinue)
+      this.skuList = skuList
+      this.specListTmp = JSON.parse(JSON.stringify(this.specList))
+    },
+    getSkuList() {
+      if (this.skuList.length === 0) {
+        this.$message.warning('请完善规格并生成sku表格')
+        return false
+      }
+      this.$refs.sku.validate((valid, items) => {
+        if (valid) {
+          this.skuList.forEach(item => {
+            const { valueY,exchange, purchaseCostY,purchasePriceY,costY, originPrice, discountRate } = item
+            item.value = accMul(valueY, 100)
+            item.purchaseCost = accMul(purchaseCostY, 100)
+            item.purchasePrice = accMul(purchasePriceY, 100)
+            item.exchangePrice = accMul(exchange, 1)
+            item.originPrice = accMul(originPrice, 1)
+            item.discountRate = accMul(discountRate, 1)
+            item.cost = costY == '' ? '' : accMul(costY, 100)
+            item.picUrl = item.picUrlArr.map(item => { return item.fileName }).toString()
+          })
+          this.$emit('valid', this.skuList)
+        } else {
+          if (items && Object.keys(items).length>0) {
+            this.$message({
+              message: items[Object.keys(items)[0]][0].message,
+              type: 'warning'
+            })
+          }
+        }
+      })
+    }
+  }
+}
+</script>
+<style lang="scss" scoped>
+.spec-table {
+  border-collapse: collapse;
+  width: 100%;
+  line-height: 32px;
+  color: #606266;
+  font-size: 14px;
+  th {
+    background-color: #ECECEC;
+  }
+  td {
+    text-align: center;
+  }
+  .pd {
+    padding: 10px;
+  }
+  .required {
+    position: relative;
+    span {
+      position: relative;
+      top: -6px;
+      left: 2px;
+      font-size: 10px;
+      color: red;
+    }
+  }
+
+}
+</style>

+ 2 - 0
src/views/business/goods/index.vue

@@ -25,6 +25,7 @@
           <el-option label="全部" value=""/>
           <el-option label="实物商品" value="1"/>
           <el-option label="卡密商品" value="2"/>
+          <el-option label="采购商品" value="3"/>
         </el-select>
       </el-form-item>
       <el-form-item label="商品分类" prop="categoryIdList">
@@ -149,6 +150,7 @@
         <template slot-scope="{row}">
           <span v-if="row.type == '1'">实物商品</span>
           <span v-if="row.type == '2'">卡密商品</span>
+          <span v-if="row.type == '3'">采购商品</span>
         </template>
       </el-table-column>
       <el-table-column label="盲豆兑换数量" prop="exchangePrice" sortable="custom" min-width="125"/>