<template>
    <page title="发布商品" ref="pageRef" light nav-color="transparent">

        <view class="wrapper">
            <view class="flex-align padding14">
                <image :src="resource.weal_create_remind" style="width: 32rpx; height: 32rpx" />
                <view class="font2 color-white marginL10">
                    发布商品发布商品发布商品发布商品发布商品发布商品
                </view>
            </view>
            <view class="content-wrapper">
                <view class="paddingY20">
                    <view class="title">商品：</view>
                    <view class="flex-wrap paddingT17 flex-align">
                        <view v-if="goods" class="item">
                            <view class="marginT11 flex-align-center">
                                <image :src="goods.spu.cover" mode="aspectFill" class="image" />
                            </view>
                            <image
                                :src="LEVEL_MAP[goods.level].titleImg"
                                class="title-level translateX"
                            />
                            <image
                                :src="resource.weal_create_minus"
                                class="minus"
                                @click="minus()"
                            />
                        </view>
                        <view v-else class="add flex-column-align-center" @click="showStoreChoose">
                            <image
                                :src="resource.weal_create_plus"
                                style="width: 32rpx; height: 32rpx"
                            />
                            <view class="color-white font4 paddingT18">选择商品</view>
                        </view>
                    </view>
                </view>
                <view class="flex-align paddingB20 line">
                    <view class="title">商品名称：</view>
                    <view class="flex1 color-white">{{ goods.spu.name }}</view>
                </view>
                <view class="flex-align paddingY20 line">
                    <view class="title">商品价格：</view>
                    <view class="flex1">
                        <input
                            v-model.trim="price"
                            type="number"
                            placeholder="请输入商品价格"
                            class="input"
                            maxlength="15"
                        />
                    </view>
                </view>
            </view>
            <view class="bottom-wrapper flex-align-center">
                <image :src="resource.sell_btn_create" webp class="btn-create" @click="submit" />
            </view>
        </view>
    </page>
</template>

<script>
import resource from '@/utils/resource'
import { LEVEL_MAP } from '@/utils/config'
export default {
    data() {
        return {
            resource,
            LEVEL_MAP,
            price: '',
            goods: null
        }
    },
    onLoad(options) {
        this.$event.on(this.$event.key.STORE_CHOOSE, (map) => {
            this.goods = Object.values(map)[0]
        })
    },
    onUnload() {
        this.$event.off(this.$event.key.STORE_CHOOSE)
    },
    methods: {
        minus() {
            this.goods = null
        },
        showStoreChoose() {
            if (this.goods) {
                this.$cache.set(this.$cache.key.STORE_CHOOSE, { [this.goods.id]: this.goods })
            }
            this.$router.push('store-choose', { single: true })
        },
        submit() {
            if (!this.goods || !this.price) {
                this.$message.error('请完善表单')
                return
            }
            this.$message.confirm('确定要发布商品吗？', () => {
                this.realSubmit()
            })
        },
        async realSubmit() {}
    }
}
</script>
<style>

</style>
<style lang="scss" scoped>
.bg {
    position: fixed;
    z-index: -1;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
}
.wrapper {
    padding-bottom: 176rpx;
}
.content-wrapper {
    margin: 0 14px;
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0px 0px 4px 2px rgba(147, 67, 255, 0.3);
    border: 1px solid rgba(174, 231, 255, 0.5);
    padding: 0 22rpx;
    .title {
        width: 160rpx;
        color: #fff;
        font-size: 32rpx;
    }
    .line {
        // box-shadow: inset 0px 2rpx 20rpx 60rpx rgba(0,0,0,0.55);
        border-bottom: 2rpx solid rgba(255, 255, 255, 0.1);
    }
    .item,
    .add {
        width: 192rpx;
        height: 256rpx;
        border-radius: 8rpx;
        margin-right: 20rpx;
        position: relative;
        background: #363748;
        box-shadow: 0px 0px 8rpx 0px rgba(167, 110, 244, 0.5);
        margin-block: 20rpx;
    }
    .item {
        .image {
            width: 156rpx;
            height: 194rpx;
            border-radius: 8rpx;
        }
        .num {
            position: absolute;
            left: 0;
            top: 0;
            height: 24rpx;
            line-height: 24rpx;
            border-radius: 8rpx 0px 8rpx 0px;
            font-size: 24rpx;
            font-weight: bold;
            padding: 0 24rpx;
            color: #fff;
        }
        .title-level {
            position: absolute;
            bottom: 2rpx;
            width: 112rpx;
            height: 48rpx;
        }
        .minus {
            position: absolute;
            right: -5rpx;
            top: -5rpx;
            width: 32rpx;
            height: 32rpx;
        }
    }
}
.bottom-wrapper {
    background: #222335;
    padding-bottom: 48rpx;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
}
.btn-create {
    width: 616rpx;
    height: 128rpx;
}
.input {
    height: 32rpx;
    color: #fff;
}
</style>