Commit 99d6018b by 李伟康

feat(OrderPopup): 弹窗组件化改造

- 新增通用 Popup 组件,提高弹窗的复用性
- 重构 OrderPopup 组件,使用新的 Popup 组件替换原有的 uni-popup
- 新增 SkuPopup 组件,用于展示 SKU 商品列表
- 优化 SkuGoodsList 组件,移除冗余代码
1 parent e7cdbaa8
<template>
<uni-popup
ref="popup"
:type="position"
:is-mask-click="maskClick"
:animation="animation"
>
<view :class="['popup-box',{'right-box':position=='right'}]">
<slot></slot>
<view class="popup-footer flex">
<view
class="popup-btn popup-cancel"
@click="cancel"
>取消</view>
<view
class="popup-btn popup-confirm"
@click="confirm"
>确定</view>
</view>
</view>
</uni-popup>
</template>
<script type='text/ecmascript-6'>
export default {
name: '',
props: {
animation: {
type: Boolean,
default: true
},
maskClick: {
type: Boolean,
default: false
},
position:{
type: String,
default: 'bottom'
}
},
data () {
return {
}
},
computed: {
},
mounted () {
},
methods: {
open () {
this.$refs.popup.open()
},
cancel () {
this.$refs.popup.close()
this.$emit('onCancel')
},
close () {
this.$refs.popup.close()
this.$emit('close')
},
confirm () {
this.$emit('onConfirm')
},
}
}
</script>
<style scoped lang='scss'>
.popup-box {
border-radius: 32rpx 32rpx 0 0;
background: #ffffff;
height: 70vh;
.popup-footer {
padding: 64rpx 0;
justify-content: center;
gap: 0 32rpx;
.popup-btn {
display: flex;
align-items: center;
justify-content: center;
width: 720rpx;
height: 80rpx;
border-radius: 64rpx;
background: #f0f1f5;
color: #333333;
font-size: 32rpx;
font-weight: 500;
}
.popup-confirm {
color: #fff;
background: linear-gradient(0deg, #2c66f7 0%, #48a6ff 100%);
}
}
}
.right-box {
width: 46vw;
height: 100vh;
border-radius: 32rpx 0 0 32rpx;
.popup-footer {
margin: 0 48rpx;
}
}
</style>
\ No newline at end of file
......@@ -85,7 +85,7 @@
</template>
<script type='text/ecmascript-6'>
import NP from 'number-precision'
export default {
name: 'GoodsList',
inject: ['userInfo', 'baseConfigData'],
......@@ -270,7 +270,9 @@ export default {
})
goodsList[index].multipleSpecificationsGoods.skuGoodsList = goodsArr
// let chooseList = await this.getChooseList(false);
this.$refs.sukRef.open(goodsList[index])
// this.$refs.skuPopupRef.open()
this.$emit('openSkuPopup',goodsList[index])
this.list = goodsList
}
} else {
......@@ -300,7 +302,6 @@ export default {
item.value = ''
})
this.list = goodsList
console.log(33333, goodsList)
// this.setData({
// goodsList
// }, () => {
......
<template>
<popup
ref="popup"
@onConfirm="confirm"
@onCancel="cancel"
>
<view class="popup-title flex">
确认需购买的商品
<view
class="popup-close flex"
@click="close"
>
<uni-icons
type="closeempty"
size="16"
></uni-icons>
</view>
</view>
<view class="popup-tips">温馨提示:请仔细确认当前售价,避免录错单</view>
<view class="popup-body">
<scroll-view
scroll-y
class="popup-scroll-view"
>
<view class="goods-list">
<template v-for="(i, index) in data.multipleSpecificationsGoods.skuGoodsList">
<view
:key="index"
@click="choose(i)"
:class="['item flex',{active: i.goodsId == currentId }]"
>
<view class="sprite-icon icon-tag-checked"></view>
<view class="text">
<view class="name"> {{data.multipleSpecificationsGoods.baseGoodsName}}</view>
<view
class="alias"
v-if="i.goodsAlias"
>
商品别名:{{i.goodsAlias}}
</view>
<view
class="position"
v-if="i.specificationStr "
>{{i.specificationStr}}</view>
</view>
<view class="price">¥<text class="price-num">{{i.sellPrice}}</text>x1</view>
</view>
</template>
</view>
</scroll-view>
</view>
</popup>
</template>
<script type='text/ecmascript-6'>
import Popup from './Popup.vue'
export default {
components: {
Popup,
},
name: '',
props: {
},
data () {
return {
data: {},
currentId: ''
}
},
mounted () {
},
methods: {
open (data) {
this.data = data
this.$nextTick(() => {
this.$refs.popup.open()
})
},
cancel () {
this.$refs.popup.close()
this.$emit('cancel')
},
close () {
this.$refs.popup.close()
this.$emit('close')
},
choose (i) {
let { currentId } = this
if (currentId == i.goodsId) {
this.currentId = ''
return
}
this.currentId = i.goodsId
},
confirm () {
let { currentId, data } = this,
{ baseGoodsName, id, specificationGoodsMap, specificationList, skuGoodsList } = data.multipleSpecificationsGoods
if (!currentId) return uni.showToast({
title: '请勾选商品',
})
let goods = skuGoodsList.find(e => e.goodsId == currentId)
this.$emit('onConfirm', {
count: 1,
goods: null,
goodsFlag: 2,
isFlag: true,
multipleSpecificationsGoods: {
baseGoodsName,
id,
specificationGoodsMap,
specificationList,
goods
}
})
this.close()
},
}
}
</script>
<style scoped lang='scss'>
.popup-box {
border-radius: 32rpx 32rpx 0 0;
background: #ffffff;
height: 70vh;
.popup-title {
height: 104rpx;
justify-content: center;
position: relative;
color: #333333;
font-size: 36rpx;
font-weight: 500;
.popup-close {
position: absolute;
height: 100%;
top: 0;
right: 0;
padding: 0 48rpx;
font-weight: 400;
color: #1a1a1a;
}
}
.popup-tips {
color: #999ea8;
font-size: 28rpx;
padding-left: 48rpx;
}
.popup-body {
height: calc(100% - 350rpx);
.popup-scroll-view {
height: 100%;
padding-top: 24rpx;
.goods-list {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 32rpx;
margin: 0 48rpx;
.item {
height: 176rpx;
border-radius: 8rpx;
border: 2rpx solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: 32rpx;
box-sizing: border-box;
padding: 0 32rpx;
background: #f5f7fa;
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
.text {
color: #666666;
font-size: 24rpx;
line-height: 36rpx;
.name {
color: #333333;
font-size: 28rpx;
font-weight: 500;
margin-bottom: 8rpx;
line-height: 40rpx;
}
.alias {
margin-bottom: 8rpx;
}
}
.price {
margin-left: auto;
color: #333333;
font-size: 28rpx;
font-weight: 500;
&-num {
margin-right: 16rpx;
}
}
}
.active {
border-color: #4673ff;
background: #4673ff1a;
.sprite-icon {
display: block;
}
}
}
}
}
}
</style>
\ No newline at end of file
<template>
<uni-popup
ref="popup"
:type="position"
:is-mask-click="maskClick"
:animation="animation"
>
<view :class="['popup-box',{'right-box':position=='right'}]">
<view class="order-popup">
<popup
:position="position"
:animation="animation"
ref="popup"
@onConfirm="confirm"
@onCancel="cancel"
>
<view class="popup-title flex">
{{title}}
<view
......@@ -53,26 +54,21 @@
:dataKey="dataKey"
ref="componentRef"
@choose="chooseContent = $event"
@openSkuPopup="openSkuPopup"
></component>
</scroll-view>
</view>
<view class="popup-footer flex">
<view
class="popup-btn popup-cancel"
@click="cancel"
>取消</view>
<view
class="popup-btn popup-confirm"
@click="confirm"
>确定</view>
</view>
</view>
</uni-popup>
</popup>
<sku-popup
ref="skuPopupRef"
@onConfirm="skuConfirm"
></sku-popup>
</view>
</template>
<script type='text/ecmascript-6'>
import Popup from './components/Popup.vue'
import config from './config'
import EmployeeList from './components/EmployeeList.vue'
import DiversionMerchant from './components/DiversionMerchant.vue'
......@@ -81,15 +77,18 @@ import CouponList from './components/CouponList.vue'
import GoodsList from './components/GoodsList.vue'
import PackageList from './components/PackageList.vue'
import SkuGoodsList from './components/SkuGoodsList.vue'
import SkuPopup from './components/SkuPopup.vue'
export default {
components: {
Popup,
EmployeeList,
DiversionMerchant,
CarModelList,
CouponList,
GoodsList,
PackageList,
SkuGoodsList
SkuGoodsList,
SkuPopup
},
name: '',
props: {
......@@ -192,6 +191,16 @@ export default {
this.$refs.popup.close()
}
},
openSkuPopup (data) {
this.confirm()
this.$refs.skuPopupRef.open(data)
},
skuConfirm (e) {
this.$emit('onConfirm', {
chooseContent: [e],
popupType: 12
})
},
clear () {
this.componentObject.searchValue = ''
this.handleSearch()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!