index.vue 9.59 KB
<!-- 选择商品 - 单选 -->
<template>
  <!--    :okText="productList.length ? '确定' : '创建商品'" -->
  <GLDialog
    class="single-pro"
    :bigTitle="!multiple?'选择商品':`选择商品(已选${infoIdList.length}项)`"
    mode="big"
    :before-close="handleSingleSelectClose"
    :okText="'确定'"
    :visible.sync="isSingleSelectVisible"
    @onOk="handleSingleSelectConfirm"
    @onCancel="handleSingleSelectClose"
  >

    <div
      class="single-pro-box"
      v-loading="loading"
    >
      <div
        class="noproDiv"
        v-if="!productList.length && fnCallBack"
      >
        <img src="@/assets/noPro.png" />
        <p class="noproP">系统暂无已创建的商品</p>
      </div>
      <template v-if="multiple">
        <el-checkbox-group
          v-model="infoIdList"
          v-if="productList.length"
          class="pro-group"
          :max="multipleMax"
        >
          <el-checkbox
            :class="['pro-box', infoIdList.includes(item.id) ? 'active' : '']"
            v-for="item in productList"
            :key="item.id"
            :label="item.id"
          >
            <!-- <img
              v-show="infoIdList.includes(item.id)"
              class="icon-check"
              src="@/assets/icon-check.png"
            /> -->
            <div
              class="icon-number icon-check"
              v-show="infoIdList.includes(item.id)"
            >{{infoIdList.findIndex(e => item.id == e) + 1}}</div>
            <img
              class="goods-img"
              :src="item.goodsImage"
            />
            <div class="txt-box">
              <p
                :title="item.goodsName"
                class="ellipsis"
              >{{ item.goodsName }}</p>
              <p class="f-s-12">销量:{{ item.saleAmount }}</p>
              <p class="f-s-12">库存:{{ item.goodsStock }}</p>
              <p class="f-s-12">零售价:{{ item.retailPrice }}</p>
              <p
                :title="item.merchantName"
                class="ellipsis f-s-12"
              >门店名称:{{ item.merchantName }}</p>
            </div>
          </el-checkbox>
        </el-checkbox-group>
      </template>
      <template v-else>
        <el-radio-group
          v-model="infoId"
          v-if="productList.length"
          class="pro-group"
        >
          <el-radio
            :class="['pro-box', item.id == infoId ? 'active' : '']"
            v-for="item in productList"
            :key="item.id"
            :label="item.id"
          >
            <img
              v-show="item.id == infoId"
              class="icon-check"
              src="@/assets/icon-check.png"
            />
            <img
              class="goods-img"
              :src="item.goodsImage"
            />
            <div class="txt-box">
              <p
                :title="item.goodsName"
                class="ellipsis"
              >{{ item.goodsName }}</p>
              <p class="f-s-12">销量:{{ item.saleAmount }}</p>
              <p class="f-s-12">库存:{{ item.goodsStock }}</p>
              <p class="f-s-12">零售价:{{ item.retailPrice }}</p>
              <p
                :title="item.merchantName"
                class="ellipsis f-s-12"
              >门店名称:{{ item.merchantName }}</p>
            </div>
          </el-radio>
        </el-radio-group>
      </template>
    </div>
  </GLDialog>
</template>

<script>
// import { getGoodsList } from '@/api/modules/common'
export default {
  name: 'selectSingleProDialog',
  data () {
    return {
      userInfo: {},
      infoId: '',
      minRatilPrice: '',
      productList: [],
      fnCallBack: false,
      infoIdList: [],
      loading: true
    }
  },

  props: {
    isSingleSelectVisible: {
      type: Boolean,
      default: false
    },
    selectedProInfo: [Object, Array],
    merchantId: {
      type: String,
      required: true
    },
    multiple: Boolean,
    multipleMax: {
      type: Number,
      default: 5
    }
  },

  computed: {},

  mounted () {
    const { multiple } = this
    this.userInfo = this.$globalState.session
    if (!multiple) this.infoId = this.selectedProInfo.id
    this.getList()
  },

  methods: {
    getList () {
      const { multiple, selectedProInfo } = this
      var params = {
        goodsStatus: 1,
        isActivityUsing: 1,
        goodsSources: multiple? [3] :[1, 3],//众筹活动不能取门店自建商品
        pageNum: 1,
        pageSize: 100000,
        deliveryType: 1,
        merchantId: this.merchantId
      }
      var that = this
      this.$apis.common.getMerchantGoodsListApi(params).then(res => {
        this.loading = false
        // console.log(res)
        this.fnCallBack = true
        this.productList = res.list
        if (multiple) {
          selectedProInfo.length && selectedProInfo.map(e => {
            if (e.id) this.infoIdList.push(e.id)
          })
        }
        this.productList.forEach(function (item) {
          item.saleAmount = item.goodsStatistics.saleAmount
          if (item.specificationDetailList && item.specificationDetailList.length > 1) {
            let retailPriceList = item.specificationDetailList.sort(function (a, b) {
              return a.retailPrice - b.retailPrice
            })
            let stockeList = item.specificationDetailList.sort(function (a, b) {
              return a.stock - b.stock
            })
            let minRatilPrice = retailPriceList[0].retailPrice / 100
            let maxRatilPrice = retailPriceList[retailPriceList.length - 1].retailPrice / 100
            let minStock = stockeList[0].stock
            let maxStock = stockeList[stockeList.length - 1].stock
            item.retailPrice = minRatilPrice == maxRatilPrice ? minRatilPrice.toFixed(2) : minRatilPrice.toFixed(2) + '-' + maxRatilPrice.toFixed(2)
            item.minRatilPrice = minRatilPrice.toFixed(2)
            item.goodsStock = minStock == maxStock ? minStock : minStock + '-' + maxStock
          } else if (item.specificationDetailList && item.specificationDetailList.length == 1) {
            item.retailPrice = (item.specificationDetailList[0].retailPrice / 100).toFixed(2)
            item.minRatilPrice = item.retailPrice
            item.goodsStock = item.specificationDetailList[0].stock
          } else {
            item.retailPrice = (item.retailPrice / 100).toFixed(2)
            item.minRatilPrice = item.retailPrice
          }
        })
      })
    },
    handleSingleSelectConfirm () {
      const { multiple, infoIdList } = this
      if (!this.productList.length) {
        var params = {
          addOrEdit: 1,
          groupOrStore: this.userInfo.accountLevel == 4 ? 2 : 1,
          $title: '新建商品'
        }
        this.$router.push({
          path: '/productGroup/editProduct',
          query: params
        })
        return true
      }
      if (multiple) {
        if (infoIdList.length < 1) return this.$message({
          message: '请选择商品',
          type: 'error',
          customClass: 'message-Z-zinde'
        })
        const list = []
        infoIdList.map(e => {
          list.push(this.productList.find(item => item.id === e))
        })
        this.$emit('handleSingleSelectConfirm', list)
      } else {
        if (!this.infoId) {
          this.$message({
            message: '请选择商品',
            type: 'error',
            customClass: 'message-Z-zinde'
          })
          return true
        }
        var selectInfo = this.productList.find(item => item.id === this.infoId)
        this.$emit('handleSingleSelectConfirm', selectInfo)
      }

    },
    handleSingleSelectClose () {
      this.$emit('handleSingleSelectClose')
    }
  }
}
</script>
<style lang="scss">
.single-pro .pro-group {
  // margin-left: 50px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px 14px;
  padding-bottom: 20px;
  .el-checkbox {
    margin-right: 0 !important;
    transition: all 0.25s;
  }
  .is-disabled {
    opacity: 0.5;
  }
  .el-checkbox__input {
    opacity: 0 !important;
    position: absolute;
  }
  .el-checkbox__label {
    padding-left: 0 !important;
  }
}
.single-pro-box {
  min-height: 20vh;
  max-height: 60vh;
  transition: all 0.25s;
}
.single-pro .pro-box {
  // width: 202px;
  width: 246px;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  transition: all 0.25s;
  // margin: 0 40px 20px 0;
}
.single-pro .pro-box:nth-child(4n) {
  // margin: 0 20px 20px 0;
}
.single-pro .pro-box.active {
  box-shadow: 0px 6px 20px 0px rgba(122, 122, 122, 0.2);
  border: 1px solid #5850ff;
}
.single-pro .el-radio__inner {
  display: none;
}
.single-pro .icon-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  line-height: 1;
  font-size: 20px;
  font-weight: 700;
}
.icon-number {
  background-color: #5850ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  overflow: hidden;
}
.single-pro p {
  margin: 0 0 8px 0;
}
.single-pro .f-s-12 {
  font-size: 12px;
}
.single-pro .pro-box .goods-img {
  width: 184px;
  height: 184px;
  display: block;
  margin: 20px auto 0;
}
.single-pro .el-radio__input {
  position: absolute;
  top: 8px;
  left: 8px;
}
.single-pro .el-radio__label {
  padding: 0;
}
.single-pro .txt-box {
  padding: 16px 20px 0;
  color: #666666;
  width: 246px;
  box-sizing: border-box;
}
.single-pro .ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.noproP {
  width: 100%;
  height: 20px;
  font-family: PingFangSC-Medium;
  font-size: 16px;
  color: #666666;
  line-height: 20px;
  font-weight: 500;
  text-align: center;
}
.noproDiv {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
</style>