<template>
<div class="jfBaseSize submitOrder" v-bind:style="isShow.vh?'height:100vh':'height: 100%;'">
    <div>
        <div class="addressOrder">
            <div class="noExistAddress" v-if="!isShow.address" v-on:click="selectAddress()">
                <p class="text-danger">新增收货地址</p>
            </div>
            <div class="existAddress" v-else v-on:click="selectAddress()">
                <p class="addressName"><span v-html="AddressObj.ConsigneeName"></span><span v-html="AddressObj.ConsigneeMobile"></span></p>
                <p v-html="AddressObj.ConsigneeAddressAll"></p>
            </div>
        </div>
        <hr />
        <div class="addressProduct">
            <div class="productList">
                <div class="productImg">
                    <img :src="dataProduct.Gift_ProductImg" />
                </div>
                <div class="productContent">
                    <p class="productName" v-html="dataProduct.Gift_Name"></p>
                    <p class="clearfix">
                        <span>
                            <span class="dangerIntegral" v-html="dataProduct.Gift_Score"></span>
                            <span>积分</span>
                        </span>
                        <span>数量：<span class="text-danger" v-html="JfCompScoreDetailObj.GiftCount"></span></span>
                    </p>
                </div>
            </div>
            <p class="productResult">
                合计
                <span>
                    <span class="dangerIntegral" v-html="dataProduct.Gift_Score&&JfCompScoreDetailObj.GiftCount?dataProduct.Gift_Score*JfCompScoreDetailObj.GiftCount:0"></span>
                    <span class="text-gray">积分</span>
                </span>
            </p>
        </div>
        <hr />
        <div class="addressWay">
            配送方式
            <span class="text-gray">
                <span>普通快递：</span>
                <span>免邮</span>
            </span>
        </div>
    </div>
    <div class="mint-popup exchangeSuccess" v-show="isShow.popup">
        <img class="successImg" src="https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/icon_exchangeSuccess.png">
        <h2 class="text-danger">恭喜你兑换成功！</h2>
        <p class="text-gray">我们将尽快发货，请注意手机保持畅通</p>
        <div>
            <mt-button class="text-danger" type="danger" v-on:click="changePage('16')">查看订单</mt-button>
            <mt-button type="danger" style="margin-left: 10%;background:#c03546" v-on:click="changePage('9')">继续兑换</mt-button>
        </div>
    </div>
    <div class="v-modal" style="z-index: 2008;" v-show="isShow.popup"></div>
    <mt-button class="btnSubmit" type="danger" size="large" v-on:click="popupShow()">提交订单</mt-button>
</div>
</template>

<script>
import { Toast } from 'mint-ui';
import { Indicator } from 'mint-ui';
import JfapiHelper from "../assets/js/JfapiHelper.js";
export default {
 name: 'JfCompClassGift',
 props: ["comp", "cfg", "selectedPage"],
  data() {
    return {
        tempLoginInfo:{},
        dataProduct:{},
        JfCompScoreDetailObj:{},
        AddressObj:{},
        orderId:'',
        isShow:{
            popup:false,
            address:false,
            vh:false,
        },
    }
  },
  methods: {
    CompGetMallGiftShowInfo() {
        var that=this;
        //that.sup8.context.enterpriseno
        var url = "/integral/CompGetMallGiftShowInfo";
        var cbBeforeSend = function(){
            Indicator.open();
        };
        var cbComplete = function(){
            Indicator.close();
        };
        var dataParams = {
            Id:that.dataProduct.ID,
            CurrentEnterpriseNo: that.tempLoginInfo.EnterpriseNo,
            UserToken:that.tempLoginInfo.UserToken,
            LanguageType:that.tempLoginInfo.LanguageType,
        };
        var cbSuccess = function (res) {
            if(res.flag)
            {
                var responseData = [];
                try {
                    responseData = JSON.parse(res.data);
                } catch (e) {
                    responseData = res.data;
                }
                if(responseData){
                    if(responseData.Gift_Score){
                        responseData.Gift_Score=parseInt(responseData.Gift_Score);
                    }
                    if(responseData.Stock){
                        responseData.Stock=parseInt(responseData.Stock);
                    }
                    if(responseData.Detail){
                        responseData.Detail=decodeURIComponent(responseData.Detail);
                    }
                    that.dataProduct=Object.assign({},that.dataProduct,responseData);
                }else{
                    Toast("未获取到商品信息，请刷新重试");
                }
            }else{
                Toast(res.msg);
            }
        };
        var cbError = function(jqXHR, textStatus, errorThrown){
            Toast(jqXHR.responseText);
        };
        JfapiHelper.CommonCallService(url,dataParams, cbSuccess,cbError,cbBeforeSend,cbComplete);
    },
    CompGetDefaultConsigneeAddress(){
        var that=this;
        //that.sup8.context.enterpriseno
        var url = "/integral/CompGetDefaultConsigneeAddress";
        var cbBeforeSend = function(){
            Indicator.open();
        };
        var cbComplete = function(){
            Indicator.close();
        };
        var dataParams = {
            CurrentEnterpriseNo: that.tempLoginInfo.EnterpriseNo,
            UserToken:that.tempLoginInfo.UserToken,
            LanguageType:that.tempLoginInfo.LanguageType,
        };
        var cbSuccess = function (res) {
            if(res.flag)
            {
                var responseData = [];
                try {
                    responseData = JSON.parse(res.data);
                } catch (e) {
                    responseData = res.data;
                }
                if(responseData){
                    if(responseData.ConsigneeAddress){
                        responseData.ConsigneeAddressAll= responseData.ConsigneeProvince+' '+responseData.ConsigneeCity+' '+responseData.ConsigneeArea+' '+responseData.ConsigneeAddress;
                    }
                    that.AddressObj=Object.assign({},that.AddressObj,responseData);
                    sessionStorage.setItem('JfCompAddressObj',JSON.stringify(responseData));
                    that.$set(that.isShow,'address',true);
                }else{
                    that.$set(that.isShow,'address',false);
                }
            }else{
                Toast(res.msg);
            }
        };
        var cbError = function(jqXHR, textStatus, errorThrown){
            Toast(jqXHR.responseText);
        };
        JfapiHelper.CommonCallService(url,dataParams, cbSuccess,cbError,cbBeforeSend,cbComplete);
    },
    popupShow(){
        var that=this;
        if(!that.dataProduct.Gift_Name||!that.dataProduct.ID){
            Toast("未获取到商品信息，请刷新重试");
            return;
        }else if(!that.AddressObj.ID){
            Toast("请填写收货地址");
            return;
        }
        var url = "/integral/CompSubmitOrder";
        var cbBeforeSend = function(){
            Indicator.open();
        };
        var cbComplete = function(){
            Indicator.close();
        };
        var dataParams = {
            CurrentEnterpriseNo: that.tempLoginInfo.EnterpriseNo,
            UserToken:that.tempLoginInfo.UserToken,
            LanguageType:that.tempLoginInfo.LanguageType,
            GiftId:that.dataProduct.ID,
            GiftCount:that.JfCompScoreDetailObj.GiftCount,
            ConsigneeName:that.AddressObj.ConsigneeName,
            ConsigneeMobile:that.AddressObj.ConsigneeMobile,
            ConsigneeAddress:that.AddressObj.ConsigneeAddressAll,
            ConsigneePostcode:that.AddressObj.ConsigneePostcode,
            MobileOrAccount:'',
            type:1,
        };
        var cbSuccess = function (res) {
            if(res.flag)
            {
                that.$set(that,'orderId',res.data);
                // sessionStorage.getItem("ExchangeOrderId");
                that.$set(that.isShow,'popup',true);
            }else{
                Toast(res.msg);
            }
        };
        var cbError = function(jqXHR, textStatus, errorThrown){
            Toast(jqXHR.responseText);
        };
        JfapiHelper.CommonCallService(url,dataParams, cbSuccess,cbError,cbBeforeSend,cbComplete);
    },
    selectAddress(){
        var that=this;
        if(!that.dataProduct.Gift_Name||!that.dataProduct.ID){
            Toast("未获取到商品信息，请刷新重试");
            return;
        }
        sessionStorage.setItem('goPageVue',"JfCompSubOrder");
        that.$parent.changeSelectedPage('24');
    },
    changePage(type){
        var that=this;
        if(type=='16'){
            sessionStorage.setItem("ExchangeOrderId",that.orderId);
        }
        that.$parent.changeSelectedPage(type);
    },
  },
  created(){
  },
  mounted: function () {
    var that=this;
    var isDesign=  location.pathname.indexOf('design');
    if (!(isDesign>-1)) {
        that.$set(that.isShow,'vh',true);
    }else{
        that.$set(that.isShow,'vh',false);
    }
        if(JfapiHelper.CheckLogin(this.$parent, that.sup8.context.enterpriseno)){
            var tempLoginInfo =  JSON.parse(localStorage.getItem("loginInfo"));
            that.tempLoginInfo=Object.assign({},that.tempLoginInfo,tempLoginInfo);
        }else{
            return;
        }
        var JfCompScoreDetailObj=JSON.parse(sessionStorage.getItem("JfCompScoreDetailObj"));
        if(JfCompScoreDetailObj&&JfCompScoreDetailObj.GiftId&&JfCompScoreDetailObj.GiftCount){
            that.$set(that.dataProduct,'ID',JfCompScoreDetailObj.GiftId);
            that.JfCompScoreDetailObj=Object.assign({},that.JfCompScoreDetailObj,JfCompScoreDetailObj);
            var JfCompAddressObj=JSON.parse(sessionStorage.getItem('JfCompAddressObj'));
            if(JfCompAddressObj){
                if(JfCompAddressObj.ConsigneeAddress){
                    JfCompAddressObj.ConsigneeAddressAll= JfCompAddressObj.ConsigneeProvince+' '+JfCompAddressObj.ConsigneeCity+' '+JfCompAddressObj.ConsigneeArea+' '+JfCompAddressObj.ConsigneeAddress;
                }
                that.AddressObj=Object.assign({},that.AddressObj,JfCompAddressObj);
                that.$set(that.isShow,'address',true);
            }else{
                that.CompGetDefaultConsigneeAddress();
            }
            that.CompGetMallGiftShowInfo();
        }else{
            Toast('未获取到商品兑换信息，请刷新重试');
        }
  }
}
</script>

<style scoped>
img{border:0;}
img[src=""],img:not([src]){opacity:0;}
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}
.clearfix{overflow:hidden;_zoom:1;}
.text-gray{color:#b3b3b3;}
.text-danger{color:#c03546;}
.text-orange{color:#eb7741;}
.v-modal {z-index: 2008;position: absolute;left: 0;top: 0;width: 100%;height: 100%;opacity: .5;background: #000;}
.dangerIntegral{color:#c03546;font-weight: 700;margin-right:0.2rem;}
hr{margin: 0;border: 0.19rem solid #e6e6e9;}
.submitOrder{width: 100%;overflow: hidden;position: relative;background-color: #e6e6e9;}
.submitOrder >div:nth-of-type(1){height: 100%;overflow-x: auto;}
.addressOrder{border-bottom: 0.2rem dashed #d4d4d4;padding: 0.8rem 3%;padding-right:7%;background:url(https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/order_arrow.png) no-repeat 97% 49%;background-size:0.5rem 1rem;background-color: #fff;}
.addressOrder .noExistAddress{padding-left: 1.4rem;background:url(https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/order_add.png) no-repeat 0.1rem 49%;background-size:1rem 1rem; }
.addressOrder .noExistAddress p{height: 3.4rem;line-height:3.4rem;margin: 0;font-weight: 700;}
.addressOrder .existAddress{padding-left: 1.8rem;background:url(https://release-sup8-images.oss-cn-shanghai.aliyuncs.com/h5_shop/order_GPS.png) no-repeat 0.1rem 49%;background-size:1rem 1.4rem;}
.addressOrder .existAddress .addressName{margin-bottom:0.6rem; }
.addressOrder .existAddress .addressName span:nth-of-type(1){margin-right: 0.6rem;}
.addressProduct{padding: 0.8rem 3%;padding-top:0.4rem;background-color: #fff;}
.addressProduct .productList{display: flex;min-height: 4.6rem;border-bottom: 0.01rem solid #f5f5f5;padding: 0.4rem 0;}
.addressProduct .productImg{width:5rem;margin-right:0.2rem;position:relative;}
.addressProduct .productImg img{width:100%;height:90%;margin-top:5%;}
.addressProduct .productContent {flex:1;}
.productContent .productName{font-size: 1rem;margin-bottom:1rem;overflow:hidden;text-overflow:ellipsis;-webkit-line-clamp:2;-webkit-box-orient:vertical;display:-webkit-box;min-height: 2.4rem;}
.addressProduct .productContent .clearfix {color:#b3b3b3;vertical-align:bottom;height: 1.2rem;line-height: 1.2rem;margin-top: 1rem;}
.addressProduct .productContent .clearfix >span:nth-of-type(1){float:left;line-height: 20px;}
.addressProduct .productContent .clearfix >span:nth-of-type(2){float: right;}
.addressProduct .productResult{margin-top: 0.8rem;margin-bottom: 0;}
.addressProduct .productResult >span {float: right;}
/* .addressProduct .productResult >span .dangerIntegral+span{font-size: 0.78rem;} */
.addressWay {padding: 0.8rem 3%;background-color: #fff;margin-bottom: 41px;}
.addressWay >span{float: right;}
.submitOrder .mint-button.btnSubmit{border-radius: 0;position: absolute;bottom: 0;background-color:#c03546;}
.mint-popup{z-index: 2011;position: absolute;width: 80%;}
.exchangeSuccess{border-radius: 0.6rem;padding: 1.2rem 2%;text-align: center;}
.exchangeSuccess .successImg{width:6rem;height: 6rem;margin:1.2rem auto;display: block;}
.exchangeSuccess p{font-size: 0.94rem;}
.exchangeSuccess div{margin-top:1.2rem; }
.exchangeSuccess div .mint-button{border-radius: 0;}
.exchangeSuccess div .text-danger{background: #fff;border:0.08rem solid #c03546;}
</style>
