step3.vue 13.1 KB
<template>
    <div>
        <Row>
            <Form :label-width="100">
                <Row>
                    <div class="create-group">
                        <span class="create-group-indicator"></span>
                        <span class="create-group-title">网销信息</span>
                        <span class="create-group-sub-title">(商品上架销售需要完成必填项信息)</span>
                    </div>
                </Row>

                <Row>
                    <Col>
                    <div class="create-item-title">商品颜色主图
                        <span class="create-group-sub-title">(商品正面图默认为用户选择商品颜色和展示使用。用户从不同频道查看商品,优先展示频道封面图)</span>
                    </div>
                    </Col>
                </Row>

                <Row v-for="good,goodIndex in product.goods" :key="good">
                    <Col span="4">
                        <div class="color-item-title">
                            <span>{{good.goodsName}}({{good.factoryGoodsName}})</span>
                        </div>
                    </Col>

                    <Col span="4">
                        <div class="upload-item">
                            <div class="upload-item-img">
                                <img :src="good.goodsImage[0].imageUrl" alt="" width="120px" height="120px">
                            </div>

                            <div class="upload-item-title">
                                商品正面图*
                            </div>
                        </div>
                    </Col>

                    <Col span="4">

                        <div class="upload-item">
                            <div class="upload-item-img">
                                <drag-file-upload
                                        :id="{goodIndex, imageIndex: 1}"
                                        @on-success="uploadSuccess"
                                        @on-remove="uploadRemove">
                                </drag-file-upload>
                            </div>

                            <div class="upload-item-title">
                                商品反面图
                            </div>
                        </div>

                    </Col>

                    <Col span="4">
                        <div class="upload-item">
                            <div class="upload-item-img">
                                <drag-file-upload
                                        :id="{goodIndex, imageIndex: 2}"
                                        @on-success="uploadSuccess"
                                        @on-remove="uploadRemove">
                                </drag-file-upload>
                            </div>

                            <div class="upload-item-title">
                                模特图
                            </div>
                        </div>
                    </Col>

                    <Col span="4">

                        <div class="upload-item">
                            <div class="upload-item-img">
                                <drag-file-upload
                                        :id="{goodIndex, imageIndex: 3}"
                                        @on-success="uploadSuccess"
                                        @on-remove="uploadRemove">
                                </drag-file-upload>
                            </div>

                            <div class="upload-item-title">
                                男生频道封面图
                            </div>
                        </div>

                    </Col>

                    <Col span="4">
                        <div class="upload-item">
                            <div class="upload-item-img">
                                <drag-file-upload
                                        :id="{goodIndex, imageIndex: 4}"
                                        @on-success="uploadSuccess"
                                        @on-remove="uploadRemove">
                                </drag-file-upload>
                            </div>

                            <div class="upload-item-title">
                                女生频道封面图
                            </div>
                        </div>
                    </Col>
                </Row>

                <Row>
                    <Col>
                    <div class="create-item-title">商品描述(详情页内容)</div>
                    </Col>
                </Row>

                <Row>
                    <Col>
                        <editor :content="desc" @change="updateProductDesc"></editor>
                    </Col>
                </Row>

                <Row>
                    <Col>
                        <div class="create-item-title">商品属性</div>
                    </Col>
                </Row>

                <Row v-for="attr in render.productStandardRelationStr" :key="attr">
                    <Col span="8" v-if="attr.inputType === 'select'">
                        <Form-item :label="attr.attributeName">
                            <Select v-model="attr.model" :placeholder="'请选择' + attr.attributeName" :label-in-value="true">
                                <Option v-for="name in attr.idNameList" :value="name.id" :key="name">{{name.text}}</Option>
                            </Select>
                        </Form-item>
                    </Col>

                    <Col v-else>
                        <Form-item :label="attr.attributeName">
                            <Checkbox-group v-model="attr.model">
                                <Checkbox v-for="name in attr.idNameList" :label="name.id" :key="name">
                                    <span>{{name.text}}</span>
                                </Checkbox>
                            </Checkbox-group>
                        </Form-item>
                    </Col>
                </Row>

                <Row v-for="attr in render.attributeProValuesOne" :key="attr">
                    <Col span="8" v-if="attr.inputType === 'select'">
                        <Form-item :label="attr.attributeName">
                            <Select v-model="attr.model" :placeholder="'请选择' + attr.attributeName">
                                <Option v-for="name in attr.idNameList" :value="name.id" :key="name">{{name.text}}</Option>
                            </Select>
                        </Form-item>
                    </Col>

                    <Col v-else>
                        <Form-item :label="attr.attributeName">
                            <Checkbox-group v-model="attr.model">
                                <Checkbox v-for="name in attr.idNameList" :label="name.id" :key="name">
                                    <span>{{name.text}}</span>
                                </Checkbox>
                            </Checkbox-group>
                        </Form-item>
                    </Col>
                </Row>

                <Row v-for="attr in render.attributeProValuesTwo" :key="attr">
                    <Col span="8" v-if="attr.inputType === 'select'">
                        <Form-item :label="attr.attributeName">
                            <Select v-model="attr.model" :placeholder="'请选择' + attr.attributeName">
                                <Option v-for="name in attr.idNameList" :value="name.id" :key="name">{{name.text}}</Option>
                            </Select>
                        </Form-item>
                    </Col>

                    <Col v-else>
                        <Form-item :label="attr.attributeName">
                            <Checkbox-group v-model="attr.model">
                                <Checkbox v-for="name in attr.idNameList" :label="name.id" :key="name">
                                    <span>{{name.text}}</span>
                                </Checkbox>
                            </Checkbox-group>
                        </Form-item>
                    </Col>
                </Row>

                <Row v-if="render.productMaterial">
                    <Col>
                    <Form-item :label="render.productMaterial.attributeName">
                        <Checkbox-group v-model="render.productMaterial.model">
                            <Checkbox v-for="name in render.productMaterial.idNameList" :label="name.id" :key="name">
                                <span>{{name.text}}</span>
                            </Checkbox>
                        </Checkbox-group>
                    </Form-item>
                    </Col>
                </Row>

            </Form>
        </Row>

        <Row>
            <Col>
                <div style="text-align: center">
                    <Button type="primary" @click="backStep" size="large">上一步</Button>
                    <Button type="primary" @click="nextStep" size="large">保存</Button>
                </div>
            </Col>
        </Row>
    </div>
</template>

<script>

import api from 'product-create/api';
import service from 'product-create/service';
import serial from 'product-create/serialize';

export default {
    props: ['step', 'product'],
    data() {
        return {
            desc: '',
            render: {
                goodsImagesReqStr: [],
                productStandardRelationStr: [],
                attributeProValuesOne: [],
                attributeProValuesTwo: [],
                productMaterial: {}
            }
        };
    },
    mounted: function() {
        this.maxSortId = this.product.maxSortId;
        this.smallSortId = this.product.smallSortId;
        this.getAllAttr(this.smallSortId, this.maxSortId);
    },
    methods: {
        nextStep: function() {
            this.$Loading.start();
            this.submit().then((result) => {
                this.$Loading.finish();

                if (result.code === 200) {
                    this.$Notice.success({title: '保存成功'});
                    this.$router.push({name: 'product.offsale'});
                } else {
                    this.$Notice.error({
                        title: '网销信息更新失败',
                        desc: result.message
                    });
                }
            });
        },
        backStep: function() {
            this.step.value = 1;
            this.$router.push({name: 'product.create.step2'});
        },
        updateProductDesc: function(c) {
            this.desc = c;
        },
        getAllAttr: function(smallSortId, maxSortId) {
            return api.getAllAttr(smallSortId, maxSortId).then((result) => {
                this.render.productStandardRelationStr = service.addNoneItem(result[0]);
                this.render.attributeProValuesOne = service.addNoneItem(result[1]);
                this.render.attributeProValuesTwo = service.addNoneItem(result[2]);
                this.render.productMaterial = result[3];
            });
        },
        submit: function() {
            let submitData = this.beforeSubmit();

            return api.updateNetInfo(submitData);
        },
        beforeSubmit: function() {
            let result = {
                productSkn: this.product.productSkn,
                id: this.product.productId,
                productIntro: this.desc,
                goodsImagesReqStr: JSON.stringify(this.handleImage()),
                productStandardRelationStr: JSON.stringify(this.handleRelation()),
                attributeProValuesOne: JSON.stringify(this.handleOne()),
                attributeProValuesTwo: JSON.stringify(this.handleTwo()),
                productMaterial: this.handleMaterial()
            };

            return result;
        },
        handleRelation: function() {
            return serial.handleRelation(this.render.productStandardRelationStr)
        },
        handleOne: function() {
            return serial.handleOne(this.product.productSkn, this.render.attributeProValuesOne);
        },
        handleTwo: function() {
            return serial.handleTwo(this.product.productSkn, this.render.attributeProValuesTwo);
        },
        handleMaterial: function() {
            return this.render.productMaterial.model.join(',');
        },
        handleImage: function() {
            return service.handleColorImage(this.product);
        },
        uploadSuccess: function(data, file) {
            let colorIndex = data.goodIndex;
            let imageIndex = data.imageIndex;

            this.product.goods[colorIndex].goodsImage[imageIndex].imageUrl = file.url;
        },
        uploadRemove: function(data) {
            let colorIndex = data.goodIndex;
            let imageIndex = data.imageIndex;

            this.product.goods[colorIndex].goodsImage[imageIndex].imageUrl = '';
        }
    }
};
</script>

<style lang="scss">

.upload-item {
    display: inline-block;
    height: 180px;
    width: 130px;
    text-align: center;
    margin: 10px 0;
}

.color-item-title {
    text-align: center;
    margin: 50px 0;
}

.upload-item-img {
    display: inline-block;
    height: 126px;
    width: 124px;
    border: 2px solid #e8e8e8;
    box-sizing: border-box;
}

.upload-item-title {
    display: inline-block;
    margin-top: 15px;
}

</style>