<template>
  <view>
    <view @click="chooseaddr">
      <ordersubUserinfo
        :username="ordersubinfo.list_address[parseInt(this.canshu.addrkey)].uname?ordersubinfo.list_address[parseInt(this.canshu.addrkey)].uname:ordersubinfo.list_address[0].uname"
        :address="ordersubinfo.list_address[parseInt(this.canshu.addrkey)].address?ordersubinfo.list_address[parseInt(this.canshu.addrkey)].address:ordersubinfo.list_address[0].address"
        :tel="ordersubinfo.list_address[parseInt(this.canshu.addrkey)].phone?ordersubinfo.list_address[parseInt(this.canshu.addrkey)].phone:ordersubinfo.list_address[0].phone"
        :addrnull="ordersubinfo.list_address.length==0"
      ></ordersubUserinfo>
      <!-- ordersubinfo.list_address.length==0 -->
    </view>

    <view class="shops" @click="servicelist">
      <ordersubShop :shops="ordersubinfo.list_goods"></ordersubShop>
    </view>
    <view class="btn">
      <ordersubBtn left="支付方式" right="在线支付" class="btn"></ordersubBtn>
    </view>
    <view @click="youhui">
      <ordersubBtn left="优惠" :right="yhale"></ordersubBtn>
    </view>
    <view class="priarr">
      <ordersubPricearr :zongjia="ordersubinfo.price_z" :yf="ordersubinfo.price_yf" :yhq="yhqprice"></ordersubPricearr>
    </view>

    <ordersubPay class="pay" :shifu="ordersubinfo.price_z-yhqprice" @pay="pay"></ordersubPay>
    <ordersubNouser :ifnull="ifnull" v-on:charge="close"></ordersubNouser>
    <view class="youhui" v-if="ifyh">
      <youhui
        :ifyouhui="ifyh"
        v-on:off="off"
        :yhqall="ordersubinfo.list_youhuijuan"
        ifget="true"
        @yhqpri="yhqpri"
        @yhqid="yhqids"
      ></youhui>
    </view>
  </view>
</template>

<script>
import ordersubUserinfo from "../../components/ordersub/ordersub-userinfo";
import ordersubShop from "../../components/ordersub/ordersub-shops";
import ordersubBtn from "../../components/ordersub/ordersub-btn";
import ordersubPricearr from "../../components/ordersub/ordersub-pricearr";
import ordersubPay from "../../components/ordersub/ordersub-pay";
import ordersubNouser from "../../components/ordersub/ordersub-nouser";
import youhui from "../../components/ordersub/ordersub-youhui";
import { requestP } from "../../static/js/request";
export default {
  components: {
    ordersubUserinfo,
    ordersubShop,
    ordersubBtn,
    ordersubPricearr,
    ordersubPay,
    ordersubNouser,
    youhui
  },
  data() {
    return {
      ifnull: false,
      ifyh: false,
      ordersubinfo: {},
      yhqprice: 0,
      yhqid: "",
      yhale: "",
      guige: "",
      canshu: {}
    };
  },
  onLoad(e) {
    console.log(e, "jiesuan0.0");
    this.canshu = e;

    this.ordersubinfo = uni.getStorageSync("ordersubinfo");
    this.canshu.addrid = this.ordersubinfo.list_address[0].address_id;
    console.log(this.ordersubinfo, "info");
    if (this.ordersubinfo.list_address.length == 0) {
    }
    if (this.ordersubinfo.list_youhuijuan.length == 0) {
        // uni.showToast({
        //   title: "您当前没有可以使用的优惠券",
        //   icon: "none",
        //   duration: 2000
        // });
        this.yhale = "没有可以使用的优惠券";
      }else{
        this.yhale = "有可以使用的优惠券";

      }
  },
  methods: {
    servicelist() {
      // uni.navigateTo({
      //   url: "/pages/shopservice/shopservice"
      // });
    },
    close(e) {
      console.log(e, 11);
      this.ifnull = e;
    },
    yhqpri(e) {
      console.log(e, "qweerew3w");
      this.yhqprice = e;
        this.yhale = "-" + e ;

    },
    yhqids(e) {
      console.log(e, "yhqid111");
      this.yhqid = e;
    },
    youhui() {
      if (this.ordersubinfo.list_youhuijuan.length == 0) {
        uni.showToast({
          title: "您当前没有可以使用的优惠券",
          icon: "none",
          duration: 2000
        });
        this.yhale = "没有可以使用的优惠券";
      } else {
        this.ifyh = true;
      }
      // this.ifyh=true
    },
    off(e) {
      this.ifyh = e;
    },
    chooseaddr() {
      console.log(this.canshu);
      uni.navigateTo({
        url:
          "/pages/chooseaddr/chooseaddr?shopid=" +
          this.canshu.shopid +
          "&guige=" +
          this.canshu.guige +
          "&num=" +
          this.canshu.num +
          "&yhqid=" +
          this.canshu.yhqid +
          "&shoptype=" +
          this.canshu.shoptype +
          "&msid=" +
          this.canshu.msid
      });
    },
    pay(e) {
      console.log(this.canshu);
      if (this.canshu.shoptype == 0) {
        // console.log(this.ordersubinfo.list_address[parseInt(this.canshu.addrkey)].address_id)
        console.log(this.ordersubinfo.list_address[0].address_id,"lkopk")
        requestP({
          url: "pay/pay_goods_do",
          data: {
            goods_id: this.canshu.shopid,
            goods_guige: this.canshu.guige,
            num: this.canshu.num,
            yhq_id: this.yhqid,
            address_id:this.canshu.addrkey?this.ordersubinfo.list_address[parseInt(this.canshu.addrkey)].address_id:this.ordersubinfo.list_address[0].address_id
          }
        }).then(res => {
          console.log(res);
          // if (res.data.code) {
          //   uni.showToast({
          //     title: "支付成功",
          //     icon: "success",
          //     duration: 2000
          //   });
          // }
        });
        console.log("asd");
      } else if (this.canshu.shoptype == 1) {
        console.log("weq");
        requestP({
          url: "pay/pay_goods_do",
          data: {
            goods_ms_id: this.canshu.msid,
            goods_guige: this.canshu.guige,
            num: this.canshu.num,
            yhq_id: this.yhqid,
            address_id: this.canshu.addrid
          }
        }).then(res => {
          console.log(res);
          if (res.data.code) {
            uni.showToast({
              title: "支付成功",
              icon: "success",
              duration: 2000
            });
          }
        });
      } else if (this.canshu.shoptype == 3) {
        console.log("weq");
        requestP({
          url: "pay/pay_cart_do",
          data: {
            cart_ids: uni.getStorageSync("cart_ids").join(','),
            yhq_id: this.yhqid,
            address_id: this.canshu.addrid
          }
        }).then(res => {
          console.log(res);
          if (res.data.code) {
            uni.showToast({
              title: "支付成功",
              icon: "success",
              duration: 2000
            });
          }
        });
      } else if (this.canshu.shoptype == 4) {
        console.log("weq");
        requestP({
          url: "pay/pay_goods_pintuan_do",
          data: {
            goods_pt_id: this.canshu.ptid,
            address_id: this.canshu.addrid,
            num: 1,
            goods_guige: this.canshu.guige
          }
        }).then(res => {
          console.log(res);
          if (res.data.code) {
            uni.showToast({
              title: "支付成功",
              icon: "success",
              duration: 2000
            });

            uni.navigateTo({
              url: "/pages/pintuanorder/pintuanorder"
            });
          }
        });
      }else if(this.canshu.shoptype==5){
         requestP({
          url: "pay/pay_goods_pintuan_do",
          data: {
            goods_pt_id: this.canshu.ptid,
            address_id: this.canshu.addrid,
            num: 1,
            goods_guige: this.canshu.guige,
            pt_order_id:this.canshu.ptorderid
          }
        }).then(res => {
          console.log(res);
          if (res.data.code) {
            uni.showToast({
              title: "支付成功",
              icon: "success",
              duration: 2000
            });

            uni.navigateTo({
              url: "/pages/pintuanorder/pintuanorder"
            });
          }
        });
      }
    }
  }
};
</script>

<style lang="scss">
Page {
  background-color: #eeeeee;
}
.shops {
  margin-top: 19upx;
  margin-bottom: 19upx;
}
.btn {
  margin-bottom: 2upx;
}
.priarr {
  margin-top: 19upx;
}
.pay {
  width: 100%;
  position: fixed;
  bottom: 0upx;
}
.youhui {
  position: absolute;
  top: 0;
  z-index: 999;
}
</style>