123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <template>
- <view class="w-full">
- <send-type @sendTypeChange="sendTypeChange" />
- <view class="gap"></view>
- <!-- <view class="address">
- <u-cell-group>
- <u-cell title="添加收货地址" :border="false" url='' isLink>
- <u-icon slot="icon" size="24" name="plus"></u-icon>
- </u-cell>
- </u-cell-group>
- </view> -->
- <view class="padding-sm dflex-b bg-main" @click="show = true">
- <view class="dflex">
- <!-- <view class="addr-label">配送至</view> -->
- <view class="w-full dflex-wrap-w send-label">
- 取餐时间
- </view>
- </view>
- <u-icon slot="icon" size="20" name="arrow-right" :label="value" labelPos="left"></u-icon>
- <!-- <view class="iconfont iconjiantou-01 fs-sm"></view> -->
- </view>
- <u-datetime-picker :show="show" v-model="value" mode="time" @confirm="onConfirm"
- @cancel="onCancel"></u-datetime-picker>
- <view class="gap"></view>
- <view class="padding-sm dflex-b bg-main">
- <view class="dflex">
- <!-- <view class="addr-label">配送至</view> -->
- <view class="w-full dflex-wrap-w send-label">
- 取餐方式
- </view>
- </view>
- <view>
- <uni-data-checkbox v-model="val" :localdata="list" @change="radioChange"
- selectedColor="#F54319"></uni-data-checkbox>
- <!-- <radio style="margin: 0 10px; transform: scale(0.85)" value="r1" :checked="typePicking" color="#ff0000" class="radio">店内用餐
- </radio >
- <radio style="transform: scale(0.85)" value="r1" :checked="typePickings" color="#ff0000" class="radio">打包带走
- </radio> -->
- </view>
- <!-- <view class="iconfont iconjiantou-01 fs-sm"></view> -->
- </view>
- <view class="gap"></view>
- <view class="goods-order-list w-full padding-lr-sm">
- <view class="shop dflex-b ">
- <view class="shop-check">
- <text class="shop-name">{{cList.name}}</text>
- </view>
- </view>
- <view class="goods-cart w-full">
- <view class="goods-cont padding-tb" v-for="(item, index) in cartData" :key="index">
- <my-goods :item="item">
- <view class="good-num">×{{item.quantity}}</view>
- </my-goods>
- </view>
- </view>
- </view>
- <!-- 金额明细 -->
- <view class="gap"></view>
- <view class="bg-main">
- <view class="dflex-b padding-lr padding-tb-sm">
- <view class="flex1">总金额</view>
- <view class="price">{{total}}</view>
- </view>
- <!-- <view class="dflex-b padding-lr padding-tb-sm">
- <view class="flex1">运费 (总重:4.960 kg )</view>
- <view class="ft-base">¥10.00</view>
- </view>
-
- <view class="dflex-b padding-lr padding-tb-sm">
- <view class="margin-right-xl">备注</view>
- <input class="flex1 padding-sm" type="text" v-model="order_desc" placeholder="请填写买家备注"
- placeholder-class="placeholder" />
- </view> -->
- </view>
- <view class="gap"></view>
- <!-- <my-gap :height="130" /> -->
- <view class="submit-bar padding-sm dflex-b">
- <view class="submit-btn dflex-c background-gradient" @click="toBuy">立即下单</view>
- </view>
- </view>
- </template>
- <script>
- import {
- multiply
- } from '@/utils/accuracy.js'
- export default {
- data() {
- return {
- cartData:[],
- total: 0,
- data: [],
- show: false,
- value: '',
- bussinessInfo:{},
- cList: {},
- val: null,
- vals: null,
- tenantId:'',
- list: [{
- text: "店内用餐",
- value: 0
- },
- {
- text: "打包带走",
- value: 1
- }
- ]
- }
- },
- onLoad(option) {
- const e = uni.getStorageSync('carl')
- this.cList = e
- // console.log('233333333333333', e)
- // // 解码 URL 编码的字符串
- // var dataString = decodeURIComponent(option.data);
- // // 尝试将字符串转换为 JSON 对象
- // var data = JSON.parse(dataString);
- // if(data.carlist[0].imgUrl.url) {
- // data.carlist[0].imgUrl = data.carlist[0].imgUrl.url;
- // }
-
- // this.data = data
- // // 打印解码后的数据
- // console.log('eeeeeeeeeeeee============data', data);
-
- const config = process.env.ENV_PATH ? require('../../../' + process.env.ENV_PATH) : require(
- '../../../env/dev.js');
- this.tenantId = config.tenantId;
- this.initCart()
- // this.loadBussinessInfo()
- },
- methods: {
- initCart() {
- let cartInfo = uni.getStorageSync('cartInfo');
- if(cartInfo){
- try{
- this.cartData = JSON.parse(cartInfo)
- this.totalPrice()
- }catch(e){}
- }
- },
- totalPrice() {
- let total = 0;
- for (let i = 0; i < this.cartData.length; i++) {
- let priceInCents = Math.round(this.carList[i].price * 100);
- let quant = this.carList[i].quantity;
- total += priceInCents * quant;
- }
- this.total = (total / 100).toFixed(2);
- },
- sendTypeChange(v) {},
- radioChange(v) {
- console.log('2=================', v)
- console.log('2=================22222', this.val)
- },
- onConfirm(v) {
- console.log('vvvvvvvvvvvvvvv', v)
- this.value = v.value
- this.show = false
- },
- onCancel() {
- this.show = false
- },
- toBuy() {
- console.log('this.val', this.val)
- if (this.value == '') {
- uni.showToast({
- title: '请选择取餐时间',
- icon: 'error',
- duration: 1000
- })
- return
- }
- if (this.val == null && this.val == undefined && this.val == '') {
- uni.showToast({
- title: '请选择取餐方式',
- icon: 'error',
- duration: 1000
- })
- return
- }
- const userId = uni.getStorageSync('appUserId');
- const userName = uni.getStorageSync('userName');
- const itemListArray = this.cartData.map(item => ({
- skuId: item.skuId,
- gift: 1, // 假设所有商品都不是礼物
- basePrice: Number(item.basePrice),
- price: Number(item.price),
- quantity: item.quantity,
- sellerType: 'C', // 假设所有商品卖家类型都是 'C'
- spuId: item.spuId,
- skuName: item.skuName,
- title: item.skuTitle,
- picUrl: item.imgUrl,
- skuProperties: item.skuProperties,
- totalFee: multiply(Number(item.price), item.quantity),
- adjustFee: 0,
- skuCode: item.skuCode,
- splitMergeId: item.splitMergeId,
- productWeight: item.productWeight,
- freightTemplateId: item.freightTemplateId
- }))
- const params = {
- buyerRate:'1',
- distributionOrder:'1',
- orderState: 'WaitPay',
- partConsign:'1',
- orderType: 1,
- serviceType: '1',
- payAmount: Number(this.total),
- totalAmount: Number(this.total),
- discountAmount: 0,
- adjustAmount: 0,
- postAmount: 0,
- receivedAmount: Number(this.total),
- commissionAmount: 0,
- payOnDeliveryAmount: 0,
- payOnDelivery: '1',
- payType: '1',
- payChannel: '1',
- invoice: '1',
- orderSource:'2',
- storeId: this.cList.id,
- storeName: this.cList.name,
- sellerNick: this.cList.name,
- sellerId: this.bussinessInfo.id,
- buyerNick: userName,
- customerId: userId,
- sellerRate:'1',
- orderItemList: itemListArray,
- shippingType: '4',
- orderPickup: {
- pickupType: this.val,
- verify: 2,
- // writeOffTime: this.value
- }
- }
- console.log('params', params);
- // uni.navigateTo({
- // url: `/pages/order/orderPaid/orderPaid`
- // })
- return
- const that = this;
- this.$request('post', `/order/tradeOrder/addTradeOrder`, params, true).then(response => {
- // 请求成功
- console.log('response', response)
- if (response.code == 200) {
- // const ids = this.data.carlist.map(car => car.id);
- // this.$request('delete', `/front/shoppingCart/${ids}`)
- // console.log('response.data', response.data)
- // uni.$emit('register_refresh');
- // uni.showToast({
- // title: '已下单,因目前是演示阶段,暂时不能付款',
- // icon: 'success',
- // duration: 2000,
- // complete: () => {
- // // 页面跳转放在complete回调中
- // uni.navigateTo({
- // url: `/pages/order/myOrder/myOrder?type=0`
- // })
- // }
- // })
- // // uni.navigateTo({
- // // url: `/pages/order/orderPaid/orderPaid?id=${response.data}`
- // // })
- uni.removeStorageSync('cartInfo');
- that.pay(response.msg)
- } else if (response.code == 500) {
- uni.showToast({
- title: response.msg,
- icon: 'error',
- duration: 2000
- });
- }
- }).catch(error => {
- // 请求失败
- console.error('请求失败:', error);
- })
- },
- //获取商家信息
- loadBussinessInfo() {
- const that = this;
- this.$req({
- url: '/sale/business/queryBusiness',
- method: 'GET',
- data: {
- pageNum: 1, //当前页
- pageSize: 20 //每页条数
- },
- success: res => {
- that.bussinessInfo = res.rows[0]
- },
- fail: err => {
- let msg = ''
- if (err && err.msg && err.msg.length < 15) {
- msg = err.msg
- } else {
- msg = '系统繁忙'
- }
- that.$refs.uToast.show({
- message: msg
- })
- },
- complete: () => {
-
- }
- })
- },
- //支付
- pay(id) {
- let that = this;
- const openId = uni.getStorageSync("openId");
- // let outTradeNo = this.uuid()
- this.$req({
- url: '/weChatPay/payment/miniPay',
- method: 'POST',
- data: {
- tenantId: this.tenantId,
- outTradeNo: id,
- openId: openId,
- total: this.totalPrice * 100,
- },
- other: res => {
- wx.requestPayment({
- "timeStamp": res.timeStamp,
- "nonceStr": res.nonceStr,
- "package": res.packageValue,
- "signType": "RSA",
- "paySign": res.paySign,
- "success": function(res) {
- // console.log('调用支付接口成功', res)
- // that.$refs.uToast.show({
- // type:'success',
- // message: '操作成功!'
- // })
- uni.redirectTo({
- url: '/pages/order/paySuccess/paySuccess?price=' + that
- .totalPrice
- });
-
- },
- "fail": function(res) {
- that.$refs.uToast.show({
- type: 'error',
- message: '支付失败!'
- })
- setTimeout(() => {
- uni.redirectTo({
- url: '/pages/order/myOrder/myOrder?type=1'
- });
- }, 1000)
- console.log('调用支付接口fail', res)
- },
- "complete": function(res) {
- console.log('调用支付接口完成', res)
- }
- })
- },
- complete: () => {
- this.load = false
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .addr-label {
- padding: 6upx 0;
- border-radius: 3px;
- background-color: #F6390D;
- color: #fff;
- width: 120upx;
- text-align: center;
- flex-shrink: 0;
- margin-right: 14upx;
- }
- .order-spec {
- padding-bottom: 10upx;
- }
- .shop {
- padding-top: 20upx;
- }
- .goods-num {
- font-size: 16px;
- padding-left: 20upx;
- }
- .goods-cont {
- width: 100%;
- box-sizing: border-box;
- }
- .total-goods {
- font-size: 12px;
- color: #999;
- }
- .submit-bar {
- height: 130rpx;
- width: 100%;
- background-color: #FFF;
- position: fixed;
- left: 0;
- bottom: 0;
- box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
- z-index: 10;
- .submit-btn {
- background-color: #0581FE;
- height: 100%;
- width: 100%;
- color: #FFF;
- font-size: 14px;
- // font-weight: 700;
- border-radius: 35upx;
- }
- }
- .good-num {
- font-size: 12px;
- padding-top: 65rpx;
- }
- .send-label {
- font-size: 14px;
- font-weight: 700;
- }
- </style>
|