123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- <template>
- <view class="padding-t-30">
- <!-- 地址 -->
- <navigator url="/pages/set/address?source=1" class="address-section">
- <view class="order-content" v-if="addressData.real_name">
- <view class="cen">
- <view class="top">
- <text class="name">{{ addressData.real_name }}</text>
- <text class="mobile">{{ addressData.phone }}</text>
- </view>
- <text
- class="address flex">{{ addressData.province + addressData.city + addressData.district }}{{ addressData.detail }}</text>
- </view>
- <text class="iconfont iconenter"></text>
- </view>
- <view class="order-content" v-if="!addressData.real_name">
- <view class="addAddress">
- <text class="iconfont iconaddition"></text>
- <text>添加收货地址</text>
- </view>
- </view>
- </navigator>
- <view class="goodsList">
- <view class="goods-section" v-for="(ls, ind) in shopList" :key="ind">
- <!-- 商品列表 -->
- <view class="g-item">
- <image :src="ls.productInfo.image"></image>
- <view class="right">
- <text class="title clamp">{{ ls.productInfo.store_name }}</text>
- <text class="spec">{{ ls.productInfo.attrInfo ? ls.productInfo.attrInfo.suk : '默认' }}</text>
- <view class="price-box">
- <text
- class="price">¥{{ ls.productInfo.attrInfo ? ls.productInfo.attrInfo.price : ls.productInfo.price }}</text>
- <text class="number">{{ 'x ' + ls.cart_num + (ls.productInfo.unit_name || '') }}</text>
- <!-- <view class="number">
- <uni-number-box class="step" :value="lss.number" :index="indx" @eventChange="numberChange"></uni-number-box>
- </view> -->
- </view>
- <view class="serverSet" v-if="ls.day>0">
- (<text>服务费:{{ls.day_deducted}}</text>
- <text class="margin-l-10">服务天数:{{ls.day}}天</text>)
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 金额明细 -->
- <view class="yt-list">
- <view class="yt-list-cell b-b">
- <text class="cell-tit clamp">运费</text>
- <text class="cell-tip disabled">{{ Postage }}</text>
- </view>
- <view class="yt-list-cell b-b">
- <text class="cell-tit clamp">备注</text>
- <input class="desc" type="text" v-model="desc" placeholder="请填写备注信息" placeholder-class="placeholder" />
- </view>
- </view>
- <view class="yt-list">
- <view class="yt-list-cell b-b" v-if="fx" @click="payType='weixin'">
- <view class="cell-tit flex">
- <image class="orderIcon" src="../../static/icon/orderWx.png" mode="widthFix"></image>
- <text class="margin-l-10">微信支付</text>
- </view>
- <image class="checked" v-if="payType=='weixin'" src="../../static/icon/addressIconXz.png"
- mode="widthFix"></image>
- <view v-else class="noChecked"></view>
- </view>
- <!-- #ifdef APP-PLUS -->
- <view class="yt-list-cell b-b" @click="payType='ali'">
- <view class="cell-tit flex">
- <image class="orderIcon" src="../../static/icon/orderAli.png" mode="widthFix"></image>
- <text class="margin-l-10">支付宝</text>
- </view>
- <image class="checked" v-if="payType=='ali'" src="../../static/icon/addressIconXz.png" mode="widthFix">
- </image>
- <view v-else class="noChecked"></view>
- </view>
- <!-- #endif -->
- <view class="yt-list-cell b-b" @click="payType='yue'">
- <view class="cell-tit flex">
- <image class="orderIcon" src="../../static/icon/ye.png" mode="widthFix"></image>
- <text class="margin-l-10">余额({{now_money}})</text>
- </view>
- <image class="checked" v-if="payType=='yue'" src="../../static/icon/addressIconXz.png" mode="widthFix">
- </image>
- <view v-else class="noChecked"></view>
- </view>
- </view>
- <!-- 底部 -->
- <view class="footer">
- <view class="price-content">
- <text>实付款</text>
- <text class="price-tip">¥</text>
- <text class="price">{{ payPrice }}</text>
- </view>
- <text class="submit" :class="{submitNo:payLoding}" @click="payLoding?'':submit()">提交订单</text>
- </view>
- </view>
- </template>
- <script>
- import {
- mapState
- } from 'vuex';
- import {
- confirm,
- computedOrderkey,
- createOrderkey,
- orderPay
- } from '@/api/order.js';
- import {
- getUserInfo
- } from '@/api/user.js';
- // #ifdef H5
- import weixinObj from "@/plugin/jweixin-module/index.js";
- // #endif
- export default {
- data() {
- return {
- payType: 'ali',
- desc: '', //备注
- // 收货地址
- addressData: {},
- // 商品列表
- shopList: [],
- // 购物车id
- cartId: '',
- //购物金额详情
- moneyAll: {
- storeFreePostage: 0, //邮费优惠
- storePostage: 0, //邮费
- totalPrice: 0, //总支付金额
- vipPrice: 0 //vip优惠价
- },
- payPrice: 0, //总支付金额
- orderKey: '', //订单id
- payLoding: false, //判断是否支付中
- orderId: '', //订单id
- now_money: 0, //余额
- onShopId: -1, //默认-1为不存在商家id
- };
- },
- onLoad(option) {
- // 保存当前商品在购物车中的id
- this.cartId = option.id;
- // 判断是否要读取商家id
- if (option.shopId) {
- this.onShopId = option.shopId;
- }
- this.loadData();
- this.userinfo();
- },
- computed: {
- Postage() {
- let money = +this.moneyAll.storePostage;
- if (money == 0) {
- return '免运费';
- } else {
- return '¥' + money;
- }
- },
- payAllMoney() {
- return +this.moneyAll.totalPrice + +this.moneyAll.vipPrice;
- },
- ...mapState('shop', ['shopDetail']),
- ...mapState(['fx'])
- },
- methods: {
- // 加载用户基础信息
- userinfo() {
- getUserInfo({}).then(({
- data
- }) => {
- this.now_money = data.now_money;
- });
- },
- // 计算支付金额
- payMoneyNub() {
- computedOrderkey({
- orderkey: this.orderKey,
- useIntegral: 0, //是否积分抵扣
- addressId: this.addressData.id //地址编号
- })
- .then(({
- data
- }) => {
- this.integralShow = true;
- // 获取支付金额
- this.payPrice = +data.result.pay_price;
- this.integralMoney = data.result.deduction_price;
- })
- .catch(e => {
- console.log(e);
- this.integralShow = false;
- });
- },
- // 加载基础数据
- loadData() {
- let obj = this;
- confirm({
- cartId: obj.cartId + ''
- }).then(({
- data
- }) => {
- obj.addressData = data.addressInfo || {};
- obj.shopList = data.cartInfo; //商品列表
- obj.moneyAll = data.priceGroup; //金额数据
- obj.orderKey = data.orderKey; //订单key
- // 计算金额
- this.payMoneyNub();
- });
- },
- // 提交订单
- submit() {
- let obj = this;
- if (!this.addressData.real_name) {
- uni.showToast({
- title: '请选择收货地址',
- icon:'none'
- });
- return false;
- }
- // 判断是否余额不足
- if (obj.payType == 'yue' && +obj.now_money < obj.payPrice) {
- uni.showModal({
- title: '提示',
- content: '账户余额不足!',
- showCancel: false,
- });
- return;
- }
- uni.showLoading({
- title: '支付中',
- mask: true
- })
- // 支付中
- obj.payLoding = true;
- // 判断是否为未支付订单中跳转进入
- obj.firstCreateOrder();
- },
- // 订单金额支付
- orderMoneyPay() {
- let obj = this;
- orderPay({
- uni: obj.orderId,
- // #ifdef H5
- from: 'weixin', //来源
- // #endif
- // #ifdef MP-WEIXIN
- from: 'routine', //来源
- // #endif
- // #ifdef APP-PLUS
- from: 'app', //来源
- // #endif
- paytype: obj.payType //支付类型 weixin-微信 yue-余额
- })
- .then(e => {
- // 判断是否微信小程序支付
- if (obj.payType == 'weixin') {
- // #ifdef H5 || MP
- let da = e.data.result.jsConfig;
- let data = {
- nonceStr: da.nonceStr,
- package: da.package,
- signType: da.signType,
- paySign: da.paySign,
- success: function(res) {
- obj.paySuccessTo();
- },
- fail: () => {
- uni.navigateTo({
- url: '/pages/order/order?state=0'
- });
- }
- };
- // #endif
- // #ifdef H5
- data.timestamp = da.timestamp;
- weixinObj.chooseWXPay(data);
- // #endif
- // #ifdef MP-WEIXIN
- data.timeStamp = da.timestamp;
- wx.requestPayment(data);
- // #endif
- // #ifdef APP
- console.log( e.data.result.jsConfig,'返回数值');
- uni.requestPayment({
- provider: 'wxpay',
- orderInfo: e.data.result.jsConfig,
- success(e) {
- obj.paySuccessTo();
- },
- fail: (e) => {
- console.log(e,'支付失败');
- uni.navigateTo({
- url: '/pages/order/order?state=0'
- });
- }
- })
- // #endif
- }
- // #ifdef APP
- if(obj.payType == 'ali'){
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: e.data.result.jsConfig,
- success(e) {
- obj.paySuccessTo();
- },
- fail: (e) => {
- console.log(e,'支付失败');
- uni.navigateTo({
- url: '/pages/order/order?state=0'
- });
- }
- })
- }
- // #endif
- uni.hideLoading();
- obj.payLoding = false;
- })
- .catch(e => {
- // 支付完成
- uni.hideLoading();
- obj.payLoding = false;
- console.log(e);
- });
- },
- // 支付成功跳转
- paySuccessTo() {
- uni.hideLoading();
- uni.redirectTo({
- url: '/pages/user/money/paySuccess?orderid=' + this.orderId,
- });
- },
- // 初次订单创建
- firstCreateOrder() {
- let obj = this;
- // 获取下单页面数据
- let prepage = obj;
- let data = {
- real_name: prepage.addressData.real_name, //联系人名称
- phone: prepage.addressData.phone, //联系人号码
- addressId: prepage.addressData.id, //支付地址id
- useIntegral: 0, //是否积分抵扣1为是0为否
- payType: obj.payType, //支付类型 weixin-微信 yue-余额
- mark: prepage.desc, //备注
- // #ifdef H5
- from: 'weixin', //来源
- // #endif
- // #ifdef MP-WEIXIN
- from: 'routine', //来源
- // #endif
- // #ifdef APP-PLUS
- from: 'app', //来源
- // #endif
- shipping_type: 1, //提货方式 1 快递 2自提
- };
- // 判断是否需要读取非默认商家id
- if (obj.onShopId != -1) {
- data.store_id = obj.onShopId;
- } else {
- data.store_id = obj.shopDetail.id;
- }
- // 生成订单
- createOrderkey(data, obj.orderKey)
- .then(({
- data,
- status,
- msg
- }) => {
- // 判断是否支付失败
- if (data.status == 'ORDER_EXIST') {
- uni.showModal({
- title: '提示',
- content: msg,
- showCancel: false
- });
- uni.hideLoading();
- obj.payLoding = false;
- return;
- }
- // 保存订单号
- obj.orderId = data.result.orderId;
- // 判断是否为余额支付
- if (obj.payType == 'yue') {
- console.log('余额支付', status == 200 && data.status == 'SUCCESS');
- if (status == 200 && data.status == 'SUCCESS') {
- obj.paySuccessTo();
- } else {
- uni.showToast({
- title: msg,
- icon:'none'
- });
- }
- } else {
- // 立即支付
- obj.orderMoneyPay();
- }
- })
- .catch(e => {
- uni.hideLoading();
- obj.payLoding = false;
- console.log(e);
- });
- }
- }
- };
- </script>
- <style lang="scss">
- page {
- background: $page-color-base;
- padding-bottom: 100rpx;
- }
- .address-section {
- border-radius: 20rpx;
- padding: 30rpx;
- margin: 0 $page-row-spacing;
- background: #fff;
- position: relative;
- .order-content {
- min-height: 100rpx;
- display: flex;
- align-items: center;
- .leftIcon {
- width: 36rpx;
- margin: 0 30rpx;
- }
- .addAddress {
- text-align: center;
- width: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- .iconaddition {
- font-size: 55rpx;
- line-height: 1;
- border-radius: 100rpx;
- margin-right: 20rpx;
- }
- }
- }
- .iconlocation {
- flex-shrink: 0;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 90rpx;
- color: #888;
- font-size: 44rpx;
- }
- .cen {
- display: flex;
- flex-direction: column;
- flex: 1;
- font-size: 28rpx;
- color: $font-color-dark;
- }
- .name {
- font-size: 34rpx;
- margin-right: 24rpx;
- }
- .address {
- margin-top: 16rpx;
- margin-right: 20rpx;
- color: $font-color-light;
- }
- .icon-you {
- font-size: 32rpx;
- color: $font-color-light;
- margin-right: 30rpx;
- }
- .a-bg {
- position: absolute;
- left: 0;
- bottom: 0;
- display: block;
- width: 100%;
- height: 5rpx;
- }
- }
- .goodsList {
- margin: 0 $page-row-spacing;
- padding: 30rpx;
- background: #fff;
- border-radius: 20rpx;
- margin-top: 30rpx;
- }
- .goods-section {
- .logo {
- display: block;
- width: 50rpx;
- height: 50rpx;
- border-radius: 100px;
- }
- .name {
- font-size: 30rpx;
- color: $font-color-base;
- margin-left: 24rpx;
- }
- .g-item {
- display: flex;
- image {
- flex-shrink: 0;
- display: block;
- width: 170rpx;
- height: 170rpx;
- border-radius: 4rpx;
- }
- .right {
- flex: 1;
- padding-left: 24rpx;
- overflow: hidden;
- .serverSet {
- font-size: 22rpx;
- color: $font-color-light;
- }
- }
- .title {
- font-size: 30rpx;
- color: $font-color-dark;
- }
- .spec {
- font-size: 26rpx;
- color: $font-color-light;
- }
- .price-box {
- display: flex;
- align-items: center;
- font-size: 32rpx;
- padding-top: 10rpx;
- color: $font-color-light;
- .price {
- margin-bottom: 4rpx;
- }
- .number {
- font-size: 26rpx;
- margin-left: 20rpx;
- }
- }
- .step-box {
- position: relative;
- }
- }
- }
- .yt-list {
- background: #fff;
- margin: 0 $page-row-spacing;
- margin-top: 30rpx;
- border-radius: 20rpx;
- }
- .yt-list-cell {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 10rpx 30rpx 10rpx 40rpx;
- line-height: 70rpx;
- position: relative;
- .checked,
- .noChecked {
- width: 36rpx;
- height: 36rpx;
- }
- .noChecked {
- border: 1px solid $font-color-light;
- border-radius: 100rpx;
- }
- &.cell-hover {
- background: #fafafa;
- }
- &.b-b:after {
- left: 30rpx;
- }
- .cell-icon {
- height: 32rpx;
- width: 32rpx;
- font-size: 22rpx;
- color: #fff;
- text-align: center;
- line-height: 32rpx;
- background: #f85e52;
- border-radius: 4rpx;
- margin-right: 12rpx;
- &.hb {
- background: #ffaa0e;
- }
- &.lpk {
- background: #3ab54a;
- }
- }
- .cell-more {
- align-self: center;
- font-size: 24rpx;
- color: $font-color-light;
- margin-left: 8rpx;
- margin-right: -10rpx;
- }
- .cell-tit {
- font-size: 26rpx;
- color: $font-color-light;
- margin-right: 10rpx;
- .orderIcon {
- width: 48rpx;
- }
- }
- .cell-tip {
- font-size: 26rpx;
- color: $font-color-dark;
- &.disabled {
- color: $font-color-light;
- }
- &.active {
- color: $base-color;
- }
- &.red {
- color: $base-color;
- }
- }
- &.desc-cell {
- .cell-tit {
- max-width: 90rpx;
- }
- }
- .desc {
- text-align: right;
- font-size: $font-base;
- color: $font-color-light;
- }
- }
- /* 支付列表 */
- .pay-list {
- padding-left: 40rpx;
- margin-top: 16rpx;
- background: #fff;
- .pay-item {
- display: flex;
- align-items: center;
- padding-right: 20rpx;
- line-height: 1;
- height: 110rpx;
- position: relative;
- }
- .icon-weixinzhifu {
- width: 80rpx;
- font-size: 40rpx;
- color: #6bcc03;
- }
- .icon-alipay {
- width: 80rpx;
- font-size: 40rpx;
- color: #06b4fd;
- }
- .icon-xuanzhong2 {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 60rpx;
- height: 60rpx;
- font-size: 40rpx;
- color: $base-color;
- }
- .tit {
- font-size: 32rpx;
- color: $font-color-dark;
- flex: 1;
- }
- }
- .footer {
- position: fixed;
- left: 0;
- bottom: 0;
- z-index: 995;
- display: flex;
- align-items: center;
- width: 100%;
- height: 90rpx;
- justify-content: space-between;
- font-size: 30rpx;
- background-color: #fff;
- z-index: 998;
- color: $font-color-base;
- box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
- .price-content {
- padding-left: 30rpx;
- }
- .price-tip {
- color: $font-color-base;
- margin-left: 8rpx;
- }
- .price {
- font-size: 36rpx;
- color: $font-color-base;
- }
- .submit {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 280rpx;
- height: 100%;
- color: #fff;
- font-size: 32rpx;
- background-color: $base-color;
- &.submitNo {
- background-color: $font-color-disabled;
- }
- }
- }
- </style>
|