h5AddressToast.vue 11.9 KB
<template>
    <div class="toast_mask" @touchmove.stop.prevent>
        <div class="pointsToast_box">
            <div class="title">填写配送地址</div>
            <!--地址-->
            <div class="address">
                <div v-if="addressInfo">
                    <div class="userinfo_box">
                        <div class="user_info">
                            <div v-if="addressInfo.name">
                                {{ addressInfo.name }}
                            </div>
                            <div v-if="addressInfo.phone">
                                {{ addressInfo.phone }}
                            </div>
                        </div>
                        <div @click="changeAddress()" class="btn">更换</div>
                    </div>
                    <div v-if="addressInfo.address" class="info">
                        {{ addressInfo.address }}
                    </div>
                </div>
                <div class="tooltips" v-else @click="changeAddress()">
                    您未填写地址,去填写
                </div>
            </div>
            <!--商品-->
            <!-- <div v-if="itemInfo" class="goods_box">
                <img v-if="itemInfo && itemInfo.img" v-lazy="itemInfo.img" />
                <div class="goods_info">
                    <div v-if="itemInfo && itemInfo.title" class="goods_title">
                        {{ itemInfo.title }}
                    </div>
                </div>
            </div> -->
            <!--底部按钮-->
            <div class="footer">
                <div @click="cancel" class="cancel">取消</div>
                <div @click="confirm" class="confirm">确认</div>
            </div>
        </div>
        <img @click="$parent.pointsToast_control=false"  class="pointsMall_close" src="static/img/addressClose.png" alt=""/>
    </div>
</template>

<script>
import { Toast, Indicator } from "mint-ui";
export default {
  name: "pointsToast",
  data () {
    return {
      itemInfo: null,
      addressInfo: null,
      goodsId: this.$route.query.goodsId || null, // 兑换商品ID
      orderId: this.$route.query.orderId || null, // 订单ID 先兑换后填地址使用
      // drawRecordItemInfo: null // 中奖记录单条信息
    };
  },
  props: ["isBuyLimit"],
  created () {
    // 判断 安卓还是ios获取回选的地址url地址
    let addressId;
    if (this.isiPhone.value) {
      addressId = this.$route.query.addressId;
    } else {
      addressId = window.localStorage.getItem("addressId") || this.$route.query.addressId;
    }

    if (addressId) {
      this.getaddressInfo(addressId);
    } else {
      // 获取我的首选地址
      // this.myFirstAddress();
    }
    //地址之后的回选
    var id = this.$route.query.id;
    if (id) {
      this.luckDrawGift(id);
    }
    // 兑换商品
    //        console.log(this.itemInfo)
  },
  methods: {
    // 父组件点击兑换调用子组件传值商品商品信息
    getItemInfo (content, orderId) {
      this.itemInfo = content;
      if (orderId) {
        this.orderId = orderId
      } else {
        this.goodsId = content.id; // 获取需要兑换商品的ID
      }
      // 获取商品信息接口
      this.luckDrawGift(content.id);
      // 获取首选地址接口
      this.myFirstAddress();
      //  存取抽奖记录选中的列表数据
      // this.$set(this, "drawRecordItemInfo", content.drawRecordItemInfo);
    },
    // 我的首选地址
    /**
     * 我的首选地址
     * * @param {string} uid [用户id]
     */
    myFirstAddress () {
      // 加载中提示
      //            Indicator.open('加载中...');

      // 请求接口
      this.http(
        "/Api/" + this.getApiVersion().index + "/myFirstAddress",
        {
          uid: this.getStore("uid")
        },
        this.myFirstAddressCallback,
        {
          method: "POST"
        }
      );
    },

    /**
     * 我的首选地址信息
     * @param {object} res [服务器返回数据]
     * @param {object} ext [扩展参数]
     */
    myFirstAddressCallback (res, ext) {
      // 加载完成
      //            Indicator.close();

      // 返回处理
      if (res.code == 200) {
        // 解构数据
        let { data: datas } = res;
        this.addressInfo = datas;
        /* 我的首选地址信息 开始 */
      } else if (res.code == 400) {
        // 获取积分商场首页信息失败
        // Toast(res.message);
      } else {
        // 获取积分商场首页信息失败
        // Toast("获取我的首选地址失败");
      }
    },
    /**
     * 选中的地址
     * * @param {string} uid [用户id]
     */
    getaddressInfo (addressId) {
      // 加载中提示
      //            Indicator.open('加载中...');

      // 请求接口
      this.http(
        "/Api/" + this.getApiVersion().index + "/addressInfo",
        {
          id: addressId
        },
        this.getaddressInfoCallback,
        {
          method: "POST"
        }
      );
    },

    /**
     * 选中的地址
     * @param {object} res [服务器返回数据]
     * @param {object} ext [扩展参数]
     */
    getaddressInfoCallback (res, ext) {
      // 加载完成
      //            Indicator.close();

      // 返回处理
      if (res.code == 200) {
        // 解构数据
        let { data: datas } = res;
        this.addressInfo = datas;
        /* 获取选中的地址失败 开始 */
      } else if (res.code == 400) {
        // 获取选中的地址失败
        Toast(res.message);
      } else {
        // 获取选中的地址失败
        Toast("获取选中的地址失败");
      }
    },
    /**
     * 选中的商品信息
     * * @param {string} uid [用户id]
     */
    luckDrawGift (id) {
      // 加载中提示
      //            Indicator.open('加载中...');

      // 请求接口
      this.http(
        "/Api/" + this.getApiVersion().LuckDraw + "/luckDrawGift",
        {
          uid: this.getStore("uid"),
          id: id
        },
        this.luckDrawGiftCallback,
        {
          method: "POST"
        }
      );
    },

    /**
     * 选中的兑换商品信息
     * @param {object} res [服务器返回数据]
     * @param {object} ext [扩展参数]
     */
    luckDrawGiftCallback (res, ext) {
      // 加载完成
      //            Indicator.close();

      // 返回处理
      if (res.code == 200) {
        // 解构数据
        let { data: datas } = res;
        this.itemInfo = datas;
        //                console.log(this.itemInfo)
        /* 获取选中的地址失败 开始 */
      } else if (res.code == 400) {
        // 获取选中的兑换商品信息失败
        Toast(res.message);
      } else {
        // 获取选中的兑换商品信息失败
        Toast("获取选中的兑换商品信息失败");
      }
    },
    /**
     * 取消
     */
    cancel () {
      // 隐藏弹框
      this.$parent.pointsToast_control = false;
      // 安卓手机下特殊处理
      if (this.isAndroid.value) {
        // 安卓下清除locaStroe的ext和addressId数据
        window.localStorage.removeItem("ext");
        window.localStorage.removeItem("addressId");
      }
      // 清除URL数据pointsToast_control
      window.location.href =
        window.location.href.split("?")[0] +
        "?uid=" +
        this.getStore("uid") + "&goodsId=" + this.$route.query.goodsId
    },
    /**
     * 确定
     */
    confirm () {
      debugger
      // 兑换商品的ID分两种一种是订单ID填写地址;一种是有商品地址填写地址
      let orderInfo = {
        addressId: null,
        id: null, // 兑换商品ID
      };
      if (this.$route.query.orderId || this.orderId) {
        orderInfo = {
          addressId: this.$route.query.addressId || this.addressInfo.id,
          id: this.$route.query.orderId || this.orderId, // 兑换商品ID
        };
      } else if (this.$route.query.goodsId || this.goodsId) {
        orderInfo = {
          addressId: this.$route.query.addressId || this.addressInfo.id,
          id: this.$route.query.goodsId || this.goodsId, // 兑换商品ID
        };
      }
      // 安卓手机下特殊处理
      if (this.isAndroid.value) {
        // 兑换商品的ID分两种一种是订单ID填写地址;一种是有商品地址填写地址
        if (this.getParameterByName("orderId") || this.orderId) {
          orderInfo.id = this.getParameterByName("orderId") || this.orderId
        } else if (this.getParameterByName("goodsId") || this.goodsId) {
          orderInfo.id = this.getParameterByName("goodsId") || this.goodsId
        }

        orderInfo.addressId = window.localStorage.getItem("addressId") || this.addressInfo.id
        orderInfo.pointsToast_control = this.getParameterByName("pointsToast_control")
        // 安卓下清除locaStroe的ext和addressId数据
        window.localStorage.removeItem("ext");
        window.localStorage.removeItem("addressId");
      } else {
        window.location.href =
          window.location.href.split("?")[0] +
          "?uid=" +
          this.getStore("uid") + "&goodsId=" + this.$route.query.goodsId || this.goodsId
      }
      // 最新地址信息回传给父组件
      this.$parent.addressInfo = this.addressInfo;
      this.addLuckDrawAddress(orderInfo);
      // 隐藏弹框
      this.$parent.pointsToast_control = false;
    },
    //       更改地址
    changeAddress () {
      // 安卓手机两次更改地址goodsId没拿到从
      if (this.isAndroid.value) {
        // 处理商品ID问题
        if (!this.goodsId) {
          let ext = "&" + window.localStorage.getItem("ext")
          this.goodsId = this.getParameterByName(
            "goodsId",
            ext
          );
        }
        // 处理商品ID问题
        if (!this.orderId) {
          let ext = "&" + window.localStorage.getItem("ext")
          this.orderId = this.getParameterByName(
            "orderId",
            ext
          );
        }
        // 处理填写地址弹框显示记录
        // let storageExt = "&pointsToast_control=true"
        // window.localStorage.setItem("ext", storageExt)
      }
      // 测试环境
      window.location.href =
        this.getApiVersion().addAddresss +
        "html/mall/1/#/pages/users/addressList/addressList" +
        "?uid=" +
        this.getStore("uid") +
        "&ext=" +
        encodeURIComponent(
          "goodsId=" +
          this.goodsId +
          "&orderId=" +
          this.orderId +
          "&pointsToast_control=" +
          this.$parent.pointsToast_control
        ) +
        "&from=redirect&redirect=" +
        encodeURIComponent(window.location.href.split("?")[0]);
    },
    // 提交中奖的商品信息
    /**
     * 提交中奖的商品信息
     * * @param {string} addressId [地址id]
     * *@param {string} id [商品id]
     * *@param {string} id_card [身份证id]
     */
    addLuckDrawAddress (orderInfo) {
      // 加载中提示
      Indicator.open("加载中...");

      // 请求接口
      this.http(
        "/Api/" + this.getApiVersion().LuckDraw + "/addLuckIntegralAddress",
        {
          uid: this.getStore("uid"),
          addressId: orderInfo.addressId,
          id: orderInfo.id // 商品ID
        },
        this.addLuckDrawAddressCallback,
        {
          method: "POST",
          ext: orderInfo
        }
      );
    },

    /**
     * 提交中奖的商品信息
     * @param {object} res [服务器返回数据]
     * @param {object} ext [扩展参数]
     */
    addLuckDrawAddressCallback (res, ext) {
      // 加载完成
      Indicator.close();
      // 返回处理
      if (res.code == 200) {
        Toast("提交成功等待发货");
        this.$emit("toUpdate", ext.ext, this.addressInfo);
      } else {
        // 兑换礼品失败
        Toast(res.message);
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less">
@import './h5AddressToast';
</style>