123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- import {
- get,
- post
- } from '../../utils/http'
- import {
- PROJECT_TYPE
- } from '../../utils/global'
- var WxParse = require('../../components/local/wxParse/wxParse.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- tempTime: null,
- visible2: false,
- deviceList: [],
- projectData: null,
- currentDevice: 0,
- currentChangeDevice: null,
- currentChangeTime: null,
- source: 'project',
- sourceType: 1,
- sourceId: 0,
- storeId: 0,
- topBannerCurrentSwiper: 0,
- navBarTitles: {
- project: '项目详情',
- product: '套餐详情',
- goods: '产品详情',
- cardgoods: '产品详情',
- secondaryCard: '次卡详情'
- },
- // 下面是选择项目的操作
- showProducePup: false,
- selectProductData: {},
- selectProductIndex: '',
- selectProductCar: [],
- onCloseCar: false,
- showMoney: 0.0,
- toSelectProduct: {}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options, 'options')
- let source = options.source || 'project'
- let sourceId = options.project_id || options.id
- let sourceType = PROJECT_TYPE[source] || 1
- wx.setNavigationBarTitle({
- title: this.data.navBarTitles[source]
- })
- let storeId =
- options.store_id ||
- getApp().globalData.storeData.id ||
- wx.getStorageSync('store_id')
- this.setData({
- source,
- sourceId,
- sourceType,
- storeId
- }, () => {
-
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if(wx.getStorageSync('store_id')){
- this.getProjectInfo(this.data.sourceId, wx.getStorageSync('store_id'))
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- console.log(this.data.sourceId, 'this.data.sourceId')
- return {
- path: `pages/projectDetail/projectDetail?project_id=${this.data.sourceId}&source=${this.data.source}&store_id=${wx.getStorageSync('store_id')}`, // 他人通过卡片进入小程序的路径,可以在后面拼接URL的形式带参数
- };
- },
- isShow() {},
- /**
- * swiper滚动事件
- * @param {*} e
- */
- swiperChange: function (e) {
- this.setData({
- topBannerCurrentSwiper: e.detail.current
- })
- },
- /**
- * 去支付
- */
- onPay() {
- // wx.requestPayment({
- // timeStamp: '',
- // nonceStr: '',
- // package: '',
- // signType: 'MD5',
- // paySign: '',
- // success(res) {},
- // fail(res) {}
- // })
- },
- /**
- * 弹框状态
- */
- onPopupState(e, key, value) {
- if (e) {
- key = e.currentTarget.dataset.key
- value = e.currentTarget.dataset.value
- }
- this.setData({
- [key]: value
- })
- },
- /**
- * 选择设备
- */
- onDeviceChange(e) {
- if (this.data.deviceList[e.currentTarget.dataset.index].status == 0) {
- return
- }
- this.setData({
- currentDevice: e.currentTarget.dataset.index
- })
- },
- onConfirmDevice() {
- let currentChangeDevice = this.data.deviceList[this.data.currentDevice]
- if (currentChangeDevice.status == 0) {
- wx.showToast({
- title: '当前设备已被预约',
- icon: 'none'
- })
- return
- }
- this.setData({
- currentChangeDevice
- })
- this.onPopupState(null, 'visible2', false)
- },
- onConfirmDate() {
- // if(this.data.currentChangeTime.status == 0) {
- // wx.showToast({
- // title: '当前设备已被预约',
- // icon: 'none'
- // })
- // return
- // }
- this.setData({
- currentChangeTime: this.data.tempTime
- })
- this.onPopupState(null, 'visible', false)
- this.getProjectDevice(this.data.currentChangeTime)
- },
- /**
- * 选择时间
- */
- onVisibleChange(e) {
- console.log(e)
- this.setData({
- // currentChangeTime: e.detail
- tempTime: e.detail
- })
- },
- /**
- * 获取详情页数据
- */
- getProjectInfo(product_id, store_id) {
- get(
- this.data.source === 'secondaryCard' ? 'v2/api/card/info' : 'api/product/info', this.data.source === 'secondaryCard' ? {
- id: this.data.sourceId,
- store_id
- } : {
- store_id,
- product_id,
- type: this.data.sourceType
- },
- (res) => {
- let content = this.removeCss(res.data.content)
- res.data.content = this.removeCss(res.data.content)
- WxParse.wxParse('article', 'html', content, this, 5)
- this.setData({
- projectData: res.data
- })
- }
- )
- },
- /**
- * 获取设备
- */
- getProjectDevice(time) {
- let {
- currentChangeTime
- } = this.data
- get(
- 'api/project/device', {
- project_id: this.data.projectData.id,
- store_id: this.data.projectData.store_id,
- order_day: currentChangeTime ? currentChangeTime.order_day : '',
- order_time_id: currentChangeTime ?
- currentChangeTime.time_id : currentChangeTime
- },
- (res) => {
- this.setData({
- deviceList: res.data
- },
- () => {
- this.onPopupState(null, 'visible2', true)
- }
- )
- }
- )
- },
- /**
- * 去除富文本图片默认样式
- */
- removeCss(content) {
- let reg = /(style|class)="[^"]+"/gi
- let img = /<img[^>]+>/gi
- let res
- if (img.test(content)) {
- res = content.match(img)
- for (let i = 0; i < res.length; i++) {
- content = content.replace(res[i], res[i].replace(reg, ''))
- }
- }
- // (/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
- return content.replace(/\<img/gi, '<img class="richImg" ')
- },
- // 这里是选择项目
- showProjectSelect() {
- let toSelectProduct = {}
- toSelectProduct.desc = this.data.projectData.tags
- toSelectProduct.cover_url = this.data.projectData.banner_urls[0]
- toSelectProduct.name = this.data.projectData.name
- toSelectProduct.use_time = this.data.projectData.use_time
- toSelectProduct.price = this.data.projectData.price
- toSelectProduct.id = this.data.projectData.id
- console.log(toSelectProduct,'toSelectProduct2222');
- this.setData({
- toSelectProduct: toSelectProduct,
- selectProductIndex: '空',
- showProducePup: true
- })
- this.productV2(toSelectProduct.id)
- },
- /**
- * 获取升级产品列表
- * /api/store/info
- */
- productV2(id) {
- console.log(222222);
- get(
- 'v2/api/product/product', {
- id: id,
- store_id: this.data.storeId
- },
- (res) => {
- this.setData({
- selectProductData: res.data
- })
- console.log(res)
- }
- )
- },
- selectProduct(e) {
- let index = e.currentTarget.dataset.index
- this.setData({
- selectProductIndex: index
- })
- },
- // 关闭产品包
- onClosePay() {
- this.setData({
- showProducePup: false
- })
- },
- submit_bottom: function () {
- let toSelectProducts = this.data.toSelectProduct
- if (this.data.selectProductIndex == '空') {
- toSelectProducts.selectMaterial = ''
- } else {
- toSelectProducts.selectMaterial = this.data.selectProductData.upgrade[this.data.selectProductIndex]
- }
- console.log(toSelectProducts)
- this.setData({
- showProducePup: false,
- toSelectProduct: toSelectProducts
- })
- this.setSubmitCar()
- },
- setSubmitCar() {
- let currentPage = getCurrentPages(); // 获取当前页的数据,
- let previousPage = currentPage[currentPage.length - 2]; // 上一页的数据,
- console.log(previousPage);
- let selectProductCarData =!previousPage?'':previousPage.data.selectProductCar
- console.log(previousPage, selectProductCarData, 'selectProductCarData');
- console.log(currentPage);
- if (!selectProductCarData) {
- console.log(11);
- let toSelectProduct = wx.getStorageSync('toSelectProduct')
- if (!toSelectProduct) {
- toSelectProduct = []
- } else {
- toSelectProduct = JSON.parse(toSelectProduct)
- }
- toSelectProduct.push(this.data.toSelectProduct)
- wx.setStorageSync('toSelectProduct', JSON.stringify(toSelectProduct))
- wx.showToast({
- title: '成功加入购物车!',
- icon: 'none'
- })
- setTimeout(() => {
- wx.switchTab({
- url: '/pages/orderBy/orderBy?cat_type=3',
- })
- }, 1000)
- return
- }
- for (let i = 0; i < selectProductCarData.length; i++) {
- if (selectProductCarData[i].id == this.data.toSelectProduct.id) {
- wx.showToast({
- title: '单项目只能选一次!',
- icon: "none"
- })
- return
- }
- }
- selectProductCarData.push(this.data.toSelectProduct)
- previousPage.setData({ //对上一个页面data中的参数进行赋值(上一个页面的数据是在当前页面进行赋值的),就变相实现了向上一个页面传值
- selectProductCar: selectProductCarData
- })
- previousPage.showCarMoney()
- wx.showToast({
- title: '成功加入购物车!',
- icon: 'none'
- })
- setTimeout(() => {
- wx.navigateBack()
- }, 1000)
- // wx.navigateBack({})
- },
- /**
- * 提交订单
- */
- addOrder() {
- if (this.data.source == 'goods' && this.data.projectData.num == 0) {
- wx.showToast({
- title: '库存不足',
- icon: 'none'
- })
- return
- }
- if (this.data.source == 'goods') {
- wx.navigateTo({
- url: `/pages/goodsOrderConfirm/goodsOrderConfirm?storeId=${this.data.storeId}&productId=${this.data.projectData.id}&isShow=false&source=${this.data.source}&isDirectOrder=true&goods_ids=${this.data.projectData.id}&type=2`,
- })
- return
- }
- if (this.data.source == 'project') {
- this.showProjectSelect()
- return
- }
- // if (!wx.getStorageSync('token')) {
- // wx.reLaunch({
- // url: '/pages/login/login'
- // })
- // return
- // }
- let {
- currentChangeDevice,
- currentChangeTime,
- projectData,
- source
- } =
- this.data
- let _projectData = Object.assign({}, projectData)
- delete _projectData.content
- let url = `/pages/reserveProject/reserveProject?source=${
- this.data.source
- }&projectData=${encodeURIComponent(JSON.stringify(_projectData))}`
- if (source == 'product') {
- url = `/pages/reserveProduct/reserveProduct?source=${
- this.data.source
- }&productData=${encodeURIComponent(JSON.stringify(_projectData))}`
- } else if (['goods', 'cardgoods', 'secondaryCard'].indexOf(source) > -1) {
- // 美妆产品、项目卡券产品 直接跳转到确认订单
- url = `/pages/orderConfirm/orderConfirm?source=${source}&data=${JSON.stringify(
- _projectData
- )}&deviceData={}&timeData={}&storeId=${this.data.storeId}`
- }
- wx.navigateTo({
- url: url
- })
- },
- // 美妆产品加入购物车
- addGoods(type) {
- if(type=='shopping'){
- wx.navigateTo({
- url: `/pages/goodsOrderConfirm/goodsOrderConfirm?storeId=${this.data.storeId}&productId=${this.data.projectData.id}&isShow=true&source=${this.data.source}`,
- })
- }else{
- let params = {
- goods_id: this.data.sourceId,
- store_id: this.data.storeId
- }
- post('v2/api/car/add', params, (res)=>{
- if(res.code == 200 ){
- wx.showToast({
- title: '成功加入购物车!',
- icon: 'none'
- })
- setTimeout(() => {
- wx.switchTab({
- url: '/pages/shoppingMall/shoppingMall?cat_type=3',
- })
- }, 1000);
- }
- })
- }
-
- // let params = {
- // goods_id: this.data.sourceId,
- // store_id: this.data.storeId
- // }
- // post('v2/api/car/add', params, (res) => {
- // if (res.code == 200) {
- // if (type == 'shopping') {
- // wx.navigateTo({
- // url: `/pages/goodsOrderConfirm/goodsOrderConfirm?storeId=${this.data.storeId}&productId=${this.data.projectData.id}&isShow=true&source=${this.data.source}`,
- // })
- // } else {
- // wx.showToast({
- // title: '成功加入购物车!',
- // icon: 'none'
- // })
- // setTimeout(() => {
- // wx.switchTab({
- // url: '/pages/orderBy/orderBy?cat_type=3',
- // })
- // }, 1000)
- // }
- // }
- // })
- }
- })
|