| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <template id="group-goods-preview">
- <div class="group-goods-preview">
- <components
- :is="styleName"
- :goods-list="goodsList"
- :active-item="activeItem"
- :title-style="titleStyle"
- :show-title="isShowTitle"
- :title="comData.title"
- :group-box="groupBox"
- :goods-style="goodsStyle"
- :btn-style="btnStyle"
- :bg-color="computedStyle.bgColor"
- ></components>
- </div>
- </template>
- <script>
- /**
- * @descriptions
- * 1. 组件名字必须对应模板形式 - 递归组件name
- * 2. 样式内容方法尽量内部维护 - 前端方便通用
- * 3. 父级组件会传预览数据 - activeItem
- */
- Vue.component('group-goods-preview', {
- name: "group-goods-preview",
- props: {
- activeItem: {
- type: Object,
- default () {
- return {}
- }
- }
- },
- template: '#group-goods-preview',
- computed: {
- computedStyle() {
- console.log(this.activeItem, 'this.activeItem.computedStyle')
- return this.activeItem.computedStyle
- },
- comData() {
- return this.activeItem.data
- },
- styleName() {
- var styleItem = this.activeItem.data.groupStyle || {}
- var name = {
- 1: "group-goods-style1",
- 2: "group-goods-style2",
- 3: "group-goods-style3"
- }
- var index = styleItem.type || 1
- return name[index]
- },
- titleStyle() {
- let {
- paddingTop,
- paddingBottom
- } = this.comData
- let style = {
- 'padding-top': paddingTop >= 0 ? `${paddingTop}px` : '10px',
- 'padding-bottom': paddingBottom >= 0 ? `${paddingBottom}px` : '10px'
- }
- return style
- },
- isShowTitle() {
- return this.comData.titleRadio || 0
- },
- groupBox() {
- let {
- marginTop,
- marginBottom,
- aroundMargin
- } = this.computedStyle
- return {
- margin: `${marginTop} ${aroundMargin} ${marginBottom}`,
- overflow: 'hidden'
- }
- },
- goodsStyle() {
- let {
- tabItem,
- searchIpts
- } = this.computedStyle
- let style = {
- 'margin-top': this.computedStyle.spacing,
- ...searchIpts
- }
- if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
- if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
- return style
- },
- btnStyle() {
- return {
- color: this.computedStyle.btnTextColor,
- background: this.computedStyle.btnBackground
- }
- },
- },
- watch: {
- "activeItem.data.goods": {
- handler(newVal, oldVal) {
- if (newVal && !deepEqual(newVal, oldVal)) {
- const ids = newVal.map(item => {
- return item.params.id
- })
- console.log(ids)
- this.getGoodsList(ids)
- }
- },
- immediate: true
- },
- goodsList: {
- handler(val) {
- if (val.length == 0) {
- this.goodsList = this.defaultList
- }
- },
- immediate: true
- }
- },
- data() {
- return {
- defaultList: [{
- cover_pic: "/resources/img/decorate/default_picture.png",
- end_at: 1640880000,
- goods_id: 0,
- goods_name: "商品名称",
- group_buy_price: 100,
- group_size: 3,
- group_status: 1,
- id: 22,
- price: 300,
- sheng: 200,
- start_at: 1639238400,
- total_num: 14
- }],
- goodsList: []
- }
- },
- methods: {
- getGoodsList(ids) {
- request({
- params: {
- r: '/group-buy/default/check-active-list',
- active_id: JSON.stringify(ids)
- },
- method: 'get'
- }).then(res => {
- this.goodsList = res.data.data
- })
- }
- }
- });
- </script>
- <style>
- </style>
|