<template>
    <el-dialog center title="支付订单" :visible.sync="show" width="680px">
        <div class="page" v-loading="loading">
            <div class="info">
                <div class="price">
                    <span class="text1">应付金额</span>
                    <img src="../assets/icon_jiage.png" alt="" />
                    <span class="text2">{{ money }}</span>
                    <span class="text3">(含gas费¥{{ gas }})</span>
                </div>
                <div class="flex1"></div>
                <!-- <div class="order">
                    <span class="text1">订单编号</span>
                    <span class="text2">{{ orderInfo.id }}</span>
                    <el-button type="info" @click="copy" size="mini" plain>复制</el-button>
                </div> -->
            </div>

            <div class="payMethods">
                <!-- <div class="title">选择支付方式</div>
                <div class="pay-list">
                    <div class="pay-info">
                        <el-radio-group v-model="payMethods">
                            <el-radio v-for="item in payList" border :label="item.type" :key="item.type">
                                <img :src="item.icon" alt="" />
                                <span> {{ item.name }}</span>
                            </el-radio>
                        </el-radio-group>
                    </div>
                </div> -->

                <div class="qrcode">
                    <vue-qrcode :value="payUrl" :options="{ width: 140, margin: 1 }" class="code"></vue-qrcode>
                </div>
                <!-- <div class="qrcode-text">二维码有效时常为5分钟，请尽快支付</div> -->
                <div class="qrcode-text">手机微信扫描二维码下单</div>
            </div>

            <div class="tips">
                <div class="text1">购买须知</div>
                <div class="text2">
                    1.数字盲盒按照随机概率进行抽取<br />
                    2.数字盲盒及其数字内容为虚拟商品<span style="color: #ff4f50">支付完成后，不可退换</span><br />
                    3.数字盲盒及其数字内容仅作为消费娱乐（或其他约定场景）使用<br />
                    4.切勿当成投资和投机品进行盲目消费
                </div>
            </div>
        </div>

        <!-- <span slot="footer" class="dialog-footer">
            <el-button type="primary" class="pay" @click="submit">确认</el-button>
        </span> -->
    </el-dialog>
</template>

<script>
import vueQrcode from '@chenfengyuan/vue-qrcode';
import resolveUrl from 'resolve-url';
import { add } from 'mathjs';
export default {
    data() {
        return {
            show: false,
            payMethods: 'ALIPAY',
            payList: [
                {
                    icon: require('../assets/alipay.png'),
                    name: '支付宝',
                    type: 'ALIPAY'
                },
                {
                    icon: require('../assets/weixin.png'),
                    name: '微信',
                    type: 'WEIXIN'
                },
                {
                    icon: require('../assets/dcep.png'),
                    name: 'DCEP支付',
                    type: 'DCEP'
                }
            ],
            loading: true,
            info: {},
            gas: 0
        };
    },
    computed: {
        payUrl() {
            return resolveUrl(this.$baseUrl, '9th/submit?id=' + this.info.id);
        },
        money() {
            if (this.info.price) {
                return add(this.info.price, this.gas);
            } else {
                return 0;
            }
        }
    },
    methods: {
        submit() {
            if (this.payMethods === 'DCEP') {
                this.wait();
            }
        },
        init(info) {
            this.checkLogin()
                .then(() => {
                    this.show = true;
                    this.loading = true;
                    this.info = info;
                    return this.$http.get('/sysConfig/get/gas_fee');
                    // return this.$http.get('/order/get/' + 1216);
                    // return this.$http.post('/order/create?collectionId=' + info.id + '&qty=1');
                })
                .then(res => {
                    this.gas = res.value;
                    this.loading = false;
                })
                .catch(e => {
                    if (e) {
                        this.$message.warning(e.error);
                    }
                });
        },
        copy() {
            this.$copyText(this.orderInfo.id).then(
                e => {
                    this.$message.success('复制成功');
                },
                e => {
                    this.$message.warning('复制失败');
                }
            );
        }
    },
    components: {
        vueQrcode
    }
};
</script>

<style lang="less" scoped>
.info {
    .flex();
    height: 94px;
    .price {
        .flex();
        align-items: flex-end;
        .text1 {
            font-size: 16px;
            color: #000000;
            line-height: 24px;
        }
        img {
            width: 10px;
            display: block;
            margin: 0 0 4px 10px;
        }
        .text2 {
            font-size: 40px;
            font-family: OSP;
            font-weight: normal;
            color: #ff4f50;
            line-height: 36px;
        }
        .text3 {
            font-size: 13px;
            color: #000000;
            line-height: 24px;
            margin-left: 15px;
        }
    }

    .order {
        .text1 {
            font-size: 13px;
            color: #939599;
            line-height: 24px;
        }

        .text2 {
            font-size: 13px;
            color: #0e0e0e;
            line-height: 22px;
            padding: 0 6px 0 30px;
        }
        .el-button {
            height: 20px;
            line-height: 20px;
            padding: 0 10px;
        }
    }
}
/deep/.el-loading-mask {
    background-color: #ffffffee;
}

/deep/.el-radio {
    .flex();
    display: inline-flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    width: 190px;
    height: 42px;
    color: #939599;
    padding: 0;
    box-sizing: border-box;
    .el-radio__label {
        .flex();
        img {
            width: 24px;
            height: 24px;
        }
        span {
            font-size: 16px;
            font-weight: bold;
            padding: 0 10px;
        }
        margin-left: 24px;
    }
    .el-radio__input {
        margin-right: 24px;
        width: 20px;
        flex-shrink: 0;

        .el-radio__inner {
            width: 20px;
            height: 20px;
            &::after {
                content: '\e6da';
                font-family: 'element-icons';
                width: 14px;
                height: 14px;
                font-size: 14px;
                color: #fff;
                font-weight: bold;
                background-color: transparent;
            }
        }

        &.is-checked {
            .el-radio__inner {
                background-image: linear-gradient(135deg, @prim 20%, @warn 100%);
                border-width: 0;
            }
        }
    }
    &.is-checked {
        .line(@bg:#E0FFF8,@radius:4px);
        border-width: 0;
        .el-radio__label {
            color: #000;
        }
    }
}
.payMethods {
    padding: 30px 0;
    .title {
        font-size: 16px;
        color: #000000;
        line-height: 24px;
        padding-bottom: 20px;
    }
}
/deep/.el-radio.is-bordered + .el-radio.is-bordered {
    margin-left: 0;
}

.tips {
    padding-top: 20px;
    .text1 {
        font-size: 16px;
        color: #939599;
        line-height: 24px;
    }
    .text2 {
        font-size: 14px;
        color: #939599;
        line-height: 28px;
        margin-top: 10px;
    }
}
.pay {
    background-image: linear-gradient(135deg, @prim, @warn);
    border-width: 0;
    width: 200px;
    color: #000;
    &:hover {
        background-image: linear-gradient(135deg, darken(@prim, 20), darken(@warn, 20));
    }
}
.qrcode {
    width: 160px;
    height: 160px;
    background: #f5f7fa;
    border-radius: 11px;
    margin: 30px auto 10px;
    padding: 10px;
    box-sizing: border-box;
    .code {
        border-radius: 11px;
        overflow: hidden;
    }
}
.qrcode-text {
    font-size: 16px;
    color: #939599;
    line-height: 24px;
    margin: 0 auto;
    text-align: center;
}
</style>
