123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- import {
- get,
- post
- } from '../../utils/http'
- import {
- PROJECT_TYPE
- } from '../../utils/global'
- var WxParse = require('../../components/local/wxParse/wxParse.js')
- const app = getApp()
- 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: {},
- shareInfo: '',
- isNewUser: 0,
- isSkinPlan: false,
- isTestSkin: false,
- },
-
- onLoad: function (options) {
- console.log(options, 'options')
-
- if (options.q) {
- let ticket = decodeURIComponent(options.q)
- console.log(ticket);
- var reg = new RegExp("(^|\\?|&)" + 'source' + "=([^&]*)(\\s|&|$)", "i");
- var reg1 = new RegExp("(^|\\?|&)" + 'id' + "=([^&]*)(\\s|&|$)", "i");
- var reg2 = new RegExp("(^|\\?|&)" + 'shareUserId' + "=([^&]*)(\\s|&|$)", "i");
- if (reg.test(ticket)) {
- options.source = unescape(RegExp.$2.replace(/\+/g, " "));
- };
- if (reg1.test(ticket)) {
- options.id = unescape(RegExp.$2.replace(/\+/g, " "));
- };
- if (reg2.test(ticket)) {
- app.globalData.shareUserId = unescape(RegExp.$2.replace(/\+/g, " "));
- console.log(unescape(RegExp.$2.replace(/\+/g, " ")), 'options.q');
- };
- app.globalData.isH5 = true
- }
- let source = options.source || 'project'
- let sourceId = options.project_id || options.id
- let sourceType = PROJECT_TYPE[source] || 1
- let isSkinPlan = false
- if (options.isSkinPlan=='true') {
- isSkinPlan = true
- }
- let isTestSkin = false
- if (options.isTestSkin=='true') {
- isTestSkin = true
- }
- if (options.shareUserId) {
- app.globalData.shareUserId = options.shareUserId
- }
- console.log(app.globalData.shareUserId);
- 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,
- isSkinPlan,
- isTestSkin
- }, () => {
- })
-
- wx.onCopyUrl(() => {
- let userID = wx.getStorageSync('userInfo')
- return {
- query: `project_id=${this.data.sourceId}&source=${this.data.source}&store_id=${wx.getStorageSync('store_id')}&shareUserId=${userID.uid}`
- }
- })
-
- this.getShareInfo()
-
- this.checkNewUser()
-
- this.skinPlanRecord()
- },
-
- 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 () {},
-
- skinPlanRecord() {
- let url = this.data.isTestSkin ? '/v2/api/order/skin' : 'v2/api/order/recommend'
- if (this.data.isTestSkin || this.data.isSkinPlan) {
- get(url, {
- type: 1
- }, (res) => {})
- }
- },
-
- onShareAppMessage: function () {
- console.log(this.data.sourceId, 'this.data.sourceId')
- let userID = wx.getStorageSync('userInfo')
- return {
- title: this.data.shareInfo.share_text,
- imageUrl: this.data.shareInfo.share_image,
- path: `pages/projectDetail/projectDetail?project_id=${this.data.sourceId}&source=${this.data.source}&store_id=${wx.getStorageSync('store_id')}&shareUserId=${userID.uid}`,
- };
- },
- isShow() {},
-
- getShareInfo() {
- get('v2/api/share/info', {
- id: this.data.sourceId,
- type: this.data.source == 'secondaryCard' ? 'card' : this.data.source
- }, res => {
- this.setData({
- shareInfo: res.data
- })
- })
- },
-
- swiperChange: function (e) {
- this.setData({
- topBannerCurrentSwiper: e.detail.current
- })
- },
-
- onPay() {
-
-
-
-
-
-
-
-
-
- },
-
- 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() {
-
-
-
-
-
-
-
- this.setData({
- currentChangeTime: this.data.tempTime
- })
- this.onPopupState(null, 'visible', false)
- this.getProjectDevice(this.data.currentChangeTime)
- },
-
- onVisibleChange(e) {
- console.log(e)
- this.setData({
-
- 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)
- res.data.new_price = Number(res.data.new_price)
- 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, ''))
- }
- }
-
- 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.new_price = this.data.projectData.new_price
- toSelectProduct.id = this.data.projectData.id
- console.log(toSelectProduct, 'toSelectProduct2222');
- this.setData({
- toSelectProduct: toSelectProduct,
- selectProductIndex: '空',
- showProducePup: true
- })
- this.productV2(toSelectProduct.id)
- },
-
- productV2(id) {
- 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
- if (!selectProductCarData) {
- 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(() => {
-
- if (this.data.isTestSkin) {
- app.globalData.isTestSkin = true
- } else if (this.data.isSkinPlan) {
- app.globalData.isSkinPlan = true
- }
- 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({
- selectProductCar: selectProductCarData
- })
- previousPage.showCarMoney()
- wx.showToast({
- title: '成功加入购物车!',
- icon: 'none'
- })
- setTimeout(() => {
- wx.navigateBack()
- }, 1000)
-
- },
-
- 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,
- source: app.globalData.isH5 ? 'h5' : '',
- share_user_id: app.globalData.shareUserId || '',
- }
- 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);
- }
- })
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
-
- checkNewUser() {
- get('v2/api/order/check_new_user', {}, (res => {
-
- this.setData({
- isNewUser: res.data.status
- })
- }))
- }
- })
|