add.vue 9.45 KB
<!-- 采购商城 -->
<template>
  <div class="mallContainer">
    <div class="bg header addressCon" slot="header">
      <div class="addressTitle">
        <img src="@/images/addressIcon.webp" alt="" class="icon" />
        <span class="title">{{ $$(addressInfo, 'yqMerchantName') }}</span>
        <span class="edit pointer" @click="addressComVisible = true">
          <img src="@/images/editAddressIcon.webp" alt="" class="editIcon" />
          修改
        </span>
      </div>
      <div class="addressInfo">
        <!-- 收货人:白敬亭 -->
        <span class="name">
          收货人:
          <span class="label">{{ $$(addressInfo, 'contactName') }}</span>
        </span>
        <span class="phone">
          电话:
          <span class="label">{{ $$(addressInfo, 'contactPhone') }}</span>
        </span>
        <span class="address">
          收货地址:
          <span class="label">{{ $$(addressInfo, 'contactAddress') }}</span>
        </span>
      </div>
    </div>
    <div class="d2-container-content shopMallCon">
      <!-- :stretch="false" -->
      <div class="classifyContainer">
        <el-tabs v-model="searchForm.goodsType" @tab-click="handleSearch" type="card">
          <el-tab-pane v-for="(item, i) in navList" :key="i" class="tabItem" :label="item.goodsTypeName" :name="item.goodsType"></el-tab-pane>
        </el-tabs>
      </div>
      <div class="searchCon">
        <GLCombiForm ref="showSearch" :formObj="searchForm" :formData="showFormData" @handleOk="handleSearch" @handleRest="handleRest"></GLCombiForm>
      </div>
      <div class="goodsCon">
        <div class="goodsItemCon" v-for="(item, index) in purchaseList" :class="[{ active: item.active }, { last: index === purchaseList.length - 1 }]" :key="index">
          <!-- 图片{{ item.thumbUrl }} -->
          <img :src="item.thumbUrl" class="img" alt="" />
          <span class="goodsName one-line-ellipsis">{{ item.goodsName }}</span>
          <!-- 名称{{ item.goodsName }} -->
          <span class="purchaseOrderCount">成交量/笔:{{ item.purchaseOrderCount }}</span>
          <!-- 成交量{{ item.purchaseOrderCount }} -->
          <span class="viewPurchase pointer" @click="handleDetail(item, index)">查看购买</span>
        </div>
        <div class="emptyCom" v-show="!purchaseList.length">
          <img :src="emptyImgUrl" class="emptyImg" alt="" />
          <span class="tips">暂无数据</span>
        </div>
      </div>
      <div class="pageCon">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.pageNum" :page-sizes="[10, 20, 30, 40]" :page-size="page.pageSize" :total="total" layout="->,prev,pager,next" />
      </div>
    </div>
    <!-- 购物车组件 -->
    <shoppingCartCom ref="shoppingCartCom" :address-info="addressInfo" @editAddress="orderFrom" />
    <addressCom :visible.sync="addressComVisible" @handleConfirmAddress="addressGet" :address-info="addressInfo" />
    <goodsDetailCom :visible.sync="goodsDetailComVisible" :goods-id="selectItem.id" />
  </div>
</template>

<script>
import shoppingCartCom from './components/shoppingCartCom'
import addressCom from './components/addressCom'
import goodsDetailCom from './components/goodsDetailCom'

export default {
  name: 'PurchasingMall',
  components: {
    shoppingCartCom,
    addressCom,
    goodsDetailCom
  },
  data() {
    return {
      //   userInfo: this.$store.state.d2admin.user.info,
      addressComVisible: false,
      goodsDetailComVisible: false,
      emptyImgUrl: require('@/assets/empty.png'),
      showFormData: [
        {
          name: 'goodsName',
          type: 'input',
          placeholder: '商品名称/系列',
          width: '282px'
        }
      ],
      searchForm: {
        goodsType: '',
        goodsName: ''
      },
      total: 0,
      page: {
        pageNum: 1,
        pageSize: 12
      },
      navList: [],
      purchaseList: [],
      addressInfo: {
        contactName: '',
        contactPhone: '',
        contactAddress: '',
        yqMerchantName: '',
        yqMerchantId: ''
      },
      productType: [],
      selectItem: {},
      showOrderCom: false
    }
  },
  created() {
    this.getGoodsCategoryConfiguration()
    this.listWithPagePurchaseInfo()
    this.addressGet()
  },
  mounted() {},
  methods: {
    orderFrom() {
      this.addressComVisible = true
      this.showOrderCom = true
    },
    handleSearch() {
      this.page.pageNum = 1
      this.listWithPagePurchaseInfo()
    },
    handleRest() {
      this.searchForm.goodsName = ''
      this.page.pageNum = 1
      this.listWithPagePurchaseInfo()
    },
    handleDetail(item, index) {
      this.selectItem = item
      this.goodsDetailComVisible = true
      const list = this.$common.utils.deepClone(this.purchaseList)
      this.purchaseList = list.map((item, itemIndex) => {
        item.active = itemIndex == index
        return item
      })
    },

    listWithPagePurchaseInfo() {
      const params = {
        ...this.page,
        goodsType: +this.searchForm.goodsType || '',
        goodsName: this.searchForm.goodsName
      }
      this.$apis.purchaseShopping
        .listWithPagePurchaseInfo(params)
        .then(result => {
          const { list, total } = result
          this.purchaseList = list
          this.total = total
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 获取类目列表
    getGoodsCategoryConfiguration() {
      this.$apis.sysBase.getGoodsCategoryConfiguration({ sceneType: 1, shoppingMallFlag: true }).then(result => {
        const { list } = result
        if (list.length) {
          const navList = list.map(({ categoryType, categoryName }) => {
            return {
              goodsType: categoryType.toString(),
              goodsTypeName: categoryName
            }
          })
          this.navList = [{ goodsType: '', goodsTypeName: '所有' }, ...navList]
        }
      })
    },
    addressGet() {
      this.$apis.purchaseShopping
        .addressGet()
        .then(result => {
          if (result) {
            this.addressInfo = result
          }

          if (this.showOrderCom) {
            this.showOrderCom = false
            this.$refs.shoppingCartCom.validateGoodsNumber()
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 每页条数
    handleSizeChange(value) {
      // this.page.pageSize = value
      // this.getList()
    },

    // 页码
    handleCurrentChange(value) {
      this.page.pageNum = value
      this.listWithPagePurchaseInfo()
    }
  },
  beforeDestroy() {
    // this.$EventBus.$off('updateCarShopping')
  }
}
</script>
<style lang="scss" scoped>
::v-deep.mallContainer {
  max-width: 1350px;
  margin: 0 auto;
  overflow: scroll;

  .bg {
    background: #fff;
  }

  .d2-header-switch {
    display: none;
  }

  .d2-container-content {
    margin: 20px auto;
    background: #fff;
  }

  .shopMallCon {
    padding: 0 0 20px !important;
  }

  .goodsCon {
    box-sizing: border-box;
    padding: 0 40px;
    display: flex;
    // justify-content: space-between;
    flex-wrap: wrap;

    .goodsItemCon {
      box-sizing: border-box;
      width: 177px;
      height: 272px;
      display: flex;
      flex-direction: column;
      background: #f9f9f9;
      border-radius: 4px;
      // margin-bottom: 16px;
      margin: 0 16px 16px;
      overflow: hidden;
      padding: 8px 8px 16px;

      &:hover {
        border: 1px solid #5850ff;
      }

      &.active {
        border: 1px solid #5850ff;
      }

      .img {
        width: 157px;
        height: 157px;
        margin-bottom: 8px;
      }

      .goodsName {
        font-weight: 600;
        color: #333333;
        margin-bottom: 8px;
      }

      .purchaseOrderCount {
        font-size: 12px;
        color: #666666;
        margin-bottom: 16px;
      }

      .viewPurchase {
        font-size: 14px;
        color: #5850ff;
      }
    }

    .last {
      margin-right: auto;
    }
  }

  .emptyCom {
    display: flex;
    flex-direction: column;
    margin: 75px auto;
    text-align: center;

    .tips {
      font-size: 20px;
      color: #666;
      margin: 16px 0;
    }
  }

  .d2-container-full__body {
    overflow-x: hidden !important;
  }
}

.addressCon {
  padding: 10px 20px;

  .addressTitle {
    display: flex;
    align-items: center;

    .title {
      font-family: PingFangSC-Medium;
      font-weight: 600;
      font-size: 16px;
      color: #333333;
    }

    .edit {
      display: flex;
      align-items: center;
      margin-left: auto;
      font-size: 14px;
      color: #5850ff;
    }

    .editIcon {
      width: 20px;
      height: 20px;
    }
  }

  .icon {
    width: 32px;
    height: 32px;
    margin-right: 8px;
  }

  .addressInfo {
    display: flex;
    box-sizing: border-box;
    flex-wrap: wrap;
    // align-items: space-between;
    align-items: center;
    // justify-content: space-between;
    width: 100%;
    // height: 36px;
    padding: 15px 20px 0;
    margin-top: 10px;
    background: #f9f9f9;
    font-size: 14px;
    color: #666666;

    > span {
      margin-right: 25px;
      margin-bottom: 15px;
    }

    .label {
      color: #333333;
      // margin-left: 0px;
    }

    .address {
      min-width: 500px;
    }
  }
}

.searchCon {
  height: 65px;

  .show-search {
    width: 670px !important;
    min-width: 670px;
  }

  ::v-deep .name {
    width: 20px !important;
  }
}

::v-deep.classifyContainer {
  width: 100%;

  .el-tabs__nav {
    border-top: none !important;
  }
}
</style>