Bläddra i källkod

优化首页装修商品列表

Blacked 2 år sedan
förälder
incheckning
4f18c02bb2

+ 2 - 2
.env.development

@@ -2,8 +2,8 @@
 ENV = 'development'
 
 // api接口请求地址
-//VUE_APP_BASE_API = 'http://lymall-platform.58for.com/apis'
-VUE_APP_BASE_API = 'http://192.168.1.176:8088'
+VUE_APP_BASE_API = 'http://lymall-platform.58for.com/apis'
+//VUE_APP_BASE_API = 'http://192.168.1.176:8088'
 
 // 客服api接口请求地址
 //VUE_APP_IM_API = 'https://b2b2c-im.mall4j.com'

+ 3 - 0
src/views/modules/platform/feature/create/edit/components/goods/index.scss

@@ -28,6 +28,9 @@
             background-size: contain;
             background-position: center;
             flex: 1;
+            display: flex;
+            justify-content: center;
+            align-items: center;
             &::before {
               content: "";
               padding-top: 100%;

+ 181 - 119
src/views/modules/platform/feature/create/edit/components/goods/index.vue

@@ -2,87 +2,130 @@
   <div class="micro-goods-box">
     <div class="design-preview-controller">
       <div class="goods-list">
-        <div v-for="(item,index) in goodsList"
-             :key="index"
-             class="goods-li"
-             :class="{isGoodCell3:formData.size === 3, isGoodCell1:formData.size === 1}">
+        <div v-for="(item, index) in goodsList" :key="index" class="goods-li"
+             :class="{ isGoodCell3: formData.size === 3, isGoodCell1: formData.size === 1 }">
           <div class="goods-li-box"
-               :class="{'no-goods-price':!formData.showContent.find(x=>x===3)&&formData.showContent.find(x=>x===4)}">
-            <div class="goods-item"
-                 :class="{goodsItem1:formData.size === 1}">
+               :class="{ 'no-goods-price': !formData.showContent.find(x => x === 3) && formData.showContent.find(x => x === 4) }">
+            <div class="goods-item" :class="{ goodsItem1: formData.size === 1 }" style="background: #fff"
+                 :style="'backgroundImage:url(' + formData.back_imgsrc + ');background-repeat: no-repeat;background-size: 100%'"
+            >
               <!--图片-->
               <div class="goods-img-one"
-                   :class="{goodsImgOne1:formData.size === 1, 'goods-empty': !goodsList[0].prodId}"
-                   :style="{backgroundImage:'url('+item.pic+')'}"></div>
+                   :class="{ goodsImgOne1: formData.size === 1, 'goods-empty': !goodsList[0].prodId }"
+                   >
+                <div :style="'backgroundImage: url(' + item.pic + ');width: '+formData.img_unit+'%;height: '+formData.img_unit+'%;padding-top: '+formData.img_unit+'%;background-repeat: no-repeat;background-size: 100%'"></div>
+              </div>
               <!--end 图片-->
-              <div class="goods-box-info"
-                   :class="{goodsBoxInfo1:formData.size === 1}">
-                <div v-if="formData.showContent.find(x=>x===1)"
-                     class="goods-info-title">{{ item.prodName }}
-                </div>
-                <div v-if="formData.showContent.find(x=>x===2)&&item.brief"
-                     class="goods-info-desc">
-                  {{ item.brief }}
-                </div>
-                <div v-if="formData.showContent.find(x=>x===3)||formData.showContent.find(x=>x===4)"
-                     class="goods-info-price "
-                     :class="{'goods-cell-3':formData.showContent.find(x=>x===4)}">
-                  <div v-if="formData.showContent.find(x=>x===3)"
-                       class="price-info"><span>¥</span>{{ item.price }}
+              <div class="goods-box-info" :class="{ goodsBoxInfo1: formData.size === 1 }" style="display: flex;justify-content: center">
+                <div :style="'width: '+formData.info_unit+'%;'">
+                  <div v-if="formData.showContent.find(x => x === 1)" class="goods-info-title">{{ item.prodName }}
+                  </div>
+                  <div v-if="formData.showContent.find(x => x === 2) && item.brief" class="goods-info-desc">
+                    {{ item.brief }}
+                  </div>
+                  <div v-if="formData.showContent.find(x => x === 3) || formData.showContent.find(x => x === 4)"
+                     class="goods-info-price " :class="{ 'goods-cell-3': formData.showContent.find(x => x === 4) }">
+                  <div v-if="formData.showContent.find(x => x === 3)" class="price-info"><span>¥</span>{{ item.price }}
+                  </div>
+                  <div v-if="formData.showContent.find(x => x === 4)"
+                       :class="['goods-info-buy-btn', 'btn-type-' + formData.buy_btn_type]">
+                    <!-- <i v-if="formData.buy_btn_type === 1" :class="['btn-type-' + formData.buy_btn_type]"></i>
+                    <i v-if="formData.buy_btn_type === 2" class="el-icon-circle-plus-outline"></i>
+                    <i v-if="formData.buy_btn_type === 3" class="el-icon-goods"></i>
+                    <i v-if="formData.buy_btn_type === 4" class="el-icon-s-goods"></i> -->
+                    <!-- <el-button v-if="formData.buy_btn_type >= 1" :round="formData.buy_btn_type >= 7" size="mini"
+                      :type="formData.buy_btn_type | buy_btn_type">{{ formData.button_text || '马上抢' }}
+                    </el-button> -->
+                    <div v-if="formData.button_type==='1'"
+                         :style="'width: '+formData.button_img_width+'px;height: '+formData.button_img_height+'px;overflow: hidden;'">
+                      <div class="el-button-img"
+                           :style="'width: '+formData.button_img_width+'px;height: '+formData.button_img_height+'px;backgroundImage: url('+formData.button_imgsrc+');background-size: 100%; background-repeat: no-repeat;'"
+                      >
+
+                      </div>
+                    </div>
+                    <div class="el-button" v-else
+                         :style="'border-radius: ' + formData.button_border_radius + 'px;background-color: ' + formData.button_back_color + ';font-size:' + formData.button_font_size + 'px;'">
+                      <!-- <i class="el-icon-circle-plus-outline"
+                        :style="'font-size: ' + formData.button_font_size + 'px;'"></i> -->
+                      {{ formData.button_text || '马上抢' }}
+                    </div>
+
                   </div>
-                  <!--
-                    v-if="formData.showContent.find(x=>x===4)"
-                    :class="['goods-info-buy-btn','btn-type-'+formData.buy_btn_type]"
-                  >
-                    <i v-if="formData.buy_btn_type===1" :class="['btn-type-'+formData.buy_btn_type]"></i>
-                    <i v-if="formData.buy_btn_type===2" class="el-icon-circle-plus-outline"></i>
-                    <i v-if="formData.buy_btn_type===3" class="el-icon-goods"></i>
-                    <i v-if="formData.buy_btn_type===4" class="el-icon-s-goods"></i>
-                    <el-button
-                      v-if="formData.buy_btn_type>=5"
-                      :round="formData.buy_btn_type>=7"
-                      size="mini"
-                      :type="formData.buy_btn_type | buy_btn_type"
-                    >{{ formData.button_text || '马上抢' }}
-                    </el-button>
-                  </div> -->
+                </div>
                 </div>
               </div>
             </div>
+
+
+<!--            <div :style="'width: 170px;background-repeat: no-repeat;background-size: 100%;background-image: url('+formData.back_imgsrc+')'">-->
+<!--              <div style="width: 170px;height: 170px;display: flex;justify-content: center;align-items: center;">-->
+<!--                <div :style="'backgroundImage: url(' + item.pic + ');width: '+formData.img_unit+'%;height: '+formData.img_unit+'%;background-repeat: no-repeat;background-size: contain;background-position: center;'"></div>-->
+<!--              </div>-->
+<!--              <div style="width: 170px;height: 80px;display: flex;align-items: center;flex-direction: column">-->
+<!--                <div :style="'width: '+formData.info_unit+'%;height: 80px;'">-->
+<!--                  <div  v-if="formData.showContent.find(x => x === 1)" style="width: 100%;font-size: 12px;line-height: 20px;font-weight: bold;height: 20px;text-overflow: ellipsis;-->
+<!--                -o-text-overflow: ellipsis;-->
+<!--                -webkit-text-overflow: ellipsis;-->
+<!--                -moz-text-overflow: ellipsis;-->
+<!--                word-break: break-word;-->
+<!--                display: -webkit-box;-->
+<!--                -webkit-line-clamp: 1;-->
+<!--                -webkit-box-orient: vertical;-->
+<!--                overflow: hidden;">{{ item.prodName }}</div>-->
+<!--                  <div  v-if="formData.showContent.find(x => x === 2)" style="width: 100%;font-size: 12px;line-height: 20px;color: #999;height: 20px;text-overflow: ellipsis;-->
+<!--                -o-text-overflow: ellipsis;-->
+<!--                -webkit-text-overflow: ellipsis;-->
+<!--                -moz-text-overflow: ellipsis;-->
+<!--                word-break: break-word;-->
+<!--                display: -webkit-box;-->
+<!--                -webkit-line-clamp: 1;-->
+<!--                -webkit-box-orient: vertical;-->
+<!--                overflow: hidden;">{{ item.brief }}</div>-->
+<!--                  <div style="width: 100%;display: flex;justify-content: space-between;flex-direction: row;padding-top: 10px">-->
+<!--                    <div style="width: 40%;height: 25px">-->
+<!--                      <div v-if="formData.showContent.find(x => x === 3)" style="width: 100%;font-size: 14px;line-height: 25px;color: #ff4444;overflow: hidden;text-overflow: ellipsis;-o-text-overflow: ellipsis; -webkit-text-overflow: ellipsis;-->
+<!--                    -moz-text-overflow: ellipsis;white-space: nowrap;">{{'¥'+item.price}}-->
+<!--                      </div>-->
+<!--                    </div>-->
+
+<!--                    <div  v-if="formData.showContent.find(x => x === 4)">-->
+<!--                      <div v-if="formData.button_type==='1'" :style="'width: '+formData.button_img_width+'px;height: '+formData.button_img_height+'px;backgroundImage: url('+formData.button_imgsrc+');background-size: 100%; background-repeat: no-repeat;'"></div>-->
+<!--                      <div v-else style="padding: 0 5px 0 5px;height: 25px;line-height: 25px;" :style="'border-radius: ' + formData.button_border_radius + 'px;background-color: ' + formData.button_back_color + ';font-size:' + formData.button_font_size + 'px;'">-->
+<!--                        {{ formData.button_text || '马上抢' }}-->
+<!--                      </div>-->
+<!--                    </div>-->
+<!--                  </div>-->
+<!--                </div>-->
+<!--              </div>-->
+<!--            </div>-->
           </div>
         </div>
-        <div class="empty-tips"
-             v-if="goodsList.length==0">
-          {{$t('shopFeature.goods.pleaseAddProd')}}
+        <div class="empty-tips" v-if="goodsList.length == 0">
+          {{ $t('shopFeature.goods.pleaseAddProd') }}
         </div>
       </div>
     </div>
 
-    <div v-if="isShowEdit"
-         class="design-editor-item design-hide-class">
+    <div v-if="isShowEdit" class="design-editor-item design-hide-class">
       <div class="design-config-editor">
-        <div class="design-editor-component-title">{{$t('shopFeature.allCanUse.goodsList')}}</div>
+        <div class="design-editor-component-title">{{ $t('shopFeature.allCanUse.goodsList') }}</div>
         <!--选择商品-->
         <div class="design-editor-component-container">
           <el-form ref="formData" :model="formData" label-position="left" class="goods-select-form">
             <el-form-item :label="$i18n.t('shopFeature.goods.prod')" class="goods-select-con">
-              <div class="goods-select-list">
+              <div  class="goods-select-list">
                 <transition-group>
-                <div v-for="(item,index) in goodsList"
-                    :key="index"
-                    class="goods-select-item">
-                  <div  @dragenter="dragenter($event, index)" @dragover="dragover($event, index)" @dragstart="dragstart(index)" draggable >
-                  <div class="goods-select-item-img"
-                      :class="{'goods-empty': !goodsList[0].prodId}"
-                      :style="{backgroundImage:'url('+item.pic+')'}"></div>
-                  <span class="close-item"
-                        @click="goodsList.splice(index,1)">x</span>
+                  <div v-for="(item, index) in goodsList" :key="index" class="goods-select-item">
+                    <div  @dragenter="dragenter($event, index)" @dragover="dragover($event, index)" @dragstart="dragstart(index)" draggable >
+                      <div class="goods-select-item-img" :class="{ 'goods-empty': !goodsList[0].prodId }"
+                           :style="{ backgroundImage: 'url(' + item.pic + ')' }"></div>
+                      <span class="close-item" @click="goodsList.splice(index, 1)">x</span>
+                    </div>
                   </div>
-                </div>
                 </transition-group>
                 <div class="goods-select-item">
-                  <div class="goods-select-item-img add-btn"
-                       @click="selectProdHandle">
+                  <div class="goods-select-item-img add-btn" @click="selectProdHandle">
                     <i class="el-icon-plus"></i>
                   </div>
                 </div>
@@ -90,20 +133,36 @@
             </el-form-item>
             <el-form-item :label="$i18n.t('shopFeature.goods.listStyle')">
               <el-radio-group v-model="formData.size">
-                <el-radio v-for="(count, index) in lineSize" :label="count.value" :key="index">{{count.label}}</el-radio>
+                <el-radio v-for="(count, index) in lineSize" :label="count.value" :key="index">{{
+                    count.label
+                  }}
+                </el-radio>
               </el-radio-group>
             </el-form-item>
             <el-form-item :label="$i18n.t('shopFeature.goods.showContent')" class="goods-show-container">
               <div class="goods-show-content">
-                <el-checkbox-group v-model="formData.showContent">
-                <el-checkbox v-for="(showItem, index) in goodsShowContent" :key="index" :label="showItem.value">{{showItem.label}}</el-checkbox>
-              </el-checkbox-group>
+                <el-checkbox-group style="display: flex;flex-wrap: wrap;" v-model="formData.showContent">
+                  <el-checkbox v-for="(showItem, index) in goodsShowContent" :key="index" :label="showItem.value">{{
+                      showItem.label
+                    }}
+                  </el-checkbox>
+                </el-checkbox-group>
+              </div>
+            </el-form-item>
+            <el-form-item label="背景样式" class="goods-show-container">
+              <div class="goods-show-content">
+                <el-form-item label="背景图选择:">
+                  <div :style="'width: 50px;height:50px;backgroundImage: url('+formData.back_imgsrc+');background-size: 100%; background-repeat: no-repeat;'">
+                  </div>
+                </el-form-item>
+                <el-button @click="changeImg(2)">选择图片</el-button>
               </div>
             </el-form-item>
-            <el-form-item label="关联类型">
-              <el-select v-model="formData.categoryName" @change="changetab" clearable :disabled="$route.query.code == 2" placeholder="请选择" value-key="categoryId">
-                <el-option v-for="item in categoryList" :key="item.categoryId" :label="item.categoryName" :value="item.categoryName"></el-option>
-              </el-select>
+            <el-form-item label="海报比例" class="goods-show-container">
+              <el-input type="number" v-model="formData.img_unit"></el-input>
+            </el-form-item>
+            <el-form-item label="详情比例" class="goods-show-container">
+              <el-input type="number" v-model="formData.info_unit"></el-input>
             </el-form-item>
             <el-form-item v-if="formData.showContent.find(x => x === 4)" label="按钮样式" class="goods-show-container">
               <el-radio v-model="formData.button_type" label="1">图片按钮</el-radio>
@@ -115,7 +174,7 @@
                     <!--                    <el-image :src="formData.button_imgsrc" style="width: 50px;height: 50px;"></el-image>-->
                   </div>
                 </el-form-item>
-                <el-button @click="changeImg">选择图片</el-button>
+                <el-button @click="changeImg(1)">选择图片</el-button>
                 <el-form-item label="背景图宽度:">
                   <el-input type="number" v-model="formData.button_img_width"></el-input>
                 </el-form-item>
@@ -145,9 +204,9 @@
         </div>
       </div>
     </div>
-    <prods-select v-if="dialogChooseGoods"
-                  ref="ProdsSelect"
-                  @refreshSelectProds="chooseGoodsFun"></prods-select>
+    <prods-select v-if="dialogChooseGoods" ref="ProdsSelect" @refreshSelectProds="chooseGoodsFun"></prods-select>
+    <!-- 弹窗, 新增图片 -->
+    <elx-imgbox ref="elxImgbox" @refreshPic="refreshPic" :maxSize="10" :imgSizeLimit="false"></elx-imgbox>
   </div>
 </template>
 <script>
@@ -156,9 +215,9 @@
  * 必须应用 microCreateMinis
  * 数据必须以formData包含
  * */
-import { microCreateMinis } from '../../minis'
+import {microCreateMinis} from '../../minis'
 import ProdsSelect from '@/components/prods-select'
-import {treeDataTranslate} from "@/utils";
+import ElxImgbox from '@/components/elx-imgbox'
 
 /** 商品组件 */
 export default {
@@ -167,7 +226,6 @@ export default {
   props: {},
   data () {
     return {
-      categoryList: [],
       dragIndex: '',
       enterIndex: '',
       resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
@@ -184,13 +242,12 @@ export default {
         value: 'el-icon-s-goods',
         label: '3'
       }],
+      currentEditIndex: undefined,
       formData: {
-        categoryName: null,
-        categoryId: null,
         size: 2, // 一行多少个
-        showContent: [1, 2, 3, 4],
-        goods: [],
+        showContent: [1, 2, 3, 4],//1.商品名称2.商品描述3.商品价格4.按钮
         button_type: '1',
+        goods: [],
         button_img_width: 54,
         button_img_height: 24,
         button_imgsrc: undefined,//购买按钮背景图
@@ -199,9 +256,11 @@ export default {
         icon_class: 'el-icon-s-goods', //购买按钮的icon
         button_font_size: 10,// 购买按钮的字体大小
         button_border_radius: 0, //购买按钮边框弧度
-        button_back_color: '#ffffff' //购买按钮背景颜色
-        // buy_btn_type: 1, // 购买按钮的样式
-        // button_text: '马上抢'// 购买按钮的文本
+        button_back_color: '#ffffff', //购买按钮背景颜色
+
+        back_imgsrc: undefined, //商品卡片背景图
+        img_unit: 80,
+        info_unit: 80,
       },
       // 商品显示内容
       goodsShowContent: [
@@ -277,7 +336,9 @@ export default {
     }
   },
   components: {
-    ProdsSelect
+    ProdsSelect,
+    ElxImgbox
+
   },
   computed: {
     theme () {
@@ -285,7 +346,6 @@ export default {
     }
   },
   mounted () {
-    this.getlistCategory()
     for (let i = 0; i < 4; i++) {
       this.demoGoods.push(
         {
@@ -305,36 +365,6 @@ export default {
     }
   },
   methods: {
-    /** 更换图片 */
-    changeImg (index) {
-      console.log(index)
-      this.isChangeImg = true
-      this.currentEditIndex = index
-      this.elxImgboxHandle(1)
-      // this.canChooseImagesNum = 1
-    },
-    getlistCategory(){
-      this.$http({
-        url: this.$http.adornUrl('/prod/category/listCategory'),
-        method: 'get',
-        params: this.$http.adornParams({
-          maxGrade: 2,
-          shopId: 1
-        })
-      }).then(({ data }) => {
-        this.categoryList = treeDataTranslate(data, 'categoryId', 'parentId')
-      })
-    },
-    changetab(val){
-      console.log(val)
-      let num = ''
-      this.categoryList.forEach((item,index)=>{
-        if(item.categoryName===val){
-          num = item.categoryId;
-        }
-      })
-      this.formData.categoryId = num
-    },
     dragstart(index) {
       this.dragIndex = index;
     },
@@ -352,15 +382,45 @@ export default {
     dragover(e, index) {
       e.preventDefault();
     },
+    /**
+     * 选择图片回调
+     * @param {String} imagePath 无前缀的图片地址字符串(多图时用,分割)
+     */
+    refreshPic(imagePath) {
+      if(this.currentEditIndex===1){
+        this.formData.button_imgsrc = this.resourcesUrl + imagePath
+      }else{
+        this.formData.back_imgsrc = this.resourcesUrl + imagePath
+      }
+      // console.log(this.formData.button_imgsrc)
+
+    },
+    /** 更换图片 */
+    changeImg(index) {
+      console.log(index)
+      this.isChangeImg = true
+      this.currentEditIndex = index
+      this.elxImgboxHandle(1)
+      // this.canChooseImagesNum = 1
+    },
+    elxImgboxHandle(type) {
+      if (this.disabled) {
+        return false
+      }
+      this.elxImgboxVisible = true
+      this.$nextTick(() => {
+        this.$refs.elxImgbox.init(type || 2, 1)
+      })
+    },
     // 选择商品操作
-    selectProdHandle () {
+    selectProdHandle() {
       this.dialogChooseGoods = true
       this.$nextTick(() => {
         this.$refs.ProdsSelect.init()
       })
     },
     // 选择商品回调
-    chooseGoodsFun ($event) {
+    chooseGoodsFun($event) {
       if ($event) {
         if (this.goodsList.find(x => x.myGoodsType === 1)) {
           this.goodsList = []
@@ -374,7 +434,7 @@ export default {
       this.dialogChooseGoods = false
     },
     /** 批量获取商品详情 */
-    getGoodsInfo (prodIds, prodType) {
+    getGoodsInfo(prodIds, prodType) {
       this.$http({
         url: this.$http.adornUrl('/prod/prod/listProdByIdsAndType'),
         method: 'get',
@@ -382,7 +442,7 @@ export default {
           prodIds,
           prodType
         })
-      }).then(({ data }) => {
+      }).then(({data}) => {
         this.goodsList = this.sortList(data)
         this.goodsList.forEach(item => {
           if (!item.pic.includes('http')) {
@@ -394,15 +454,17 @@ export default {
     /**
      * 按照添加的顺序排序
      */
-    sortList (goodsList) {
+    sortList(goodsList) {
       let showArr = this.dataField.goods
       goodsList.forEach(item => {
         item.sortId = showArr.indexOf(item.prodId)
       })
-      return goodsList.sort((a, b) => { return a.sortId - b.sortId })
+      return goodsList.sort((a, b) => {
+        return a.sortId - b.sortId
+      })
     },
     /* 校验 */
-    checkData () {
+    checkData() {
       if (this.formData.goods.length > 0) {
         this.myCheckResult(true)
       } else {