<template>
    <view class="cu-modal" :class="{'show': visible}">
        <view class="cu-dialog wrapper">
            <view class="content">
                <view class="flex-align-center">
                    <image :src="resource.sell_change_title" webp style="width: 320rpx; height: 46rpx" />
                </view>
                <view class="input-wrapper marginY20 flex-align paddingX10">
                    <input v-model.trim="price" class="flex1 color-white" />
                    <image v-if="price" @click="price = ''" :src="resource.weal_cancel" webp style="width: 32rpx;height: 32rpx" />
                </view>
                <view class="flex-align-between">
                    <image :src="resource.modal_cancel" webp style="width: 254rpx;height:92rpx" @click="close" />
                    <image :src="resource.modal_ok" webp style="width: 254rpx;height:92rpx" @click="apply" />
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import { throttle } from '@/utils'
import resource from '@/utils/resource'

export default {
    data() {
        return {
            resource,
            visible: false,
            price: '',
            index: null,
            goodsId: null
        }
    },
    computed: {},
    methods: {
        show(index, goodsId) {
            this.$parent.$parent.$parent.lock = true
            this.index = index
            this.goodsId = goodsId
            this.price = ''
            this.visible = true
        },
        async apply() {
            if (!this.price) return
            throttle.call(this.realApply)
        },
        async realApply() {
            const res = await this.$service.sell.change(this.goodsId, this.price)
            if (res) {
                this.$emit('success', { index: this.index, price: this.price })
                this.close()
            } else {
                this.price = ''
            }
        },
        close() {
            this.$parent.$parent.$parent.lock = false
            this.visible = false
            this.index = null
            this.goodsId = null
        }
    }
}
</script>
<style lang="scss" scoped>
.mask {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
}
.wrapper {
    width: 100%;
    margin-top: -100px;
    background: transparent;
    .content {
        padding: 40rpx 60rpx;
        margin: 0 20px;
        background: #000000;
        border-radius: 16px;
        border: 4px solid;
        border-image: linear-gradient(180deg, rgba(89, 55, 195, 1), rgba(169, 27, 136, 1)) 2 2;
        .input-wrapper {
            height: 100rpx;
            background: rgba(0, 0, 0, 0.5);
            box-shadow: 0px 0px 8rpx 4rpx rgba(147, 67, 255, 0.3);
            border-radius: 8rpx;
            border: 2rpx solid rgba(174, 231, 255, 0.5);
        }
    }
}
</style>