<template>
  <view class="">
    <view v-if="!isAddress" class="m-card row">
      <up-cell-group>
        <up-cell title="我的地址" :isLink="true" :border="false" @click="showAddress=true"></up-cell>
      </up-cell-group>
    </view>
    <view v-else class="m-card m-address">
      <view class="address-info">
        <view class="top">
          <up-icon name="map"></up-icon>
          <view class="t-name">小王</view>
          <view>155****9999</view>
        </view>
        <view class="bottom u-line-2">
          四川泸州市龙马潭区莲花池街道商业街1号
        </view>
      </view>
      <view class="address-btn">
        <view style="width: 80px;"><up-button @click="showAddress = true" size="small" shape="circle" color="#f6f6f6"
            :customStyle="{color:'#666666'}">修改</up-button></view>
      </view>
    </view>
    <view class="m-card row">
      <up-cell-group>
        <up-cell title="请添加自提点" :isLink="true" :border="false"></up-cell>
      </up-cell-group>
    </view>
    <view class="m-card m-good">
      <image class="image" src="../../static/logo.png"></image>
      <view class="body-content">
        <view>
          <view class="title">
            <view>黄牛肉20kg</view>
            <view>¥10.00</view>
          </view>
          <view class="tips">
            <view>我不吃牛肉</view>
            <view>x5</view>
          </view>
        </view>
        <view class="time">
          预计48小时发货
        </view>
      </view>
    </view>
    <view class="m-card good-info">
      <view class="head-title">价格明细</view>
      <view class="row">
        <view>商品总价 <text>共计5件商品</text></view>
        <view><text>¥</text>50<text>.00</text></view>
      </view>
      <view class="row">
        <view>运费</view>
        <view><text>¥</text>0<text>.00</text></view>
      </view>
    </view>
    <view class="m-card good-info">
      <view class="head-title">支付方式</view>
      <view class="row">
        <view class="icon-text"><up-icon name="weixin-circle-fill" color="#20b128" size="22"
            style="margin-right: 10rpx;"></up-icon> 微信支付</view>
        <view class="icon">
          <image v-if="true" src="@/static/icon/check.png"></image>
          <image v-else src="@/static/icon/n-check.png"></image>
        </view>
      </view>
    </view>
    <view class="m-card order-remark">
      <view class="head-title">
        <text>订单备注</text>
        <text>0/200</text>
      </view>
      <up-textarea style="background-color: #F6F6F6;" v-model="formData.remark" placeholder="暂无备注内容"
        :height="100"></up-textarea>
    </view>
    <view class="fiexd-btn-box">
      <view class="tips">
        <view style="margin-right: 20rpx;">80款，共500件</view>
        <view class="all">
          <text style="color: #000;">合计: </text>
          <text>￥</text>
          <text style="font-size: 32rpx;font-weight: bold;">5620</text>
          <text>.26</text>
        </view>
      </view>
      <view style="width: 200rpx;">
        <up-button color="#20B128" shape="circle" @click="submitOrder">提交订单</up-button>
      </view>
    </view>

    <addressPopup :show="showAddress" @close="showAddress=false" @change="changeAddress" />
    <modal title="尚未设置收货地址" content="您还没有添加收货地址，请点击添加" cancleText="添加地址" confirmText="继续支付" :show="toastAddressShow"
      @close="addAddress" @change="goPay" />
  </view>
</template>

<script setup>
  import { nextTick, ref } from "vue"
  import addressPopup from "@/components/addressPopup.vue";
  import modal from "@/components/modal.vue"

  const formData = ref({
    remark: ""
  })

  const isAddress = ref(false);
  const toastAddressShow = ref(false);

  // 选择地址
  const showAddress = ref(false);
  const changeAddress = (e) => {
    showAddress.value = false;
    isAddress.value = true;
    console.log(e);
  }
  
  // 选择地址
  const addAddress = () => {
    toastAddressShow.value = false;
    nextTick(()=>{
      showAddress.value = true;
    })
  }
  // 继续支付
  const goPay = ()=>{
    toastAddressShow.value = false;
    isAddress.value = true;
    submitOrder();
  }

  // 提交订单
  const submitOrder = () => {
    if (!isAddress.value) return toastAddressShow.value = true;
    uni.$u.toast('支付成功')
  }
</script>

<style lang="scss">
  .m-card {
    margin: 20rpx;
    border-radius: 14rpx;
    background-color: #fff;
    padding: 20rpx;
  }

  .row {
    padding: 0;
    overflow: hidden;
  }

  .m-address {
    margin-bottom: 20rpx;
    display: flex;
    justify-content: space-between;
    color: #999999;

    .address-info {
      width: 510rpx;

      .top {
        display: flex;
        font-size: 28rpx;

        .t-name {
          color: #444;
          margin: 0 10rpx;
        }
      }

      .bottom {
        font-size: 24rpx;
      }
    }
  }

  .m-good {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20rpx;

    .image {
      width: 160rpx;
      height: 160rpx;
      margin-right: 20rpx;
    }

    .body-content {
      width: 490rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      color: #989898;

      .title {
        display: flex;
        justify-content: space-between;
        font-size: 28rpx;
        color: #444;
      }

      .tips {
        display: flex;
        justify-content: space-between;
        font-size: 24rpx;
        margin-top: 10rpx;
      }

      .time {
        background-color: #F6F6F6;
        padding: 5rpx 10rpx;
        font-size: 26rpx;
        color: #444;
        border-radius: 10rpx;
      }
    }
  }

  .good-info {
    margin-bottom: 20rpx;

    .head-title {
      margin-bottom: 18rpx;
      color: #000;
      font-weight: bold;
    }

    .row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 18rpx;

      .red {
        color: #F55726;
      }

      .icon-text {
        display: flex;
      }

      .icon {
        image {
          width: 40rpx;
          height: 40rpx;
        }
      }
    }

    .row-need {
      display: flex;
      justify-content: flex-end;
      color: #F55726;
    }

    text {
      font-size: 22rpx;
    }
  }

  .order-remark {
    .head-title {
      margin-bottom: 18rpx;
      display: flex;
      justify-content: space-between;
    }
  }

  .tips {
    font-size: 28rpx;
    color: #999;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex: 1;
    margin-right: 20rpx;

    .all {
      color: #F55726;
    }
  }
</style>