peng
2025-09-15 89c12efa2ef8464680c81b11a5d98ac39fc99338
seller/src/views/goods/goods-seller/goodsOperationSec.vue
@@ -74,6 +74,17 @@
                            @on-change="choosePreTime"></DatePicker>
              </div>
            </FormItem>
            <FormItem v-if="baseInfoForm.goodsType == 'VIRTUAL_GOODS'" class="form-item-view-el" label="商品类型">
              <Select
                v-model="baseInfoForm.virtualGoodsType"
                clearable
                style="width: 160px"
                @on-clear="handleGoodsType"
                @on-change="handleGoodsType"
              >
                <Option value="COUPON">优惠卷</option>
                </select>
            </FormItem>
            <FormItem v-if="baseInfoForm.salesModel == 'WHOLESALE'" class="form-item-view-el" label="销售规则"
                      prop="wholesaleRule">
              <div class="form-item-view-wholesale">
@@ -118,6 +129,7 @@
            </FormItem>
          </div>
          <h4>商品规格及图片</h4>
          <div class="form-item-view">
            <FormItem class="form-item-view-el required" label="主图" prop="goodsGalleryFiles"  >
              <div style="display: flex; flex-wrap: wrap;">
@@ -156,6 +168,9 @@
                <img v-if="goodsPictureVisible" :src="previewGoodsPicture" style="width: 100%"/>
              </Modal>
            </FormItem>
            <FormItem>
<!--              <div class="demo-upload-list" v-for="(item,index) in showListImages">-->
@@ -270,12 +285,13 @@
                                      </template>
                                    </div>
                                  </vuedraggable>
<!--                                  todo 3-->
                                  <Upload ref="uploadSku" action="-"
                                  <!--                                  todo 3-->
                                  <Upload ref="uploadSku" :action="uploadFileUrl"
                                          v-if="val.images < 1"
                                          :before-upload="handleBeforeUpload"
                                          :format="['jpg', 'jpeg', 'png', 'webp']"
                                          :max-size="2048"
                                          :headers="{ ...accessToken }"
                                          :on-error="() => { $Spin.hide(); }"
                                          :on-exceeded-size="handleMaxSize"
                                          :on-format-error="handleFormatError"
@@ -344,6 +360,14 @@
                              baseInfoForm.goodsUnit || ""
                            }}</span>
                          </Input>
                        </template>
                        <template slot="COUPON" slot-scope="{ row }">
                          <div  @click="showCouponListModal(row)">
                            <Input v-model="row.couponName" clearable placeholder="选择优惠卷"
                            >
                            </Input>
                          </div>
                        </template>
                        <template slot="cost" slot-scope="{ row }">
                          <Input v-model="row.cost" clearable placeholder="请输入成本价"
@@ -504,7 +528,43 @@
        <Button type="primary" @click="saveToDraft">保存为模版</Button>
      </ButtonGroup>
    </div>
    <Modal v-model="showCouponModal" title="优惠卷列表" width="1200px">
      <div style="display: flex; align-items: center; margin-bottom: 20px;">
        <!-- 模拟表单label样式 -->
        <label style="width: 100px; text-align: right; padding-right: 12px; font-size:14px;">
          已选择优惠卷:
        </label>
        <Input
          :disabled="true"
          style="width: 30%;"
          v-model="showCoupon"
          placeholder="请点击选择表格内优惠劵"
        ></Input>
      </div>
        <Table
          :loading="couponLoading"
          border
          :columns="couponColumns"
          :data="couponData"
          ref="table"
          @on-current-change="handleRowClick"
          highlight-row
        ></Table>
        <Row type="flex" justify="center" class="mt_10">
          <Page
            :current="couponSearchForm.pageNumber"
            :total="couponTotal"
            :page-size="couponSearchForm.pageSize"
            @on-change="couponChangePage"
            @on-page-size-change="couponChangePageSize"
            :page-size-opts="[10, 20, 50]"
            size="small"
            show-total
            show-elevator
            show-sizer
          ></Page>
        </Row>
    </Modal>
    <Modal v-model="showGoodsVideo" title="查看视频">
      <div id="dplayer">
@@ -560,7 +620,8 @@
import {getFileKey} from "@/utils/file.js";
import {getFilePreview, getSts} from "@/api/file";
import {formatDate} from "@/utils/filters";
import {getShopCouponList} from '@/api/promotion'
import {promotionsScopeTypeRender} from "../../../utils/promotions";
export default {
  name: "goodsOperationSec",
@@ -592,6 +653,105 @@
      }, 1000);
    };
    return {
      currentRow:null,
      showCouponModal:false,
      showCoupon:'',
      couponSearchForm: {
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: "startTime", // 默认排序字段
        order: "desc", // 默认排序方式
        promotionStatus:"START",
      },
      selectedRowId:'',
      couponTotal:0,
      couponData:[],
      couponLoading:false,
      couponColumns: [
        // 表头
        {
          title: "优惠券名称",
          key: "couponName",
          width: 180,
          tooltip: true,
        },
        {
          title: "面额/折扣",
          key: "price",
          width: 150,
          render: (h, params) => {
            if (params.row.price) {
              return h("priceColorScheme", {props:{value:params.row.price,color:this.$mainColor}} );
            } else {
              return h("div", params.row.couponDiscount + "折");
            }
          },
        },
        {
          title: "获取方式",
          width: 120,
          key: "getType",
          render: (h, params) => {
            if (params.row.getType === "FREE") {
              return h("Tag", { props: { color: "red" } }, "免费获取");
            } else if (params.row.getType === "ACTIVITY") {
              return h("Tag", { props: { color: "volcano" } }, "活动获取");
            } else if (params.row.getType === "INSIDE") {
              return h("Tag", { props: { color: "lime" } }, "内购");
            } else if (params.row.getType === "IGAME") {
              return h("Tag", { props: { color: "lime" } }, "游戏人生");
            } else {
              return h("Tag", { props: { color: "purple" } }, "未知");
            }
          },
        },
        {
          title: "优惠券类型",
          key: "couponType",
          width: 150,
          render: (h, params) => {
            let text = "";
            if (params.row.couponType === "DISCOUNT") {
              return h("Tag", { props: { color: "blue" } }, "打折");
            } else if (params.row.couponType === "PRICE") {
              return h("Tag", { props: { color: "geekblue" } }, "减免现金");
            } else {
              return h("Tag", { props: { color: "purple" } }, "未知");
            }
          },
        },
        {
          title: "品类描述",
          key: "scopeType",
          width: 120,
          render: (h, params) => {
            return promotionsScopeTypeRender(h, params);
          },
        },
        {
          title: "活动时间",
          render: (h, params) => {
            if (
              params?.row?.getType === "ACTIVITY" &&
              params?.row?.rangeDayType === "DYNAMICTIME"
            ) {
              return h("div", "长期有效");
            } else if (params?.row?.startTime && params?.row?.endTime) {
              return h("div", {
                domProps: {
                  innerHTML:
                    params.row.startTime + "<br/>" + params.row.endTime,
                },
              });
            }
          },
        }
      ],
      showListImages: [],
      regular,
      openImage: false,
@@ -664,6 +824,7 @@
      ],
      /** 发布商品基本参数 */
      baseInfoForm: {
        virtualGoodsType:"",
        salesModel: "RETAIL",
        /** 商品相册列表 */
        goodsGalleryFiles: [],
@@ -700,7 +861,8 @@
        preSaleTime:[],
        preSaleBeginDate:'',
        preSaleEndDate:'',
        commission:5
        commission:5,
      },
      /** 表格头 */
      skuTableColumn: [],
@@ -758,6 +920,8 @@
        "price",
        "weight",
        "quantity",
        "couponName",
        "couponId",
        // "alertQuantity",
        "specId",
        "specValueId",
@@ -766,6 +930,7 @@
      selectedFormBtnName: "", // 点击图片绑定form
      selectedImage: [],
      lastEditSkuValue: '',
    };
  },
  watch: {
@@ -782,6 +947,50 @@
    }
  },
  methods: {
    showCouponListModal(row){
      this.showCouponModal = true;
      this.showCoupon ='';
      this.getCouponDataList()
      this.currentRow = row;
    },
    handleGoodsType(){
      //重新渲染
      this.renderTableData(this.skuTableData);
    },
    getCouponDataList() {
      // 获取数据
      this.couponLoading = true;
      getShopCouponList(this.couponSearchForm).then((res) => {
        this.couponLoading = false;
        if (res.success) {
          this.couponData = res.result.records;
          this.couponTotal = res.result.total;
        }
      });
      this.couponLoading = false;
    },
    // 处理行点击事件
    handleRowClick(currentRow ,oldCurrentRow){
      this.showCoupon = currentRow.couponName;
      this.$set(this.currentRow, 'couponName', currentRow.couponName);
      this.currentRow.couponId = currentRow.id
      console.log(this.currentRow)
      this.updateSkuTable(this.currentRow,"couponName")
      this.updateSkuTable(this.currentRow,"couponId")
      console.log(this.skuTableData)
    },
    couponChangePage(v) {
      // 改变页码
      this.couponSearchForm.pageNumber = v;
      this.getCouponDataList();
    },
    couponChangePageSize(v) {
      // 改变页数
      this.couponSearchForm.pageNumber = 1;
      this.couponSearchForm.pageSize = v;
      this.getCouponDataList();
    },
    // 格式化显示值
    formatter(date) {
      return this.formatDate(date, 'yyyy-MM-dd');
@@ -1116,6 +1325,16 @@
      }
    },
    // sku图片上传前钩子
  // async handleBeforeUpload(file) {
  //     const check =
  //       this.selectedSku.images !== undefined &&
  //       this.selectedSku.images.length > 5;
  //     if (check) {
  //       this.$Notice.warning({title: "图片数量不能大于五张"});
  //       return false;
  //     }
  //   },
    // sku图片上传前钩子
  async handleBeforeUpload(file) {
      const check =
        this.selectedSku.images !== undefined &&
@@ -1327,6 +1546,8 @@
          // cost: e.cost,
          quantity: e.quantity,
          // alertQuantity: e.alertQuantity,
          couponName:e.couponName,
          couponId:e.couponId,
          weight: e.weight,
        };
        if (e.goodsGalleryList && e.goodsGalleryList.length >= 1) {
@@ -1459,8 +1680,8 @@
        this.$Message.error("已存在相同规格项!");
        return;
      }
      if (this.zz(0, val) > 20) {
        this.$Message.error("规格值最多十个字符长度!");
      if (this.zz(0, val) > 30) {
        this.$Message.error("规格值最多十五个字符长度!");
        // val = val.toString().slice(0, 4);
        this.skuInfo[index].name = this.countCharacters(val, 10);
        this.$forceUpdate();// 调用该方法会触发组件的重新渲染
@@ -1515,8 +1736,8 @@
      if (val.value === '') {
        return;
      }
      if (this.zz(0, val.value) > 20) {
        this.$Message.error("规格值最多十个字符长度!");
      if (this.zz(0, val.value) > 30) {
        this.$Message.error("规格值最多十五个字符长度!");
        // val.value = val.value.toString().slice(0, 4);
        this.skuInfo[$index].spec_values[index].value = this.countCharacters(val.value, 10);
        this.$forceUpdate();// 调用该方法会触发组件的重新渲染
@@ -1678,6 +1899,8 @@
              // find.cost && (find.cost = "");
              find.quantity && (find.quantity = "");
              // find.alertQuantity && (find.alertQuantity = "");
              find.couponName && (find.couponName = "");
              find.couponId && (find.couponId = "");
              find.weight && (find.weight = "");
              this.skuTableData.splice(this.skuTableData.length, 0, find);
@@ -1692,6 +1915,8 @@
              find.sn && (find.sn = "");
              // find.cost && (find.cost = "");
              find.quantity && (find.quantity = "");
              find.couponName && (find.couponName = "");
              find.couponId && (find.couponId = "");
              // find.alertQuantity && (find.alertQuantity = "");
              find.weight && (find.weight = "");
@@ -1731,7 +1956,7 @@
     * 渲染table所需要的column 和 data
     */
    renderTableData(skus) {
      console.log('-------------->销售类型',skus)
      console.log('-------------->销售类型', skus)
      this.skuTableColumn = [];
      let pushData = [];
      // 渲染头部
@@ -1783,6 +2008,14 @@
          title: "重量",
          slot: "weight",
        });
      }
      if (this.baseInfoForm.goodsType ==="VIRTUAL_GOODS" && this.baseInfoForm.virtualGoodsType==="COUPON"){
        pushData.push(
          {
            title:"优惠卷",
            slot:"COUPON"
          }
        )
      }
      pushData.push(
        {
@@ -1836,6 +2069,7 @@
              id: skus[index].id,
              sn: skus[index].sn,
              quantity: skus[index].quantity,
              coupon: skus[index].coupon,
              cost: skus[index].cost,
              price: skus[index].price,
              // [spec[0].name]: skus[index][spec[0].name] ? skus[index][spec[0].name] : specItem.value,
@@ -1999,10 +2233,10 @@
            }
            this.baseInfoForm.goodsId = this.goodsId;
            let submit = JSON.parse(JSON.stringify(this.baseInfoForm));
            console.log('----------------->提交',submit);
            if (
              submit.goodsGalleryFiles &&
                submit.goodsGalleryFiles.length <= 0
              submit.goodsGalleryFiles.length <= 0
            ) {
              this.submitLoading = false;
              this.$Message.error("请上传商品图片");
@@ -2037,10 +2271,25 @@
                cost: 1,
                price: sku.price,
                quantity: sku.quantity,
                couponName:sku.couponName,
                couponId:sku.couponId,
                // alertQuantity: sku.alertQuantity,
                sn: sku.sn,
                images: [],
              };
              if(this.baseInfoForm.goodsType === "VIRTUAL_GOODS" &&
                this.baseInfoForm.virtualGoodsType !== '' &&
                this.baseInfoForm.virtualGoodsType !== undefined &&
                this.baseInfoForm.virtualGoodsType !== null){
                if (sku.couponId === null || sku.couponId === undefined){
                  this.$Message.error("请选择优惠劵")
                  return;
                }
                if (sku.couponName === null || sku.couponName === undefined){
                  this.$Message.error("请选择优惠劵")
                  return;
                }
              }
              if (this.openImage) {
                this.skuInfo[0].spec_values.forEach(item => {
                  if (!item.images || item.images.length === 0) {
@@ -2067,6 +2316,7 @@
              }
              submit.skuList.push(skuCopy);
            });
            console.log('----------------->提交', submit);
            if (containEmptyImage) {
              this.$Message.error("开启规格图片,所有规格图片不能为空!");
              this.submitLoading = false;
@@ -2094,6 +2344,7 @@
                }
              });
            } else {
              console.log(submit)
              API_GOODS.createGoods(submit).then((res) => {
                if (res.success) {
                  this.submitLoading = false;
@@ -2177,18 +2428,18 @@
          this.$Message.error("刷新失败,请重试");
        }
      }).catch(reason => {
        console.log("获取模板失败",reason)
        console.log("获取模板失败", reason)
      });
    },
    removeVideo(){
    removeVideo() {
      this.baseInfoForm.showGoodsVideo = null;
      this.baseInfoForm.goodsVideo = null;
    },
    // todo 文件上传
    async upLoadImg(file) {
      console.log(file,this.count++);
      if (this.listImages.length >= 5) {
        this.$Message.error("图片上传不能超过5个");
      console.log(file, this.count++);
      if (this.listImages.length >= 10) {
        this.$Message.error("图片上传不能超过10个");
        return;
      }
      try {
@@ -2305,12 +2556,10 @@
        this.baseInfoForm.goodsType = this.firstData.goodsType;
        if (this.categoryId!=null && this.categoryId!=='') {
        if (this.categoryId != null && this.categoryId !== '') {
          /** 获取该商城分类下 商品参数信息 */
          this.GET_GoodsParams();
          console.log('分类id------------------>',this.categoryId);
          console.log('分类id------------------>', this.categoryId);
          /** 查询分类绑定的规格信息 */
          this.Get_SkuInfoByCategory(this.categoryId);
          /** 查询品牌列表 */