confirmOrder.vue 9.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
<template>
  <!-- 确认订单 -->
  <u-navbar bgColor="#F6F8FA" :placeholder="true" title="" :autoBack="true"></u-navbar>
  <view class="mainBox">
    <view class="checkAddress flexJ" @click="checkAddress" v-if="!adress.name">
      <view class="add flexA">
        <image src="/static/shopCarIc/address.png" mode=""></image>
        新增收货地址
      </view>
      <image src="/static/mineIc/gayRight.png" mode=""></image>
    </view>
    <view v-else @click="checkAddress">
      <!-- 收货地址 -->
      <shopAddres :adress="adress"></shopAddres>
    </view>
    <view class="ordersShop">
      <view class="shop flexJ" v-for="item in buyShop" :key="item.id">
        <view class="shopPhoto">
          <image :src="item.image" mode=""></image>
        </view>
        <view class="shopInfo">
          <view class="shopName ellipsis">{{ item.name }}</view>
          <view class="shopDesc ellipsis">{{ item.describe }}</view>
          <view class="price flexJ">
            <text v-if="shopType != 3">¥{{ item.goods_price }}</text>
            <view v-else class="flexA points">
              {{ orderInfo.coscore }}
              <text>积分</text>
            </view>
            <view class="num">x{{ item.total_num }}</view>
          </view>
        </view>
      </view>
      <view class="line"></view>
      <view class="modeBox flexJ">
        <text>提货方式</text>
        <view class="mode">快递配送</view>
      </view>
      <view class="modeBox flexJ" v-if="shopType == 3">
        <text>运费</text>
        <view class="yunPrice">¥{{ orderInfo.express_price }}</view>
      </view>
    </view>
    <view class="btnsBox iosAuto flexJ">
      <!-- 积分购买 -->
      <view class="pointsPrcie flexV" v-if="shopType == 3">
        <view class="allPoints flexA">
          <view class="all">合计:</view>
          <view class="pointsNum">
            {{ orderInfo.coscore }}
            <text>积分</text>
          </view>
        </view>
        <view class="pointsMoeny">{{ orderInfo.express_price }}元</view>
      </view>
      <!-- 非积分购买 -->
      <view class="allMoney flexA" v-else>
        <text>总价:</text>
        {{ orderInfo.total_price }}
      </view>
      <view class="btn flexC" @click="btns">{{ shopType == 3 ? '立即兑换' : '立即购买' }}</view>
    </view>
    <!-- 选择支付方式弹窗 -->
    <payMode @canclePop="modeShow = false" :car_Id="car_Id" :balance="balance" :totalPrice="orderInfo.total_price" :adressId="adress.id" :payParams="payParams" :modeShow="modeShow"></payMode>
    <!-- 确认积分兑换弹窗 -->
    <tipPop @pointsBtns="pointsBtns" :integral="orderInfo.coscore" :tipShow="tipShow"></tipPop>
  </view>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import payMode from '@/componets/checkPayMode.vue'
import tipPop from '@/componets/tipPop.vue'
import shopAddres from '@/componets/address.vue'
import { getbBuyData, getCarsettlement, getyue } from '@/api/'
onLoad(e => {
  if (e.ids) {
    car_Id.value = e.ids
    getCarsettlements(e.ids) //购物车结算
  } else {
    shopType.value = e.shopType //商品类型
    payParams.value = JSON.parse(e.params) //规格id 商品数量 商品id
    getbBuyDatas(JSON.parse(e.params))
    console.log(e.params, '商品规格信息')
  }
  //默认地址
  uni.getStorageSync('defaultAdres') ? (adress.value = uni.getStorageSync('defaultAdres')) : ''
})
onShow(() => {
  // 余额
  getyues()
  // uni.getStorageSync('balance') ? balance.value = uni.getStorageSync('balance') : ''
})
let modeShow = ref(false) //选择支付方式
let payParams = ref({}) //支付参数
let shopType = ref(1) // 1=普通商品,2=特价商品,3=积分商品
let car_Id = ref('') //购物车结算商品的购物车id
let balance = ref(0) //余额
let buyShop = ref([]) //购买de商品
let orderInfo = ref({}) //购买信息
// 购买商品信息
const getbBuyDatas = async obj => {
  try {
    let params = {
      goods_id: obj.id, //integer	是	商品ID
      num: obj.num, //integer	是	数量
      goods_spec_id: obj.specId //integer	是	规格ID
    }
    const res = await getbBuyData(params)
    buyShop.value = res.goods_list //购买de商品
    orderInfo.value = res //购买信息
    console.log('getbBuyData', res)
    // 保存数据
  } catch (err) {
    uni.showToast({ title: err, icon: 'none' })
    console.log('getbBuyData', err)
  }
}

const getyues = async () => {
  try {
    const res = await getyue()
    balance.value = res.money
    // 保存数据
  } catch (err) {
    uni.showToast({ title: err, icon: 'none' })
    console.log('getyue', err)
  }
}

// 购物车结算
const getCarsettlements = async ids => {
  try {
    const res = await getCarsettlement(ids)
    buyShop.value = res.goods_list //购买de商品
    orderInfo.value = res //购买信息
    console.log('getCarsettlement', res)
    // 保存数据
  } catch (err) {
    uni.showToast({ title: err, icon: 'none' })
    console.log('getCarsettlement', err)
  }
}
let adress = ref({}) //收货地址
// 选择地址
const checkAddress = () => {
  uni.navigateTo({
    url: `/pages/mine/myAddress?isCheck=${1}`,
    events: {
      steBack: data => {
        adress.value = data
        console.log('地址', data)
      }
    }
  })
}
// 是否使用积分弹窗
const tipShow = ref(false)
// 是否使用积分 0否 1 是
const pointsBtns = type => {
  tipShow.value = false
  if (type == 1) {
    modeShow.value = true
  }
}
// 立即购买按钮 shopType== 1 || 2立即购买 ==  shopType==3立即兑换按钮
const btns = () => {
  if (shopType.value == 3) {
    console.log('立即兑换按钮')
    if (uni.getStorageSync('myPoints') < orderInfo.value.coscore) return uni.showToast({ title: '您的积分不足~', icon: 'none' })
    tipShow.value = true
  } else {
    modeShow.value = true
    console.log('立即购买')
  }
}
</script>

<style lang="scss">
page {
  background: #f6f8fa;
}

.mainBox {
  width: 100%;
  padding: 20rpx 24rpx 0;
  box-sizing: border-box;

  .checkAddress {
    width: 100%;
    padding: 24rpx 20rpx 26rpx;
    box-sizing: border-box;
    border-radius: 24rpx;
    background: #ffffffff;
    margin-bottom: 20rpx;

    .add {
      color: #323233ff;
      font-size: 28rpx;
      font-weight: 700;

      image {
        width: 32rpx;
        height: 32rpx;
        margin-right: 16rpx;
      }
    }

    image {
      width: 16rpx;
      height: 32rpx;
    }
  }

  .addressBox {
    margin-bottom: 20rpx;
    padding: 32rpx 20rpx 31rpx 32rpx;
    background: #fff;

    .right {
      display: flex;

      image {
        width: 32rpx;
        height: 32rpx;
        margin-right: 8rpx;
        margin-top: 9rpx;
      }

      .area {
        text {
          color: #323233ff;
          font-size: 28rpx;
          font-weight: 700;
          line-height: 36rpx;
        }

        .name {
          color: #646566ff;
          font-size: 24rpx;
          margin-top: 9rpx;
        }
      }
    }

    image {
      width: 16rpx;
      height: 32rpx;
    }
  }

  .ordersShop {
    width: 100%;
    padding: 24rpx 20rpx 32rpx 20rpx;
    box-sizing: border-box;
    border-radius: 24rpx;
    background-color: #fff;

    .shop {
      margin-bottom: 24rpx;

      .shopPhoto {
        width: 180rpx;
        height: 180rpx;
        margin-right: 20rpx;

        image {
          width: 180rpx;
          height: 180rpx;
          border-radius: 16rpx;
        }
      }

      .shopInfo {
        width: 100%;

        .shopName {
          color: #323233ff;
          font-size: 26rpx;
          font-weight: 700;
        }

        .shopDesc {
          margin: 16rpx 0 58rpx;
          color: #00000066;
          font-size: 20rpx;
        }

        .price {
          width: 100%;

          text {
            color: #fc4338ff;
            font-size: 28rpx;
            font-weight: 700;
          }

          .num {
            color: #323233ff;
            font-size: 26rpx;
          }

          .points {
            color: #000000e6;
            font-size: 32rpx;
            font-weight: 700;

            text {
              margin: 6rpx 0 0 8rpx;
              color: #000000e6;
              font-size: 22rpx;
            }
          }
        }
      }
    }

    .line {
      margin: 40rpx 0 33rpx;
      width: 100%;
      height: 1rpx;
      opacity: 1;
      background: #eeeff0ff;
    }

    .modeBox {
      margin-top: 32rpx;
      text {
        color: #000000e6;
        font-size: 26rpx;
      }

      .mode {
        color: #000000e6;
        font-size: 26rpx;
        font-weight: 700;
      }

      .yunPrice {
        color: #fc4338ff;
        font-size: 26rpx;
        font-weight: 700;
      }
    }
  }
}

.btnsBox {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 96rpx;
  opacity: 1;
  background: #ffffffff;

  .allMoney {
    margin-left: 32rpx;
    color: #fc4338ff;
    font-size: 40rpx;
    font-weight: 700;

    text {
      color: #000000ff;
      font-size: 32rpx;
      font-weight: 700;
    }
  }

  .btn {
    margin-right: 24rpx;
    width: 256rpx;
    height: 80rpx;
    border-radius: 80rpx;
    color: #ffffffff;
    font-size: 30rpx;
    font-weight: 700;
    background: linear-gradient(-88deg, #fe6434ff 0%, #ff2f2fff 100%);
  }

  .pointsPrcie {
    margin-left: 32rpx;

    .allPoints {
      .all {
        color: #000000ff;
        font-size: 30rpx;
        font-weight: 700;
      }

      .pointsNum {
        margin-left: 12rpx;
        color: #fc4338ff;
        font-size: 40rpx;
        font-weight: 700;

        text {
          margin: 8rpx 0 0 8rpx;
          color: #fc4338ff;
          font-size: 22rpx;
        }
      }
    }

    .pointsMoeny {
      color: #00000099;
      font-size: 24rpx;
    }
  }
}
</style>