|
@@ -1,8 +1,26 @@
|
|
|
import request from '@/helpers/request'
|
|
|
import { moneyFormat } from '@/helpers/utils'
|
|
|
-import { Swipe, SwipeItem, Image, CellGroup, Cell, ImagePreview } from 'vant'
|
|
|
+import {
|
|
|
+ Swipe,
|
|
|
+ SwipeItem,
|
|
|
+ Image,
|
|
|
+ CellGroup,
|
|
|
+ Cell,
|
|
|
+ ImagePreview,
|
|
|
+ RadioGroup,
|
|
|
+ Radio,
|
|
|
+ Tag,
|
|
|
+ Row,
|
|
|
+ Col,
|
|
|
+ Sticky,
|
|
|
+ ActionBar,
|
|
|
+ ActionBarButton,
|
|
|
+ ActionBarIcon,
|
|
|
+ Icon
|
|
|
+} from 'vant'
|
|
|
import { defineComponent } from 'vue'
|
|
|
import styles from './index.module.less'
|
|
|
+import iconShopCart from '../images/icon-shop-cart.png'
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'goods-detail',
|
|
@@ -11,19 +29,58 @@ export default defineComponent({
|
|
|
return {
|
|
|
id: query.id,
|
|
|
albumPics: [],
|
|
|
- product: {} as any
|
|
|
+ product: {} as any,
|
|
|
+ radio: '',
|
|
|
+ skuStockListTemp: [],
|
|
|
+ detailMobileHtml: '',
|
|
|
+ loading: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ skuStockList() {
|
|
|
+ // 处理规格
|
|
|
+ const product = this.product
|
|
|
+ const skuStockList: any =
|
|
|
+ this.skuStockListTemp.length > 0
|
|
|
+ ? this.skuStockListTemp
|
|
|
+ : [
|
|
|
+ {
|
|
|
+ id: -1,
|
|
|
+ price: product.price,
|
|
|
+ pic: product.pic,
|
|
|
+ stock: product.stock,
|
|
|
+ spData: null
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ skuStockList.forEach((item: any) => {
|
|
|
+ if (item.spData) {
|
|
|
+ const spData = JSON.parse(item.spData)
|
|
|
+ let str = ''
|
|
|
+ spData.forEach((sp: any) => {
|
|
|
+ str += `${sp.value}`
|
|
|
+ })
|
|
|
+ item.spDataJson = str
|
|
|
+ } else {
|
|
|
+ item.spDataJson = '默认'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return skuStockList
|
|
|
}
|
|
|
},
|
|
|
async mounted() {
|
|
|
try {
|
|
|
+ this.loading = true
|
|
|
const res = await request.get(
|
|
|
`/api-mall-portal/product/detail/${this.id}`
|
|
|
)
|
|
|
+ this.loading = false
|
|
|
const result = res.data || {}
|
|
|
this.albumPics = result.product.albumPics
|
|
|
? result.product.albumPics.split(',')
|
|
|
- : []
|
|
|
+ : [result.product.pic]
|
|
|
this.product = result.product
|
|
|
+ this.skuStockListTemp = result.skuStockList || []
|
|
|
+ this.detailMobileHtml = result.product.detailMobileHtml
|
|
|
} catch {}
|
|
|
},
|
|
|
methods: {
|
|
@@ -34,6 +91,26 @@ export default defineComponent({
|
|
|
startPosition: index,
|
|
|
closeable: true
|
|
|
})
|
|
|
+ },
|
|
|
+ onShowImg(target: any) {
|
|
|
+ const { localName } = target.srcElement
|
|
|
+ if (localName !== 'img') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let startPosition = 0
|
|
|
+ const domList = document.querySelectorAll('.msgWrap img')
|
|
|
+ let imgList = Array.from(domList).map((item: any, index: number) => {
|
|
|
+ if (target.srcElement == item) {
|
|
|
+ startPosition = index
|
|
|
+ }
|
|
|
+ return item.src
|
|
|
+ })
|
|
|
+
|
|
|
+ ImagePreview({
|
|
|
+ images: imgList,
|
|
|
+ startPosition: startPosition,
|
|
|
+ closeable: true
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
render() {
|
|
@@ -44,11 +121,12 @@ export default defineComponent({
|
|
|
class={styles.swipe}
|
|
|
lazyRender
|
|
|
v-slots={{
|
|
|
- indicator: (item: any) => (
|
|
|
- <div class={styles['custom-indicator']}>
|
|
|
- {(item.active || 0) + 1} / {item.total}
|
|
|
- </div>
|
|
|
- )
|
|
|
+ indicator: (item: any) =>
|
|
|
+ item.total > 1 && (
|
|
|
+ <div class={styles['custom-indicator']}>
|
|
|
+ {(item.active || 0) + 1} / {item.total}
|
|
|
+ </div>
|
|
|
+ )
|
|
|
}}
|
|
|
>
|
|
|
{this.albumPics.map((item: string, index: number) => (
|
|
@@ -78,8 +156,8 @@ export default defineComponent({
|
|
|
¥{moneyFormat(product.originalPrice)}
|
|
|
</del>
|
|
|
</div>
|
|
|
- ),
|
|
|
- default: () => <div class={styles.stock}>销量4件</div>
|
|
|
+ )
|
|
|
+ // default: () => <div class={styles.stock}>销量4件</div>
|
|
|
}}
|
|
|
/>
|
|
|
|
|
@@ -90,6 +168,75 @@ export default defineComponent({
|
|
|
titleClass={[styles.goodsName, 'van-ellipsis']}
|
|
|
/>
|
|
|
</CellGroup>
|
|
|
+
|
|
|
+ <Row class={[styles.row, 'mb12']}>
|
|
|
+ <Col span={4} class={styles.col}>
|
|
|
+ 规格
|
|
|
+ </Col>
|
|
|
+ <Col span={20}>
|
|
|
+ <RadioGroup
|
|
|
+ class={styles['radio-group']}
|
|
|
+ modelValue={this.radio}
|
|
|
+ onUpdate:modelValue={val => (this.radio = val)}
|
|
|
+ >
|
|
|
+ {this.skuStockList.map((item: any) => {
|
|
|
+ const isActive = item.id === this.radio
|
|
|
+ const type = isActive ? 'primary' : 'default'
|
|
|
+ return (
|
|
|
+ <Radio
|
|
|
+ class={styles.radio}
|
|
|
+ name={item.id}
|
|
|
+ disabled={item.stock === 0}
|
|
|
+ onClick={() => {
|
|
|
+ // 判断是否有库存
|
|
|
+ if (item.stock === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.radio = item.id
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Tag size="large" plain={isActive} type={type}>
|
|
|
+ {item.spDataJson}
|
|
|
+ </Tag>
|
|
|
+ </Radio>
|
|
|
+ )
|
|
|
+ })}
|
|
|
+ </RadioGroup>
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ {this.detailMobileHtml && (
|
|
|
+ <div class={[styles.section]}>
|
|
|
+ <div class={styles.detail}>
|
|
|
+ <span>图文详情</span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div
|
|
|
+ class={[styles.photoDetail, 'msgWrap']}
|
|
|
+ onClick={this.onShowImg}
|
|
|
+ v-html={this.detailMobileHtml}
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {!this.loading && (
|
|
|
+ <ActionBar class={styles.actionBar}>
|
|
|
+ <ActionBarIcon
|
|
|
+ icon="cart-o"
|
|
|
+ // text="购物车"
|
|
|
+ v-slots={{
|
|
|
+ icon: () => <Icon name={iconShopCart} size={30} />
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <div class={styles.buyGroup}>
|
|
|
+ <ActionBarButton
|
|
|
+ type="primary"
|
|
|
+ class={styles.addCertBtn}
|
|
|
+ text="加入购物车"
|
|
|
+ />
|
|
|
+ <ActionBarButton type="primary" text="立即购买" />
|
|
|
+ </div>
|
|
|
+ </ActionBar>
|
|
|
+ )}
|
|
|
</div>
|
|
|
)
|
|
|
}
|