From b212136f20cc7f98c3616c97936978b1d1065b36 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期三, 03 四月 2024 19:32:06 +0800 Subject: [PATCH] 购买 --- packageBookService/pages/bookServices/detail/index.wxml | 7 +- packagePersonal/pages/myOrder/index.js | 15 ++++- packageBookService/pages/bookServices/detail/index.wxss | 15 ++++ packageBookService/pages/bookServices/detail/index.js | 136 +++++++++++++++++++++++---------------------- 4 files changed, 99 insertions(+), 74 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js index 96d0b81..37ed055 100644 --- a/packageBookService/pages/bookServices/detail/index.js +++ b/packageBookService/pages/bookServices/detail/index.js @@ -1,7 +1,9 @@ // pages/bookServices/detail/index.js import Toast from "tdesign-miniprogram/toast"; import tool from "../../../../assets/js/toolClass"; -import { loginInfo } from "../../../../assets/js/login"; +import { + loginInfo +} from "../../../../assets/js/login"; const app = getApp(); Page({ /** @@ -427,13 +429,14 @@ }; app.MG.store.getProductList(obj).then((res) => { if (res.datas && res.datas.length > 0) { + console.log(res.datas[0], 2) this.setData({ bookItemDetail: res.datas[0], selectedIds: res.datas[0].defaultSaleMethod.id, - bookBuy: - res.datas[0].purchasedSaleMethodIdList.indexOf( - res.datas[0].defaultSaleMethodId - ) > -1, + bookBuy: res.datas[0].purchasedSaleMethodIdList.indexOf( + res.datas[0].defaultSaleMethodId + ) > -1, + "bookDetail.price": this.numFormat(res.datas[0].price), }); let times = new Date(res.datas[0].defaultSaleMethod.endDate).getTime(); let startTime = new Date( @@ -495,10 +498,9 @@ } this.setData({ selectedIds: this.data.bookDetail.defaultSaleMethodId, - bookBuy: - this.data.bookDetail.purchasedSaleMethodIdList.indexOf( - this.data.bookDetail.defaultSaleMethodId - ) > -1, + bookBuy: this.data.bookDetail.purchasedSaleMethodIdList.indexOf( + this.data.bookDetail.defaultSaleMethodId + ) > -1, }); let times = new Date( this.data.bookDetail.defaultSaleMethod.endDate @@ -602,7 +604,9 @@ }, // 璺宠浆缃戝簵 goShop(e) { - const { link } = e.currentTarget.dataset; + const { + link + } = e.currentTarget.dataset; wx.navigateTo({ url: `/packageBookService/pages/bookServices/webpage/index?url=${link}`, }); @@ -902,13 +906,11 @@ console.log(determine); if (!determine) { let query = { - requests: [ - { - saleMethodId: this.data.selectedIds, - storeEventId: null, - agentCode: "鐢靛瓙涔�", - }, - ], + requests: [{ + saleMethodId: this.data.selectedIds, + storeEventId: null, + agentCode: "鐢靛瓙涔�", + }, ], }; const addRes = app.MG.store.addShoppingCart(query); this.showSuccessToast(); @@ -949,14 +951,12 @@ let bookOrdersId = ""; let query = { remarks: "鐢靛瓙涔�", - requests: [ - { - saleMethodId: this.data.bookItemDetail.defaultSaleMethodId - ? this.data.bookItemDetail.defaultSaleMethodId - : this.data.bookDetail.defaultSaleMethodId, - count: 1, - }, - ], + requests: [{ + saleMethodId: this.data.bookItemDetail.defaultSaleMethodId ? + this.data.bookItemDetail.defaultSaleMethodId : + this.data.bookDetail.defaultSaleMethodId, + count: 1, + }, ], }; // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉 const res = await app.MG.store.initOrder(query); @@ -965,13 +965,29 @@ console.log(bookOrdersId); // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪 if (bookOrdersId) { - const url = "/pages/cart/paymentPage/index?orderNumber=" + bookOrdersId; - wx.navigateTo({ - url, - }); + if (this.data.bookDetail.price == "0.00") { + app.MG.store.confirmOrder({ + orderNum: bookOrdersId + }).then(res => { + if (res) { + wx.showToast({ + title: "棰嗗彇鎴愬姛", + icon: "none", + duration: 1000, + }); + this.getBookInfo(this.data.bookDetail.id); + } + }) + } else { + const url = "/pages/cart/paymentPage/index?orderNumber=" + bookOrdersId; + wx.navigateTo({ + url, + }); + } } else { console.log(222); } + } else { wx.showToast({ title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", @@ -1080,14 +1096,12 @@ cmsTypeRefCode: "", newDataListRequest: [], name: this.data.bookDetail.name, // name涓虹敵璇风殑涔︽湰鍚嶇О - content: JSON.stringify([ - { - name: this.data.bookDetail.name, - id: this.data.bookDetail.id, - // defaultSaleMethodId: bookData.value.defaultSaleMethodId, - icon: this.data.bookDetail.icon, - }, - ]), + content: JSON.stringify([{ + name: this.data.bookDetail.name, + id: this.data.bookDetail.id, + // defaultSaleMethodId: bookData.value.defaultSaleMethodId, + icon: this.data.bookDetail.icon, + }, ]), }; app.MG.ugc.newTopicMessage(query).then(async (res) => { if (res) { @@ -1103,8 +1117,7 @@ title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", complete: (res) => { - if (res.cancel) { - } + if (res.cancel) {} if (res.confirm) { wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", @@ -1118,8 +1131,7 @@ title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", complete: (res) => { - if (res.cancel) { - } + if (res.cancel) {} if (res.confirm) { wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", @@ -1147,8 +1159,7 @@ title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", complete: (res) => { - if (res.cancel) { - } + if (res.cancel) {} if (res.confirm) { wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", @@ -1504,9 +1515,9 @@ if (new RegExp("(" + k + ")").test(fmt)) { fmt = fmt.replace( RegExp.$1, - RegExp.$1.length == 1 - ? o[k] - : ("00" + o[k]).substr(("" + o[k]).length) + RegExp.$1.length == 1 ? + o[k] : + ("00" + o[k]).substr(("" + o[k]).length) ); } } @@ -1560,12 +1571,10 @@ try { let query = { remarks: "缁勫嵎", - requests: [ - { - saleMethodId: this.data.mockData.id, - count: 1, - }, - ], + requests: [{ + saleMethodId: this.data.mockData.id, + count: 1, + }, ], }; if (this.data.flag) { this.setData({ @@ -1615,13 +1624,11 @@ }); // 璁板綍璐拱鏃堕棿锛屽苟璁剧姸鎬乻tate涓�1锛岃〃绀哄垰璐拱瀹屾垚缁勫嵎 app.MG.identity.setUserKey({ - setKeyRequests: [ - { - domain: "mockData", - key: this.data.bookDetail.id + "", - value: JSON.stringify(this.data.mockData.mockList), - }, - ], + setKeyRequests: [{ + domain: "mockData", + key: this.data.bookDetail.id + "", + value: JSON.stringify(this.data.mockData.mockList), + }, ], }); }, // 鑾峰彇鐩稿叧鍥句功 @@ -1705,8 +1712,7 @@ return false; } wx.navigateTo({ - url: - "/packageBookService/pages/components/webView/index?md5=" + + url: "/packageBookService/pages/components/webView/index?md5=" + this.data.fileInfo.md5 + "&fileName=" + this.data.fileInfo.bookName + @@ -1881,8 +1887,7 @@ wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", }); - } else if (res.cancel) { - } + } else if (res.cancel) {} }, }); } @@ -1951,8 +1956,7 @@ wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", }); - } else if (res.cancel) { - } + } else if (res.cancel) {} }, }); } @@ -2037,4 +2041,4 @@ teach: tree, }); }, -}); +}); \ No newline at end of file diff --git a/packageBookService/pages/bookServices/detail/index.wxml b/packageBookService/pages/bookServices/detail/index.wxml index b719eac..9555a2c 100644 --- a/packageBookService/pages/bookServices/detail/index.wxml +++ b/packageBookService/pages/bookServices/detail/index.wxml @@ -168,15 +168,16 @@ </view> <view class="btn-text">绾歌川鏍蜂功鐢宠</view> </view> - <view class="bottom-btn tryRead" bind:tap="goRead" wx:if="{{!bookBuy}}"> + <view class="{{!bookBuy && bookDetail.isSell ? 'bottom-btn tryRead' : 'bottom-btn try'}}" bind:tap="goRead" wx:if="{{!bookBuy}}"> <view> <t-image src="/static/images/bookService/detail/shidu.png"></t-image> </view> <view class="btn-text">璇曡</view> </view> - <view class="shopCar shopCarColor" bind:tap="addBookShopcCar" wx:if="{{!bookBuy}}">鍔犲叆璐墿杞�</view> - <view class="buy buyColor" bind:tap="buyBtn" wx:if="{{!bookBuy}}">绔嬪嵆璐拱</view> + <view class="shopCar shopCarColor" bind:tap="addBookShopcCar" wx:if="{{!bookBuy && bookDetail.price !== '0.00' && bookDetail.isSell}}">鍔犲叆璐墿杞�</view> + <view class="buy buyColor" bind:tap="buyBtn" wx:if="{{!bookBuy && bookDetail.price !== '0.00' && bookDetail.isSell}}">绔嬪嵆璐拱</view> + <view class="buy receiveColor" bind:tap="buyBtn" wx:if="{{!bookBuy && bookDetail.price == '0.00' && bookDetail.isSell}}">鍏嶈垂棰嗗彇</view> <view class="buy read" bind:tap="goRead" wx:if="{{bookBuy}}">绔嬪嵆鏌ョ湅</view> </view> </view> diff --git a/packageBookService/pages/bookServices/detail/index.wxss b/packageBookService/pages/bookServices/detail/index.wxss index 6242e6f..5a305ee 100644 --- a/packageBookService/pages/bookServices/detail/index.wxss +++ b/packageBookService/pages/bookServices/detail/index.wxss @@ -242,8 +242,9 @@ .bottom-btn { background-color: #fff; - width: 25%; + /* width: 25%; */ display: flex; + flex: 2; align-items: center; justify-content: center; flex-direction: column; @@ -251,7 +252,11 @@ } .tryRead { - width: 120rpx; + flex: 1 !important; +} + +.try { + flex: 2 !important; } .btn-text { @@ -276,6 +281,7 @@ align-items: center; justify-content: center; color: #fff; + flex: 2; } .read { @@ -295,6 +301,11 @@ background-color: #F14B3B; } +.receiveColor { + background-color: #F14B3B; + width: 50% !important; +} + .disabledColor { background-color: #d9d9d9; } diff --git a/packagePersonal/pages/myOrder/index.js b/packagePersonal/pages/myOrder/index.js index 9798e7f..a0dd2bd 100644 --- a/packagePersonal/pages/myOrder/index.js +++ b/packagePersonal/pages/myOrder/index.js @@ -173,14 +173,23 @@ }) this.getDataList(false); }, - goBookDetails(e) { + async goBookDetails(e) { const { book, remarks } = e.currentTarget.dataset; - let id = remarks != null && JSON.stringify(remarks).slice(1, -1) == 'object' && JSON.parse(remarks).pId ? JSON.parse(remarks).pId : book.orderSaleMethod.product.id; + let parentData = null; + let bookId = book.orderSaleMethod.product.id; + if (remarks == null) { + parentData = await app.MG.store.getProductBySaleMethod({ + 'saleMethodId': book.orderSaleMethod.id + }) + bookId = parentData.parentProduct[parentData.parentProduct.length - 1].id; + } else if (remarks != null && JSON.stringify(remarks).slice(1, -1) == 'object' && JSON.parse(remarks).pId) { + bookId = JSON.parse(remarks).pId + } wx.navigateTo({ - url: `/packageBookService/pages/bookServices/detail/index?id=${id}&name=${book.name}`, + url: `/packageBookService/pages/bookServices/detail/index?id=${bookId}&name=${book.name}`, }); }, -- Gitblit v1.9.1