reason.vue 5.55 KB
<template>
    <div v-if="product.checked" class="reason">
        <div class="select-reason">
            <slot name="type">退货原因</slot>

            <span class="icon iconfont">&#xe604;</span>
            <select class="reason" v-model="product.reason.id" @change="changeReason(product.reason.id)" name="reason">
                <option v-for="(reason, index) in reasons" :key="index" :value="reason.id" :selected="reason.id === product.reason.id">{{reason.name}}</option>
            </select>
        </div>
        <template v-if="specialReasons.indexOf(product.reason.id) !== -1">
            <div class="remark">
                <textarea v-model="product.remark" max-length="100" placeholder="退货原因说明"></textarea>
            </div>
            <div class="image-list clearfix">
                <div class="image-item" v-for="(image, index) in imageListForShow" :key="index">
                    <span @click="deleteImage(image.index)" class="icon iconfont icon-close">&#xe623</span>
                    <img :src="image.path | resize(100, 130)">
                </div>
                <upload v-show="imageListForShow.length < 4" class="image-item" :image-list="product.imageList" :bucket="bucket"></upload>
            </div>
        </template>
    </div>
    <div v-else></div>
</template>

<script>
    const upload = require('components/tools/upload.vue');
    const util = require('plugin/util');
    const tip = require('plugin/tip');
    const reasonConfig = require('home/return/reason');

    module.exports = {
        props: ['product', 'data'],
        data() {
            console.log(this);
            return {
                bucket: 'evidenceImages',
                reasons: [],
                specialReasons: []
            };
        },
        computed: {
            imageListForShow() {
                const list = [];

                this.product.imageList.forEach((path, index) => {
                    list.push({
                        index: index,
                        path: util.getImgHost(path, this.bucket) + '?imageView2/2/w/160/h/160'
                    });
                });

                return list;
            }
        },
        methods: {
            deleteImage(index) {
                this.product.imageList.splice(index, 1);
            },
            changeReason(rid) {
                if (this.product.change &&
                    this.product.change.sku === this.product.productSku &&
                    this.specialReasons.indexOf(rid) === -1) {
                    this.product.change = null;
                    tip.show('无理由换货不可选择相同颜色尺码');
                }
            }
        },
        components: {
            upload
        },
        created() {
            this.reasons = reasonConfig.reasons;
            this.specialReasons = reasonConfig.specialReasons;
        }
    };

</script>

<style>
    .reason {
        font-size: 32px;
        background: #f6f6f6;
        border-top: 1px solid #f1f1f1;
        border-bottom: 1px solid #f1f1f1;

        .select-reason {
            padding: 0 30px;
            width: 100%;
            height: 90px;
            line-height: 90px;
            background: #fff;
            overflow: hidden;

            select {
                direction: rtl;
                height: 90px;
            }

            .icon,
            .reason {
                line-height: 90px;
                float: right;
                color: #b0b0b0;
            }

            .reason {
                margin-right: 6px;
            }
        }

        .remark {
            background: #fff;
            position: relative;

            &:before {
                content: "";
                position: absolute;
                left: 30px;
                right: 0;
                top: 0;
                border-bottom: 1px solid #f1f1f1;
            }

            textarea {
                width: 100%;
                font-size: 24px;
                resize: none;
                border: 1px solid #f1f1f1;
                border-radius: 5px;
                padding: 15px 20px;
            }
        }

        .image-list {
            padding: 30px;
            padding-top: 0;
            background: #fff;

            .image-item {
                position: relative;
                float: left;
                margin-right: 25px;
                margin-top: 25px;
                width: 154px;
                height: 154px;

                &:last-child {
                    margin-right: 0;
                }

                .icon-close {
                    position: absolute;
                    right: -20px;
                    top: -20px;
                    color: #fff;
                    background-color: red;
                    border-radius: 100%;
                    z-index: 2;
                    width: 40px;
                    height: 40px;
                    font-size: 30px;
                    text-align: center;
                }

                img {
                    width: 100%;
                    height: 100%;
                }
            }

            .label-input {
                position: relative;
                width: 150px;
                height: 150px;
                font-size: 150px;

                &:before {
                    content: "\e604";
                }

                input {
                    position: absolute;
                    left: 0;
                    top: 0;
                    width: 0;
                    height: 0;
                    opacity: 0;
                }
            }
        }
    }
</style>