| | |
| | | // packageBookService/pages/bookServices/detail/buyResource/index.js |
| | | const app = getApp() |
| | | const app = getApp(); |
| | | Page({ |
| | | |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | barHeight: '', |
| | | navBarHeight: '', |
| | | barHeight: "", |
| | | navBarHeight: "", |
| | | learn: [], |
| | | openLearnids: [], |
| | | bookId: '', |
| | | bookId: "", |
| | | loading: false, |
| | | shoppingList: [], |
| | | shoppingCartGetId: [], |
| | | methodId: [], |
| | | paymentPage: false, |
| | | superior: false |
| | | superior: false, |
| | | checkAllState: false, |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad(options) { |
| | | |
| | | const systInfo = wx.getSystemInfoSync(); |
| | | const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息 |
| | | const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | | const navBarHeight = |
| | | (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度 |
| | | this.setData({ |
| | | barHeight: systInfo.statusBarHeight, |
| | | navBarHeight: navBarHeight, |
| | | bookId: options.bookId |
| | | bookId: options.bookId, |
| | | }); |
| | | this.getResourceClass() |
| | | this.getResourceClass(); |
| | | console.log(options); |
| | | this.getResourceData({ |
| | | productLinkPath: options.productLinkPath, |
| | | refCode: options.refCode |
| | | }) |
| | | this.getShoppingCartProductGet() |
| | | this.getBookInfo(options.bookId) |
| | | refCode: options.refCode, |
| | | }); |
| | | this.getShoppingCartProductGet(); |
| | | this.getBookInfo(options.bookId); |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面初次渲染完成 |
| | | */ |
| | | onReady() { |
| | | |
| | | }, |
| | | onReady() {}, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | onShow() { |
| | | |
| | | }, |
| | | onShow() {}, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面隐藏 |
| | | */ |
| | | onHide() { |
| | | |
| | | }, |
| | | onHide() {}, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | | */ |
| | | onUnload() { |
| | | |
| | | }, |
| | | onUnload() {}, |
| | | |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |
| | | onPullDownRefresh() { |
| | | |
| | | }, |
| | | onPullDownRefresh() {}, |
| | | |
| | | /** |
| | | * 页面上拉触底事件的处理函数 |
| | | */ |
| | | onReachBottom() { |
| | | |
| | | }, |
| | | onReachBottom() {}, |
| | | |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |
| | | onShareAppMessage() { |
| | | |
| | | onShareAppMessage() {}, |
| | | changeCheckAll(e) { |
| | | this.setData({ |
| | | checkAllState: e.detail.value, |
| | | }); |
| | | }, |
| | | goBack() { |
| | | wx.navigateBack() |
| | | wx.navigateBack(); |
| | | }, |
| | | // 获取教学资源 云学习 云测试 |
| | | getResourceData(type) { |
| | | this.setData({ |
| | | loading: true, |
| | | noResources: false |
| | | }) |
| | | noResources: false, |
| | | }); |
| | | let query = { |
| | | path: '*', |
| | | queryType: '*', |
| | | path: "*", |
| | | queryType: "*", |
| | | productId: this.data.bookId, |
| | | cmsPath: type.productLinkPath, |
| | | itemFields: { |
| | | SysType: 'CmsFolder', |
| | | SysType: "CmsFolder", |
| | | // 资源类型,试读文件,是否允许下载等参数 |
| | | selectType: [], |
| | | freeFile: [], |
| | |
| | | isDownload: [], |
| | | jsek_resourceBrief: [], |
| | | jsek_link: [], |
| | | jsek_questionBank: [] |
| | | jsek_questionBank: [], |
| | | }, |
| | | pading: { |
| | | start: 0, |
| | | size: 999 |
| | | size: 999, |
| | | }, |
| | | } |
| | | }; |
| | | app.MG.store |
| | | .getProductDetail(query) |
| | | .then(async (res) => { |
| | | if (!res.datas.cmsDatas[0].datas.length) { |
| | | return this.setData({ |
| | | noResources: true, |
| | | loading: false |
| | | }) |
| | | loading: false, |
| | | }); |
| | | } |
| | | //教学资源 云学习 |
| | | if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') { |
| | | if ( |
| | | type.refCode == "jsek_teachingResources" || |
| | | type.refCode == "jsek_cloudLearning" |
| | | ) { |
| | | if (res.datas.cmsDatas[0].datas.length > 0) { |
| | | res.datas.cmsDatas[0].datas.forEach(item => { |
| | | item.checked = false, |
| | | item.checkAll = true |
| | | }) |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | if (type.refCode == 'jsek_teachingResources') { |
| | | res.datas.cmsDatas[0].datas.forEach((item) => { |
| | | (item.checked = false), (item.checkAll = true); |
| | | }); |
| | | const list = await this.getAllResource(res.datas.cmsDatas[0].datas); |
| | | if (type.refCode == "jsek_teachingResources") { |
| | | this.setData({ |
| | | teach: list, |
| | | loading: false |
| | | }) |
| | | this.findChildIds(this.data.teach, this.data.openTeachids = []) |
| | | } else if (type.refCode == 'jsek_cloudLearning') { |
| | | const result = [] |
| | | res.datas.cmsDatas[0].datas.forEach(item => { |
| | | item.checked = false |
| | | }) |
| | | this.findChildIds(list, result) |
| | | loading: false, |
| | | }); |
| | | this.findChildIds(this.data.teach, (this.data.openTeachids = [])); |
| | | } else if (type.refCode == "jsek_cloudLearning") { |
| | | const result = []; |
| | | res.datas.cmsDatas[0].datas.forEach((item) => { |
| | | item.checked = false; |
| | | }); |
| | | this.findChildIds(list, result); |
| | | this.setData({ |
| | | learn: list, |
| | | loading: false, |
| | | openLearnids: result |
| | | }) |
| | | console.log('教学资源', list); |
| | | openLearnids: result, |
| | | }); |
| | | console.log("教学资源", list); |
| | | } |
| | | } else { |
| | | // 无数据 |
| | | } |
| | | } else if (type.refCode == 'jsek_questionBank') { |
| | | } else if (type.refCode == "jsek_questionBank") { |
| | | // const list = await this.getAllResource(res.datas.cmsDatas[0].datas) |
| | | this.setData({ |
| | | test: res.datas.cmsDatas[0].datas, |
| | | loading: false |
| | | }) |
| | | loading: false, |
| | | }); |
| | | } else { |
| | | console.log('其他'); |
| | | console.log("其他"); |
| | | } |
| | | }) |
| | | .catch((e) => { |
| | | console.log(e) |
| | | }) |
| | | console.log(e); |
| | | }); |
| | | }, |
| | | // 获取tag下所有资源 |
| | | async getAllResource(data) { |
| | | if (!data.length) return false |
| | | if (!data.length) return false; |
| | | for (let i = 0; i < data.length; i++) { |
| | | let item = data[i] |
| | | if (item.sysType == 'CmsFolder' && item.childrenCount > 0) { |
| | | item.children = [] |
| | | item.children = await this.getFolderItem(item.productLinkPath) |
| | | await this.getAllResource(item.children) |
| | | let item = data[i]; |
| | | if (item.sysType == "CmsFolder" && item.childrenCount > 0) { |
| | | item.children = []; |
| | | item.children = await this.getFolderItem(item.productLinkPath); |
| | | await this.getAllResource(item.children); |
| | | } |
| | | } |
| | | return data |
| | | return data; |
| | | }, |
| | | // 获取资源接口 |
| | | async getFolderItem(path) { |
| | | let query = { |
| | | path: '*', |
| | | queryType: '*', |
| | | path: "*", |
| | | queryType: "*", |
| | | productId: this.data.bookId, |
| | | cmsPath: path, |
| | | itemFields: { |
| | | SysType: 'CmsFolder', |
| | | SysType: "CmsFolder", |
| | | // 资源类型,试读文件,是否允许下载等参数 |
| | | selectType: [], |
| | | freeFile: [], |
| | |
| | | isDownload: [], |
| | | jsek_resourceBrief: [], |
| | | jsek_link: [], |
| | | accessType: [] |
| | | accessType: [], |
| | | }, |
| | | pading: { |
| | | start: 0, |
| | | size: 999 |
| | | size: 999, |
| | | }, |
| | | } |
| | | const data = await app.MG.store.getProductDetail(query) |
| | | }; |
| | | const data = await app.MG.store.getProductDetail(query); |
| | | data.datas.cmsDatas[0].datas.forEach((item) => { |
| | | this.data.resourceClassList.forEach((type) => { |
| | | if (type.value == item.resourcesClassification) item.resourceClass = type.name |
| | | }) |
| | | if (type.value == item.resourcesClassification) |
| | | item.resourceClass = type.name; |
| | | }); |
| | | // 网页 不能下载 私有文件 |
| | | if (item.sysType == 'CmsItem') { |
| | | if (item.selectType == 'webpage') { |
| | | item.disabled = true |
| | | if (item.sysType == "CmsItem") { |
| | | if (item.selectType == "webpage") { |
| | | item.disabled = true; |
| | | } else { |
| | | if (item.isDownload != 1) { |
| | | item.disabled = true |
| | | item.disabled = true; |
| | | } |
| | | } |
| | | if (item.file) { |
| | | if (item.fileMap[item.file].protectType == 'Private') item.disabled = true |
| | | if (item.fileMap[item.file].protectType == "Private") |
| | | item.disabled = true; |
| | | } |
| | | } |
| | | }) |
| | | data.datas.cmsDatas[0].datas.forEach(item => { |
| | | item.checked = false |
| | | item.isbuy = this.resourceIsBuy(item) |
| | | item.isShopCar = this.isShoppingCart(item) |
| | | }) |
| | | return data.datas.cmsDatas[0].datas |
| | | }); |
| | | data.datas.cmsDatas[0].datas.forEach((item) => { |
| | | item.checked = false; |
| | | item.isbuy = this.resourceIsBuy(item); |
| | | item.isShopCar = this.isShoppingCart(item); |
| | | }); |
| | | return data.datas.cmsDatas[0].datas; |
| | | }, |
| | | getBookInfo(id) { |
| | | this.setData({ |
| | | "mockData'.id": 0, |
| | | "mockData.price": 0, |
| | | "mockData.count": 0 |
| | | }) |
| | | "mockData.count": 0, |
| | | }); |
| | | const query = { |
| | | path: '*', |
| | | queryType: '*', |
| | | path: "*", |
| | | queryType: "*", |
| | | productId: id, |
| | | favoriteTypes: 'FavoriteBookCity', |
| | | favoriteTypes: "FavoriteBookCity", |
| | | itemFields: { |
| | | 'SysType=': 'CmsFolder', |
| | | "SysType=": "CmsFolder", |
| | | }, |
| | | coverSize: { |
| | | height: 300, |
| | |
| | | app.MG.store.getProductDetail(query).then(async (res) => { |
| | | this.setData({ |
| | | bookDetail: res.datas, |
| | | buyIdList: res.datas.purchasedSaleMethodIdList |
| | | buyIdList: res.datas.purchasedSaleMethodIdList, |
| | | }); |
| | | }); |
| | | |
| | | }, |
| | | // 获取已购买商品 |
| | | getShoppingCartProductGet() { |
| | |
| | | start: 0, |
| | | size: 999, |
| | | filterList: [], |
| | | searchList: [] |
| | | } |
| | | searchList: [], |
| | | }; |
| | | app.MG.store.getShoppingCartProductList(query).then((res) => { |
| | | const list = [] |
| | | const list = []; |
| | | res.datas.forEach((item) => { |
| | | list.push(item.saleMethod.id) |
| | | }) |
| | | list.push(item.saleMethod.id); |
| | | }); |
| | | this.setData({ |
| | | shoppingList: res.datas, |
| | | shoppingCartGetId: list |
| | | }) |
| | | }) |
| | | shoppingCartGetId: list, |
| | | }); |
| | | }); |
| | | }, |
| | | // 判断资源是否购买 |
| | | resourceIsBuy(data) { |
| | | if (data.saleMethod && data.saleMethod.length) { |
| | | const isSHow = this.data.buyIdList.some((item) => item == data.saleMethod[0].Id) |
| | | return !isSHow |
| | | const isSHow = this.data.buyIdList.some( |
| | | (item) => item == data.saleMethod[0].Id |
| | | ); |
| | | return !isSHow; |
| | | } else { |
| | | return false |
| | | return false; |
| | | } |
| | | }, |
| | | // 判断资源加入购物车按钮是否显示 |
| | | isShoppingCart(data) { |
| | | if (data.saleMethod && data.saleMethod.length) { |
| | | if (data.saleMethod[0].Price <= 0) return false |
| | | if (data.saleMethod[0].Price <= 0) return false; |
| | | // 再判断是否购买 |
| | | const isBuy = this.data.buyIdList.some((item) => item == data.saleMethod[0].Id) |
| | | const isBuy = this.data.buyIdList.some( |
| | | (item) => item == data.saleMethod[0].Id |
| | | ); |
| | | if (isBuy) { |
| | | // 购买了 |
| | | return false |
| | | return false; |
| | | } else { |
| | | // 判断是否加入购物车 |
| | | const isSHow = this.data.shoppingCartGetId.some((item) => item == data.saleMethod[0].Id) |
| | | return !isSHow |
| | | const isSHow = this.data.shoppingCartGetId.some( |
| | | (item) => item == data.saleMethod[0].Id |
| | | ); |
| | | return !isSHow; |
| | | } |
| | | } else { |
| | | return false |
| | | return false; |
| | | } |
| | | }, |
| | | // 获取展开项 |
| | | findChildIds(data, result) { |
| | | let index = 0 |
| | | let index = 0; |
| | | for (let i = 0; i < data.length; i++) { |
| | | if (index < 3) { |
| | | const item = data[i] |
| | | const item = data[i]; |
| | | if (item.children && item.children.length > 0) { |
| | | result.push(item.id) |
| | | result.push(item.id); |
| | | for (let j = 0; j < item.children.length; j++) { |
| | | if (index < 3) { |
| | | const childrenItme = item.children[j] |
| | | const childrenItme = item.children[j]; |
| | | if (item.children && item.children.length > 0) { |
| | | result.push(childrenItme.id) |
| | | index += 1 |
| | | result.push(childrenItme.id); |
| | | index += 1; |
| | | } |
| | | } else { |
| | | break |
| | | break; |
| | | } |
| | | } |
| | | } else if (item.children && item.children.length > 0) { |
| | | result.push(item.id) |
| | | index += 1 |
| | | result.push(item.id); |
| | | index += 1; |
| | | } |
| | | } else { |
| | | break |
| | | break; |
| | | } |
| | | } |
| | | }, |
| | | // 获取资源所属分类 |
| | | getResourceClass() { |
| | | let query = { |
| | | refCodes: ['resourcesClassification'] |
| | | } |
| | | refCodes: ["resourcesClassification"], |
| | | }; |
| | | app.MG.store.getProductTypeField(query).then((res) => { |
| | | this.setData({ |
| | | resourceClassList: JSON.parse(res[0].config).option |
| | | }) |
| | | }) |
| | | resourceClassList: JSON.parse(res[0].config).option, |
| | | }); |
| | | }); |
| | | }, |
| | | checkAll() { |
| | | const child = this.selectComponent('#tree') |
| | | child.checkAll() |
| | | |
| | | const child = this.selectComponent("#tree"); |
| | | child.checkAll(); |
| | | }, |
| | | //购买按钮 |
| | | batchPurchase() { |
| | | let saleMethodIds = []; |
| | | let requests = []; |
| | | let item = []; |
| | | let selectAllId = []; |
| | | const child = this.selectComponent("#tree"); |
| | | |
| | | |
| | | |
| | | let saleMethodIds = [] |
| | | let requests = [] |
| | | let item = [] |
| | | let selectAllId = [] |
| | | const child = this.selectComponent('#tree') |
| | | |
| | | console.log(child.data.superiorPurchaseSaleMethodId, 'superiorPurchaseSaleMethodId'); |
| | | console.log(child.data.sonPurchaseSaleMethodId, 'child.data'); |
| | | console.log( |
| | | child.data.superiorPurchaseSaleMethodId, |
| | | "superiorPurchaseSaleMethodId" |
| | | ); |
| | | console.log(child.data.sonPurchaseSaleMethodId, "child.data"); |
| | | // console.log(child.data.selectAll, 'selectAll'); |
| | | item = child.data.superiorPurchaseSaleMethodId |
| | | const sonItem = child.data.sonPurchaseSaleMethodId |
| | | let selectAll = child.data.selectAll |
| | | item = child.data.superiorPurchaseSaleMethodId; |
| | | const sonItem = child.data.sonPurchaseSaleMethodId; |
| | | let selectAll = child.data.selectAll; |
| | | if (selectAll) { |
| | | // console.log(selectAll); |
| | | selectAll.forEach(item => { |
| | | selectAll.forEach((item) => { |
| | | if (item.saleMethod != 0) { |
| | | // console.log(item, 'item'); |
| | | selectAllId.push(item.saleMethod[0].Id) |
| | | selectAllId.push(item.saleMethod[0].Id); |
| | | } |
| | | }) |
| | | }); |
| | | console.log(selectAllId); |
| | | app.MG.store.initOrder({ |
| | | requests: selectAllId.map(id => ({ |
| | | saleMethodId: id, |
| | | count: 1, |
| | | })), |
| | | }).then(res => { |
| | | if (res) { |
| | | wx.navigateTo({ |
| | | url: '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber, |
| | | }) |
| | | selectAllId = [] |
| | | child.setData({ |
| | | selectAll: [] |
| | | }) |
| | | |
| | | } |
| | | }) |
| | | app.MG.store |
| | | .initOrder({ |
| | | requests: selectAllId.map((id) => ({ |
| | | saleMethodId: id, |
| | | count: 1, |
| | | })), |
| | | }) |
| | | .then((res) => { |
| | | if (res) { |
| | | wx.navigateTo({ |
| | | url: |
| | | "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber, |
| | | }); |
| | | selectAllId = []; |
| | | child.setData({ |
| | | selectAll: [], |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | if (item) { |
| | | console.log(item, 'sadsdasd'); |
| | | console.log(item, "sadsdasd"); |
| | | // 拿到id |
| | | item.forEach(items => { |
| | | item.forEach((items) => { |
| | | if (items.saleMethod != 0) { |
| | | saleMethodIds.push(items.saleMethod[0].Id) |
| | | saleMethodIds.push(items.saleMethod[0].Id); |
| | | } |
| | | }) |
| | | console.log(saleMethodIds, 'saleMethodIds'); |
| | | }); |
| | | console.log(saleMethodIds, "saleMethodIds"); |
| | | |
| | | app.MG.store.initOrder({ |
| | | requests: saleMethodIds.map(id => ({ |
| | | saleMethodId: id, |
| | | count: 1, |
| | | })), |
| | | }).then(res => { |
| | | if (res) { |
| | | wx.navigateTo({ |
| | | url: '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber, |
| | | }) |
| | | app.MG.store |
| | | .initOrder({ |
| | | requests: saleMethodIds.map((id) => ({ |
| | | saleMethodId: id, |
| | | count: 1, |
| | | })), |
| | | }) |
| | | .then((res) => { |
| | | if (res) { |
| | | wx.navigateTo({ |
| | | url: |
| | | "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber, |
| | | }); |
| | | |
| | | child.setData({ |
| | | superiorPurchaseSaleMethodId: [] // 使用setData方法清空sonPurchaseSaleMethodId数据 |
| | | }) |
| | | } |
| | | }) |
| | | child.setData({ |
| | | superiorPurchaseSaleMethodId: [], // 使用setData方法清空sonPurchaseSaleMethodId数据 |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | if (item.length == 0 && sonItem) { |
| | | app.MG.store.initOrder({ |
| | | requests: sonItem.map(id => ({ |
| | | saleMethodId: id, |
| | | count: 1, |
| | | })), |
| | | }).then(res => { |
| | | if (res) { |
| | | wx.navigateTo({ |
| | | url: '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber, |
| | | }) |
| | | this.setData({ |
| | | paymentPage: true |
| | | }) |
| | | child.setData({ |
| | | sonPurchaseSaleMethodId: [] // 使用setData方法清空sonPurchaseSaleMethodId数据 |
| | | }) |
| | | } |
| | | }) |
| | | app.MG.store |
| | | .initOrder({ |
| | | requests: sonItem.map((id) => ({ |
| | | saleMethodId: id, |
| | | count: 1, |
| | | })), |
| | | }) |
| | | .then((res) => { |
| | | if (res) { |
| | | wx.navigateTo({ |
| | | url: |
| | | "/pages/cart/paymentPage/index?orderNumber=" + res.orderNumber, |
| | | }); |
| | | this.setData({ |
| | | paymentPage: true, |
| | | }); |
| | | child.setData({ |
| | | sonPurchaseSaleMethodId: [], // 使用setData方法清空sonPurchaseSaleMethodId数据 |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | }) |
| | | }); |