123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826 |
- <template>
- <view class="container">
- <view class="address-info-box" @click="selectAddress()">
- <view class="address-icon">
- <text class="iconfont icondizhi"></text>
- </view>
- <view class="address-content">
- <text class="address-info">
- <text class="address-name">{{addressData.username}}</text>
- <text class="address-phone">{{addressData.phone}}</text>
- </text>
- <view class="address-detail">{{addressData.address}}</view>
- </view>
- <view class="address-link">
- <text class="iconfont iconfangxiang"></text>
- </view>
- </view>
- <view class="goods-info-box">
- <view class="shop-info">
- <text class="iconfont icondianpu"></text>
- <text class="shop-name">{{orderData.supplierName}}</text>
- <text class="iconfont iconfangxiang"></text>
- </view>
- <view class="goods-list">
- <view class="goods-row" v-for="(item, index) in orderData.goodsList" :key="index">
- <image class="goods-img" mode="aspectFill" :src="item.imgUrl"></image>
- <view class="goods-info">
- <view class="goods-name">{{item.productName}}</view>
- <view class="goods-type">
- 类型:{{item.productType == 1 ? '普通商品' : (item.productType == 2 ? '拍卖商品' : (item.productType == 3 ? '自助采摘' : '共享种植'))}}
- </view>
- <view class="plant-area" v-if="orderType == 3">面积:{{orderData.areaSize}}㎡</view>
- <view class="goods-price-number">
- <text class="goods-unit">¥</text>
- <text class="goods-price">{{(orderType == 1 || orderType == 3) ? item.bizPrice : paySum}}</text>
- <text class="goods-number">x{{item.buyNum}}</text>
- <text class="plant-text" v-if="orderType == 3">有效期:{{orderData.term}}天</text>
- </view>
- </view>
- </view>
- </view>
- <view class="order-info">
- <u-cell-group :border="false">
- <u-cell-item title="商品金额" :arrow="false" :border-bottom="false" title-width="170" :title-style="{textAlign: 'right'}">
- <text class="order-text-right">¥{{(orderType == 1 || orderType == 3) ? getAllGoodsInitialPrice() : paySum}}</text>
- </u-cell-item>
- <u-cell-item title="积分抵扣" :arrow="false" :border-bottom="false" title-width="170" :title-style="{textAlign: 'right'}"
- v-if="orderType == 1">
- <view>
- <text class="order-text-left">-{{getIntegral()+'积分'}}</text>
- <text class="order-text-right">-¥{{(getIntegral()/100).toFixed(2)}}</text>
- </view>
- </u-cell-item>
- <u-cell-item title="优惠券" :border-bottom="false" title-width="170" :title-style="{textAlign: 'right'}" @click="showCoupon()"
- v-if="orderType == 1">
- <view>
- <text class="order-text-left">{{coupon.couponName}}</text>
- <text class="order-text-right">{{couponList.length ? ('-¥'+coupon.discountAmount) : '无可用优惠券'}}</text>
- </view>
- </u-cell-item>
- <u-field label="备注" v-model="notes" placeholder="请输入备注" :border-bottom="false" label-align="right" label-width="170"
- :field-style="{marginLeft: '16px'}"></u-field>
- </u-cell-group>
- </view>
- <view class="pay-info">
- <text class="pay-text">共{{getAllGoodsNumber()}}件</text>
- <text class="pay-text">总计</text>
- <text class="pay-price">¥{{(orderType == 1 || orderType == 3) ? getAllGoodsPrice() : paySum}}</text>
- </view>
- </view>
- <view class="handle-box">
- <view class="handle-info">
- <text class="handle-text" style="margin-right: 12px;">共{{getAllGoodsNumber()}}件</text>
- <text class="handle-text">合计:</text>
- <text class="handle-price">¥{{(orderType == 1 || orderType == 3) ? getAllGoodsPrice() : paySum}}</text>
- </view>
- <view class="handle-button" @click="submitOrder()">提交订单</view>
- </view>
- <uni-popup ref="popup" type="bottom">
- <view class="coupon-box">
- <view class="coupon-row" v-for="(item, index) in couponList" :key="index" @click="selectCoupon(item)">
- <view class="coupon-left">
- <view class="coupon-left-price"><text style="font-size: 16px;">¥</text>{{item.discountAmount}}</view>
- <view class="coupon-left-text">满减金额</view>
- </view>
- <view class="coupon-info">
- <view class="coupon-text1">{{item.couponName}}</view>
- <view class="coupon-text1" style="margin-bottom: 4px;">满{{item.fullAmount}}减{{item.discountAmount}}</view>
- <view class="coupon-text2">{{item.couponType == 1 ? '仅限用于' + item.supplierName + '的店铺' : ''}}</view>
- <view class="coupon-text2" style="color: #999999;">有效期:{{item.publishStartTime}}~{{item.useEndTime}}</view>
- </view>
- </view>
- </view>
- </uni-popup>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- data() {
- return {
- flag: 1,
- orderType: 1,
- addressData: {
- memberAddressId: '',
- username: '',
- phone: '',
- province: '',
- city: '',
- area: '',
- address: '',
- },
- userData: {},
- orderData: {
- tenantCode: '',
- supplierName: '',
- areaSize: '',
- term: '',
- goodsList: []
- },
- integral: 0,
- coupon: {
- couponId: '',
- couponName: '',
- discountAmount: 0,
- couponType: '',
- },
- couponList: [],
- notes: '',
- paySum: 0,
- mineIntegral: {},
- orderId: '',
- goodType: false,
- }
- },
- onLoad(options) {
- this.orderType = options.orderType
- this.paySum = options.paySum ? options.paySum : 0
- this.flag = options.flag
- this.userData = uni.getStorageSync("userData")
- this.orderData = uni.getStorageSync("orderData")
- if (!uni.getStorageSync("defaultAddress")) {
- NET.request(API.getAddressList, {}, 'POST').then(res => {
- if (res.data.find(site => site.isDefault == 1)) {
- let address = res.data.find(site => site.isDefault == 1)
- this.addressData = {
- memberAddressId: address.id,
- username: address.username,
- phone: address.phone,
- province: address.province,
- city: address.city,
- area: address.area,
- address: address.address
- }
- }
- }).catch(error => {
- this.$refs.uTips.show({
- title: '获取默认地址失败',
- type: 'warning',
- })
- })
- }
- if (this.orderType == 1) {
- NET.request(API.getIntegral, {}, 'POST').then(res => {
- this.integral = res.data.usableIntegral
- }).catch(error => {
- this.$refs.uTips.show({
- title: '获取个人积分失败',
- type: 'warning',
- })
- })
- NET.request(API.getUsableCouponList, {
- tenantCode: this.orderData.tenantCode,
- totalPrice: this.getAllGoodsInitialPrice(),
- }, 'GET').then(res => {
- this.couponList = res.data
- }).catch(error => {
- this.$refs.uTips.show({
- title: res.msg,
- type: 'warning',
- })
- })
- }
- },
- onReady() {
- this.goodType = (this.orderData.goodsList.filter(site => site.productType == 3).length > 0) ? 3 : ''
- },
- onShow() {
- if (uni.getStorageSync("defaultAddress")) {
- this.addressData = uni.getStorageSync("defaultAddress")
- }
- },
- methods: {
- // 获取全部商品原价格
- getAllGoodsInitialPrice() {
- let price = this.orderData.goodsList.reduce((total, site) => {
- return total + site.bizPrice * site.buyNum
- }, 0)
- return price.toFixed(2)
- },
- // 获取全部价格
- getAllGoodsPrice() {
- let price = this.orderData.goodsList.reduce((total, site) => {
- return total + site.bizPrice * site.buyNum
- }, 0)
- return (price - this.coupon.discountAmount - (this.getIntegral() / 100)).toFixed(2)
- },
- // 获取全部商品数量
- getAllGoodsNumber() {
- let number = this.orderData.goodsList.reduce((total, site) => {
- return total + site.buyNum
- }, 0)
- return number
- },
- // 选择地址
- selectAddress() {
- uni.navigateTo({
- url: '/pagesMain/addressList?type=2'
- });
- },
- // 获取积分
- getIntegral() {
- let price = this.orderData.goodsList.reduce((total, site) => {
- return total + site.bizPrice * site.buyNum
- }, 0) - this.coupon.discountAmount
- if (this.integral / 100 > price) {
- return price * 100
- } else {
- return this.integral
- }
- },
- // 显示优惠券弹窗
- showCoupon() {
- if (!this.couponList.length) {
- return
- }
- this.$refs.popup.open()
- },
- // 选择优惠券
- selectCoupon(item) {
- this.coupon = {
- couponId: item.couponId,
- couponName: item.couponName,
- discountAmount: parseFloat(item.discountAmount).toFixed(2),
- couponType: item.couponType,
- }
- this.$refs.popup.close()
- },
- // 提交订单
- submitOrder() {
- if (!this.addressData.username) {
- this.$refs.uTips.show({
- title: '请选择地址',
- type: 'warning',
- })
- } else {
- let paySum = (this.orderType == 1 || this.orderType == 3) ? this.getAllGoodsPrice() : this.paySum
- NET.request(API.submitOrder, {
- // 会员
- mid: this.userData.userId,
- nickname: this.userData.userName,
- // 地址
- ...this.addressData,
- // 商铺
- supplierName: this.orderData.supplierName,
- tenantCode: this.orderData.tenantCode,
- // 商品
- productIds: this.orderData.goodsList.map(site => {
- return site.productId
- }).join(','),
- productType: this.orderData.goodsList.map(site => {
- return site.productType
- }).join(','),
- products: this.orderData.goodsList.map(site => {
- return {
- ...site,
- supplierName: this.orderData.supplierName,
- tenantCode: this.orderData.tenantCode,
- bizPrice: (this.orderType == 1 || this.orderType == 3) ? site.bizPrice : this.paySum,
- }
- }),
- // 优惠券
- couponId: this.orderType == 1 ? this.coupon.couponId : '',
- // 优惠券优惠总额
- couponDiscountAmount: this.orderType == 1 ? this.coupon.discountAmount : '',
- couponType: this.orderType == 1 ? this.coupon.couponType : '',
- // 积分
- integralValue: this.orderType == 1 ? this.getIntegral() : 0,
- // 积分优惠总额
- integralAmount: this.orderType == 1 ? this.getIntegral() / 100 : 0,
- // 总优惠金额
- discountAmount: this.orderType == 1 ? (parseFloat(this.coupon.discountAmount) + (this.getIntegral() / 100)) : 0, // 订单总金额(优惠前)
- orderSum: (this.orderType == 1 || this.orderType == 3) ? this.orderData.goodsList.reduce((total, site) => {
- return total + site.bizPrice * site.buyNum
- }, 0) : this.paySum,
- paySum: (this.orderType == 1 || this.orderType == 3) ? this.getAllGoodsPrice() : this.paySum,
- // 支付类型
- flag: this.flag,
- orderType: this.orderType,
- // 备注
- notes: this.notes,
- // #ifdef APP-PLUS
- channel: 2
- //#endif
- }, 'POST').then(res => {
- console.log('提交订单', res)
- if (res.isSuccess) {
- if (res.data) {
- this.orderId = res.data.orderId
- if (paySum == '0.00') {
- this.$refs.uTips.show({
- title: '购买成功',
- type: 'success',
- })
- setTimeout(() => {
- uni.navigateTo({
- url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
- });
- }, 1000)
- return;
- }
- if (this.goodType == 3) {
- setTimeout(() => {
- uni.redirectTo({
- url: '/pagesMain/paySuccess?orderId=' + this.orderId + '&orderStatus=' + 1 + '&goodType=' + this.goodType + '&tenantCode=' + res.data.tenantCode
- });
- }, 1000)
- return;
- }
- // #ifdef MP-WEIXIN
- uni.requestPayment({
- provider: 'wxpay',
- timeStamp: res.data.timeStamp,
- nonceStr: res.data.nonceStr,
- package: res.data.packageValue,
- signType: res.data.signType,
- paySign: res.data.paySign,
- success: (payRes) => {
- console.log('success:' + JSON.stringify(payRes));
- uni.redirectTo({
- url: '/pagesMain/paySuccess?orderId=' + this.orderId + '&orderStatus=' + 2
- });
- },
- fail: (error) => {
- console.log('fail:' + JSON.stringify(error));
- this.$refs.uTips.show({
- title: '支付未成功',
- type: 'warning',
- })
- setTimeout(() => {
- // uni.redirectTo({
- // url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
- // });
- uni.navigateTo({
- url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
- });
- }, 1000)
- }
- })
- //#endif
-
- // #ifdef APP-PLUS
- uni.requestPayment({
- provider: 'wxpay',
- orderInfo:{
- "package": res.data.packageValue,
- "appid": res.data.appId,
- "sign": res.data.paySign,
- "partnerid": res.data.partnerId,
- "prepayid": res.data.prepayId,
- "noncestr": res.data.nonceStr,
- "timestamp": res.data.timeStamp,
- },
- success: (payRes) => {
- console.log('paySuccess:' + JSON.stringify(payRes));
- uni.redirectTo({
- url: '/pagesMain/paySuccess?orderId=' + this.orderId + '&orderStatus=' + 2
- });
- },
- fail: (error) => {
- console.log('payfail:' + JSON.stringify(error));
- this.$refs.uTips.show({
- title: '支付未成功',
- type: 'warning',
- })
- setTimeout(() => {
- // uni.redirectTo({
- // url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
- // });
- uni.navigateTo({
- url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
- });
- }, 1000)
- }
- })
- //#endif
- } else {
- uni.redirectTo({
- url: '/pagesMain/paySuccess'
- });
- }
- }
- }).catch(error => {
- console.log('error提交订单失败:', error);
- this.$refs.uTips.show({
- title: error.data.msg,
- type: 'warning',
- })
- })
- }
- },
- },
- }
- </script>
- <style lang="less" scoped>
- page {
- width: 100%;
- height: 100%;
- }
- .container {
- width: 100%;
- // height: 100%; // 100%不行,屏幕长时底下有留白
- height: 100vh;
- float: left;
- background-color: #f7f7f7;
- box-sizing: border-box;
- padding-bottom: 70px;
- overflow-y: auto;
- .address-info-box {
- width: calc(100% - 32px);
- float: left;
- box-sizing: border-box;
- padding: 16px 18px 16px 16px;
- margin: 10px 16px;
- background: #FFFFFF;
- border-radius: 10px;
- .address-icon {
- width: 36px;
- height: 40px;
- float: left;
- align-items: center;
- display: flex;
- .iconfont {
- color: #52A63A;
- font-size: 36px;
- }
- }
- .address-content {
- width: calc(100% - 66px);
- height: 40px;
- float: left;
- margin: 0 8px 0 12px;
- .address-info {
- height: 20px;
- font-family: PingFang SC;
- line-height: 20px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- .address-name {
- font-size: 16px;
- color: #333333;
- margin-right: 14px;
- }
- .address-phone {
- font-size: 12px;
- color: #666666;
- }
- }
- .address-detail {
- height: 20px;
- font-size: 16px;
- font-family: PingFang SC;
- color: #333333;
- line-height: 20px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- }
- .address-link {
- width: 10px;
- height: 40px;
- float: left;
- align-items: center;
- display: flex;
- .iconfont {
- color: #999999;
- font-size: 12px;
- }
- }
- }
- .goods-info-box {
- width: calc(100% - 32px);
- float: left;
- margin: 0 16px 10px 16px;
- background: #FFFFFF;
- border-radius: 10px;
- .shop-info {
- width: 100%;
- height: 48px;
- float: left;
- box-sizing: border-box;
- padding: 13px 15px 12px 15px;
- border-bottom: 1px solid #EEEEEE;
- line-height: 22px;
- .icondianpu {
- font-size: 22px;
- color: #333333;
- }
- .shop-name {
- font-size: 15px;
- font-family: PingFang SC;
- color: #333333;
- margin: 0 8px 0 10px;
- }
- .iconshangjia {
- font-size: 12px;
- color: #999999;
- }
- }
- .goods-list {
- width: 100%;
- float: left;
- box-sizing: border-box;
- padding: 10px 15px 0 15px;
- .goods-row {
- width: 100%;
- height: 90px;
- float: left;
- display: flex;
- margin-bottom: 10px;
- .goods-img {
- width: 90px;
- height: 90px;
- border-radius: 5px;
- object-fit: cover;
- }
- .goods-info {
- width: calc(100% - 106px);
- height: 90px;
- margin-left: 16px;
- .goods-name {
- width: 100%;
- height: 36px;
- float: left;
- font-size: 14px;
- font-family: PingFang SC;
- color: #333333;
- line-height: 18px;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- word-wrap: break-word;
- }
- .goods-type {
- height: 20px;
- float: left;
- background: #F0F0F0;
- border-radius: 4px;
- padding: 0 8px;
- margin: 6px 0;
- font-size: 10px;
- font-family: PingFang SC;
- color: #666666;
- line-height: 20px;
- }
- .plant-area {
- height: 20px;
- float: right;
- margin: 6px 0;
- font-size: 12px;
- font-family: PingFang SC;
- color: #333333;
- }
- .goods-price-number {
- width: 100%;
- height: 20px;
- float: left;
- line-height: 20px;
- font-family: PingFang SC;
- color: #333333;
- .goods-unit {
- font-size: 12px;
- }
- .goods-price {
- font-size: 15px;
- margin-right: 6px;
- }
- .goods-number {
- font-size: 12px;
- }
- }
- .plant-text {
- float: right;
- font-size: 12px;
- font-family: PingFang SC;
- color: #333333;
- }
- }
- }
- }
- .order-info {
- width: 100%;
- float: left;
- .order-text-left {
- font-size: 13px;
- font-family: PingFang SC;
- color: #666666;
- float: left;
- margin-left: 16px;
- }
- .order-text-right {
- font-size: 13px;
- font-family: PingFang SC;
- color: #52A63A;
- }
- /deep/.u-cell_title {
- color: #333333;
- }
- /deep/.u-label-text {
- color: #333333;
- }
- }
- .pay-info {
- width: 100%;
- height: 46px;
- float: left;
- box-sizing: border-box;
- border-top: 1px solid #EEEEEE;
- padding-right: 15px;
- line-height: 44px;
- font-family: PingFang SC;
- font-size: 14px;
- text-align: right;
- white-space: nowrap;
- .pay-text {
- color: #333333;
- margin-right: 6px;
- }
- .pay-price {
- color: #52A63A;
- }
- }
- }
- .handle-box {
- width: 100%;
- height: 70px;
- box-sizing: border-box;
- padding: 15px 0 15px 16px;
- position: fixed;
- bottom: 0;
- background: #FFFFFF;
- box-shadow: 0px 3px 13px 0px rgba(0, 0, 0, 0.15);
- .handle-info {
- width: calc(100% - 110px);
- height: 40px;
- float: left;
- line-height: 40px;
- font-family: PingFang SC;
- text-align: left;
- white-space: nowrap;
- .handle-text {
- font-size: 16px;
- color: #666666;
- }
- .handle-price {
- font-size: 15px;
- color: #52A63A;
- }
- }
- .handle-button {
- width: 100px;
- height: 40px;
- float: right;
- box-sizing: border-box;
- padding-left: 10px;
- background: #52A63A;
- border-radius: 20px 0px 0px 20px;
- font-size: 15px;
- font-family: PingFang SC;
- color: #FFFFFF;
- line-height: 40px;
- text-align: center;
- }
- }
- .coupon-box {
- width: 100vw;
- height: 500px;
- background-color: #FFFFFF;
- border-radius: 15px 15px 0px 0px;
- box-sizing: border-box;
- padding: 16px 16px 0 16px;
- overflow-y: auto;
- .coupon-row {
- width: 100%;
- height: 105px;
- float: left;
- margin-bottom: 10px;
- border-radius: 10px;
- background: #FFFFFF;
- box-shadow: 0px 0px 10px 0px rgba(103, 103, 103, 0.3);
- overflow: hidden;
- .coupon-left {
- width: 107px;
- height: 105px;
- box-sizing: border-box;
- padding-right: 10px;
- float: left;
- background-size: 107px 105px;
- background-position: center;
- background-repeat: no-repeat;
- background-image: url(@/static/images/couponHead.png);
- .coupon-left-price {
- width: 100%;
- height: 24px;
- float: left;
- margin: 28px 0 12px 0;
- font-size: 24px;
- font-family: PingFang SC;
- color: #FFFFFF;
- line-height: 24px;
- text-align: center;
- }
- .coupon-left-text {
- width: 100%;
- height: 20px;
- float: left;
- color: #FFFFFF;
- font-size: 12px;
- font-family: PingFang SC;
- line-height: 20px;
- text-align: center;
- }
- }
- .coupon-info {
- width: calc(100% - 115px);
- height: 100%;
- float: right;
- box-sizing: border-box;
- padding: 16px 0 12px 0;
- .coupon-text1 {
- width: 100%;
- height: 20px;
- float: right;
- font-size: 15px;
- font-family: PingFang SC;
- color: #333333;
- line-height: 20px;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- }
- .coupon-text2 {
- width: 100%;
- height: 18px;
- float: right;
- font-size: 13px;
- font-family: PingFang SC;
- color: #EB5F2F;
- line-height: 18px;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- }
- }
- }
- }
- }
- </style>
|