<template>
    <view class="main">
        <!-- nav -->
        <navigation>{{ i18n.ChooseAddress }}<view slot="right" class="right" @click="editFlag = !editFlag;">{{
                editFlag ? i18n.OK : i18n.Edit
        }}
            </view>
        </navigation>
        <view class="content">
            <view class="message-item">
                {{ i18n.message4 }}
            </view>
            <view class="message-item last">
                {{ i18n.message5 }}
            </view>
            <view class="card" v-if="coinList.length > 0">
                <view class="dataBody" v-for="(item, index) in 4" :key="index">
                    <view class="coinTitle">USDT</view>
                    <view class="addressItem" v-for="(addressItem, addressIndex) in 2" :key="addressIndex"
                        @click="itemClick(index, addressIndex)">
                        <view class="radio"
                            :class="{ select: (editCoinIndex === index && editCoinAddressIndex === addressIndex) }"
                            v-if="editFlag"></view>
                        <view class="addressInfo">
                            <view class="addressTitle">{{ i18n.myOmniAddress }}</view>
                            <view class="address">SDIHJSD9809U9ERF9IOU0980970</view>
                            <view class="time">2022/08/06 14:50:34</view>
                        </view>

                    </view>
                </view>
            </view>
            <!-- 确认框 -->
            <u-modal :show="modalShow" :confirmText="i18n.OK" :cancelText="i18n.Cancel" :showCancelButton="true"
                :title="i18n.WarmTips" :content='i18n.WarmTipsText' @confirm="deleteAddress" @cancel="modalShow = false"
                confirmColor="#00E8A2">
            </u-modal>
            <!-- 编辑按钮 -->
            <view class="buttonBg">
                <u-button class="button" :color="editFlag ? '#F4506A' : '#00E8A2'" throttleTime="500" @click="btnClick"
                    :disabled="btnIsCanClick">
                    {{ editFlag ? i18n.DeleteAddress : i18n.AddAddress }}
                </u-button>
            </view>

        </view>

    </view>
</template>

<script>
import KeyValueRow from '../../components/KeyValueRow/KeyValueRow.vue';
export default {
    components: { KeyValueRow },
    name: "chooseAddress",
    data() {
        return {
            coinList: [{}],
            coinAddressList: [{}],
            editFlag: false, // 是否在编辑状态
            editCoinIndex: '',
            editCoinAddressIndex: '',
            coinAddress: 'SDIHJSD9809U9ERF9IOU0980970',
            currentCoin: 'USDT',
            modalShow: false,

        };
    },
    computed: {
        i18n() {
            return this.$t("withdrawal");
        },
        btnIsCanClick() { // 按钮是否可以点击
            if (this.editFlag) {
                // console.log(`${this.editCoinIndex}` ? false : true);
                return `${this.editCoinIndex}` ? false : true; // 在编辑模式,有值才能点
            } else {
                return false; // 不在编辑模式始终可以点
            }
        }
    },
    onLoad() {

    },
    onShow() { },
    methods: {
        itemClick(index, addressIndex) {
            // 编辑模式下
            if (this.editFlag) {
                // console.log(index, addressIndex);
                if (this.editCoinIndex === index && this.editCoinAddressIndex === addressIndex) { // 取消选择
                    this.editCoinIndex = '';
                    this.editCoinAddressIndex = '';
                } else { // 选择
                    this.editCoinIndex = index;
                    this.editCoinAddressIndex = addressIndex;
                }
            } else {
                // 选择地址情况下 点击地址返回传参有问题 可能要通用vuex解决
                uni.$emit('coinAddressChang', {
                    coinAddress: this.coinAddress,
                });
                uni.navigateBack()

            }

        },
        btnClick() {
            // 在编辑模式弹出确认框
            if (this.editFlag) {
                this.modalShow = true
            } else {
                // 在非编辑模式下直接跳转
                uni.navigateTo({
                    url : '/pages/withdrawal/addAddress'
                });
            }
        },

        deleteAddress() {
            this.modalShow = false;
            console.log('deleteAddress');
        },

    },
}
</script>

<style lang="scss" scoped>
.main {

    .right {
        width: 82rpx;
        height: 56rpx;
        line-height: 56rpx;
        position: absolute;
        right: 32rpx;
        font-size: 24rpx;
        background: rgba(246, 166, 9, 0.1);
        border-radius: 8px;
        color: #FFBC1F;
    }

   
    .content {
        margin-top: 200rpx;
        padding: 40rpx;

        .message-item {
            padding: 0 16rpx;
            font-size: 24rpx;
            color: #A1A0A8;
            line-height: 36rpx;

            &.last {
                margin-bottom: 30rpx;
            }
        }


        .card {

            .dataBody {
                margin-bottom: 32rpx;
                padding: 32rpx;
                box-sizing: border-box;
                background: #211F32;
                border-radius: 20rpx;

                .coinTitle {
                    font-size: 24rpx;
                    line-height: 28rpx;
                    margin-bottom: 32rpx;
                }

                .addressItem {
                    height: 180rpx;
                    box-sizing: border-box;
                    padding: 32rpx 0;
                    border-top: 2rpx solid #323045;
                    display: flex;

                    .radio {
                        margin-top: 32rpx;
                        margin-right: 24rpx;
                        box-sizing: border-box;
                        width: 48rpx;
                        height: 48rpx;
                        background: #323045;
                        border: 3rpx solid #DCDBE0;
                        border-radius: 16rpx;


                        &.select {
                            background-image: url(../../static/withdrawal/Checkbox_pr.png);
                            background-repeat: no-repeat;
                            background-size: 48rpx;
                            border: none;
                        }
                    }

                    .addressInfo {
                        flex: 1;

                        .addressTitle {
                            position: relative;
                            font-size: 24rpx;
                            margin-bottom: 20rpx;

                            &::after {
                                display: block;
                                position: absolute;
                                content: '';
                                background-image: url(../../static/charity/ic_ma_arrow_down.png);
                                background-repeat: no-repeat;
                                background-size: 32rpx;
                                width: 32rpx;
                                height: 32rpx;
                                top: 0rpx;
                                right: 0rpx;
                                transform: rotate(270deg);
                            }
                        }

                        .address {
                            font-size: 24rpx;
                            line-height: 28rpx;
                            color: #A1A0A8;
                        }

                        .time {
                            font-size: 24rpx;
                            line-height: 28rpx;
                            color: #A1A0A8;
                        }
                    }
                }





                &:last-child {
                    margin-bottom: 160rpx;
                }

            }
        }

        /deep/.u-popup__content {
            background: #323045;

            .u-modal__title {
                color: #fff;
            }

            .u-modal__content__text {
                text-align: center;
            }
        }

        .buttonBg {
            position: fixed;
            bottom: 0rpx;
            background-color: #15141F;

            .button {
                width: 670rpx;
                box-sizing: border-box;
                height: 112rpx;
                margin-bottom: 40rpx;
                border-radius: 32rpx;
                font-weight: 700;
                font-size: 32rpx;
                color: #15141F !important;

            }
        }




    }




}
</style>
