123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098 |
- const io = require('./socket.io-mp')
- var user = require('./services/user.js');
- const api = require('/config/api.js');
- const util = require('/utils/util.js');
- const UNLOGIN = 'NO_LOGIN'
- const btoa = require('./utils/btoa')
- const manyCount = 30
- import remote from './config.js'
- var app = getApp();
- var isIos = false
- wx.getSystemInfo({
- success: function (res) {
- isIos = res.platform == "ios"
- }
- })
- let urlToJson = (url = window.location.href) => { // 箭头函数默认传值为当前页面url
- let obj = {},
- index = url.indexOf('?'), // 看url有没有参数
- params = url.substr(index + 1); // 截取url参数部分 id = 1 & type = 2
- if (index != -1) { // 有参数时
- let parr = params.split('&'); // 将参数分割成数组 ["id = 1 ", " type = 2"]
- for (let i of parr) { // 遍历数组
- let arr = i.split('='); // 1) i id = 1 arr = [id, 1] 2)i type = 2 arr = [type, 2]
- obj[arr[0]] = arr[1]; // obj[arr[0]] = id, obj.id = 1 obj[arr[0]] = type, obj.type = 2
- }
- }
- return obj;
- }
- export default {
- joinUrl() {
- let options = {
- API_BASE_URL: api.API_BASE_URL,
- "url": this.data.url,
- // "url": 'http://192.168.0.109:8080',
- "reload": this.data.reload,
- "token": wx.getStorageSync('token'),
- "code": this.mcode,
- "brandId": this.options.id,
- "open": this.data.showCommodity,
- "pauseVideo": this.pauseVideo,
- "bottom": this.data.bottom || 0,
- socket: {
- socketHost: remote.socketHost,
- path: '/fsl-node',
- options: {
- ...this.data.socketOptions,
- nickname: encodeURI(encodeURI(this.data.socketOptions.nickname))
- }
- }
- }
- console.error('joinurl', options)
- // let base = 'http://127.0.0.1:5500/index.html'
- // let base = remote.viewHost + '/shop-container/shop.html'
- let sponsor = !!this.data.canShow
- if (this.data.join && !this.options.join) {
- sponsor = false
- }
- // remote.viewHost
- let base = remote.viewHost + '/shop-container/fashilong.html?env='+remote.env+'&sponsor=' + sponsor + '&many=' + this.data.many
- // let base = 'http://192.168.0.109:8081/shop-container/fashilong.html?env='+remote.env+'&sponsor=' + sponsor + '&many=' + this.data.many
- // let base = remote.viewHost + '/shop.html'
- this.data.reload = false
- this.data.showCommodity = false
- if (!this.data.webviewUrl) {
- this.setData({
- 'webviewUrl': base + '#' + JSON.stringify(options)
- })
- } else {
- this.socketSendMessage('clientSyncAction', {
- sender: 'h5',
- type: 'hashChange',
- data: options
- })
- }
- },
- onShow() {
- this.setData({
- isIos,
- showComtypesAllTab: false
- })
-
- if (this.socketSendMessage) {
- this.pauseVideo = false
- this.joinUrl()
- this.socketSendMessage('changeOnlineStatus', { status: true })
- }
- },
- changeShowComtypesAllTab(ev) {
- this.setData({
- showCommodity: false
- })
- setTimeout(() => {
- this.setData({
- showComtypesAllTab: ev.currentTarget.dataset.show,
- showCommodity: true
- })
- }, 100)
- },
- async authorizeRecord() {
- let isAuth = await new Promise((r, j) => {
- wx.authorize({
- scope: 'scope.record',
- success: () => r(true),
- fail: () => r(false)
- })
- })
- if (isAuth) return true
- let res = await new Promise(r => {
- wx.showModal({
- title: '提示',
- content: '您未授权录音,说话功能将无法使用',
- showCancel: true,
- confirmText: "授权",
- confirmColor: "#52a2d8",
- success: res => r(res),
- fail: () => r(false)
- })
- })
- if (!res || res.cancel) return;
- isAuth = await new Promise((r) => {
- wx.openSetting({
- success: res => r(res.authSetting['scope.record']),
- fail: () => r(false)
- })
- })
- return isAuth
- },
- async agetUserInfo() {
- const res = await util.request(api.UserInfo)
- if (res.errno === 401) {
- return {
- userId: UNLOGIN,
- avatar: ''
- }
- } else {
- const data = res.data
- data.region = data.city ? data.city.split(',') : []
- data.birthday = data.birthday || '1990-01-01'
- return data
- }
- },
- async getUserInfo() {
- let userInfo = wx.getStorageSync('userInfo');
- let token = wx.getStorageSync('token');
- if (userInfo && userInfo.userId && token) {
- let info = await this.agetUserInfo()
- return {
- ...userInfo,
- ...info,
- avatarUrl: info.avatar
- };
- } else {
- return {
- userId: UNLOGIN,
- avatar: ''
- }
- }
- // let detail
- // let isAuth = await new Promise((r, j) => {
- // wx.authorize({
- // scope: 'scope.userInfo',
- // success: () => r(true),
- // fail: () => r(false)
- // })
- // })
- // if (!isAuth) {
- // this.setData({userAuth: true})
- // detail = await new Promise(r => {
- // this.bindGetUserInfo = (e) => {
- // if (e.detail.userInfo) {
- // this.setData({userAuth: false})
- // console.log('gei', e.detail)
- // r(e.detail)
- // }
- // }
- // })
- // } else {
- // detail = await new Promise(r => {
- // wx.getUserInfo({
- // success: res => r(res),
- // fail: () => r(false)
- // })
- // })
- // }
- // try {
- // let res = await user.loginByWeixin(detail)
- // app.globalData.userInfo = res.data.userInfo;
- // app.globalData.token = res.data.token;
- // return res.data.userInfo
- // } catch(e) {
- // return false
- // }
- },
- login() {
- getApp().setLoginProps(false)
- },
- async getSocketOptions(sceneId, roomId) {
- let room = roomId || (Number(Date.now().toString().slice(4)) + parseInt((Math.random() * 1000)))
- // let room = '147852'
- let userInfo = await this.getUserInfo()
- // console.log('---', userInfo)
- // this.setData({
- // userInfoa: userInfo.nickname.split('').join(' ')
- // })
-
- this.role !== 'leader'
- let roomType
- if ((!this.data.canShow && !this.data.join) || (this.data.join && !this.options.join)) {
- roomType = '1v1'
- }
- return {
- role: this.role || 'leader',
- userId: userInfo.userId,
- roomType,
- avatar: userInfo.avatarUrl,
- nickname: userInfo.nickname,
- voiceStatus: getApp().globalData.voiceProps.noMute ? 0 : 2,
- enableTalk: this.role === 'leader' ? true : undefined,
- roomId: room,
- sceneNumber: sceneId,
- onlineStatus: true,
- userLimitNum: this.data.peopleCount
- }
- },
- async socketStart({
- sceneId,
- roomId,
- options
- }) {
- if (!options) {
- options = await this.getSocketOptions(sceneId, roomId)
- }
- console.log('小程序参数', options)
- let socket = io(remote.socketHost, {
- path: '/fsl-node',
- query: {
- ...options,
- isClient: true
- }
- })
- console.error('新建socket Room', options.roomId)
- this.setData({
- socketStatus: 0
- })
- socket.on('connect', () => this.setData({
- socketStatus: 1
- }))
- socket.on('connect_error', () => this.setData({
- socketStatus: -1
- }))
- socket.on('connect_timeout', () => this.setData({
- socketStatus: -1
- }))
- socket.on('disconnect', () => this.setData({
- socketStatus: -1
- }))
- socket.on('reconnect', () => {
- this.setData({
- socketStatus: 0
- })
- let noMute = getApp().globalData.voiceProps.noMute
- this.socketSendMessage('changeVoiceStatus', {
- status: noMute ? 0 : 2
- })
- this.socketSendMessage('changeOnlineStatus', { status: true })
- })
- socket.on('reconnect_failed', () => this.setData({
- socketStatus: -1
- }))
- socket.on('error', () => this.setData({
- socketStatus: -1
- }))
- socket.on('roomIn', config => {
- let enableTalk = config.roomsConfig.enableTalk !== false
- let noMute = getApp().globalData.voiceProps.noMute
- getApp().globalData.voiceProps.force = enableTalk
- if (!enableTalk && !noMute) {
- this.mic()
- }
- })
- this.socketSendMessage = (event, obj) => {
- let socket = this.socket
- console.error('发送 socket Room', options.roomId, event, obj, socket)
- try {
- socket.emit(event, obj)
- } catch (e) {
- console.error(e, '试图重新发送')
- setTimeout(() => {
- this.socketSendMessage(event, obj)
- }, 500)
- }
- }
- socket.on('clientSyncAction', (data) => {
- console.log('调用', data.type, '方法', data)
- if (this[data.type]) {
- this[data.type](data)
- } else {
- console.error('没有', data.type, '方法')
- }
- })
- socket.on('action', (data) => {
- if (data.type === 'navigateToGoods') {
- this.navigateToGoodsAction(data.data)
- }
- })
- socket.on('changeRoomEnableTalk', config => {
- if (this.role !== 'leader') {
- this.changeRoomEnableTalk(config)
- }
- })
- socket.on('startCall', this.startCall.bind(this))
- socket.on('stopCall', (data) => {
- console.log('on stopCall')
- this.stopCall(data)
- })
- socket.on('someOneInRoom', this.startCall.bind(this))
- socket.on('someOneLeaveRoom', (user, data) => {
- this.handleSomeOneLeave(user)
- })
- socket.on('roomClose', (data) => {
- console.log('on roomClose')
- this.stopCall(data)
- })
- this.socketStop = () => {
- socket.close()
- console.error('断开 并滞空 socket Room', options.roomId)
- this.setData({
- socketStatus: 2
- })
- socket = null
- }
- this.socket = socket
- return options
- },
- changeRoomEnableTalk(data) {
- console.log(data)
- let noMute = getApp().globalData.voiceProps.noMute
- getApp().globalData.voiceProps.force = data.enableTalk
- // noMute true 静音
- // enableTalk false 静音
- if (!!data.enableTalk === !!noMute) {
- this.mic()
- }
- },
- navigateToGoods({
- data
- }) {
- // wx.showToast({
- // title: JSON.stringify(data).substr(40)
- // })
- this.navigateToGoodsAction(data)
- },
- navigateToGoodsAction(id) {
- wx.navigateTo({
- url: '/pages/goods/goods?id=' + id,
- })
- },
- getUrl(url, socketOptions, isJoin) {
- url += '&room_id=' + socketOptions.roomId + '&user_id=' + socketOptions.userId + '&API_BASE_URL=' + api.API_BASE_URL + '&X-Nideshop-Token=' + wx.getStorageSync('token') + '&special=' + ~this.data.handleScenes.indexOf(this.data.sceneNumber) + '&canShow=' + this.data.canShow
-
- if (isJoin) {
- url += '&role=' + this.role + '&shopping'
- } else {
- url += '&role=' + this.role
- }
- console.error(url)
- console.log(isJoin)
- return url
- },
- navigateToMiniProgram(data) {
- wx.showModal({
- title: '温馨提示',
- content: '即将跳到其他小程序,是否继续?',
- showCancel: true, //是否显示取消按钮
- cancelText: "取消", //默认是“取消”
- confirmText: "确定", //默认是“确定”
- success: function (res) {
- if (res.cancel) {
- //点击取消,wx.navigateBack
- } else {
- wx.navigateToMiniProgram(data.data)
- }
- },
- fail: function (res) {
- //接口调用失败的回调函数,wx.navigateBack
- },
- complete: function (res) {
- //接口调用结束的回调函数(调用成功、失败都会执行)
- },
- })
- },
- async startCall(data) {
- if (!data) return;
- this.setData({
- surplus: this.data.peopleCount - data.roomsPerson.length
- })
- if (!this.isAuthorizeRecord) {
- const voiceStatus = Number(await this.authorizeRecord())
- this.isAuthorizeRecord = true
- // getApp().setVoiceProps({
- // noMute: !voiceStatus
- // })
- // console.log(getApp().globalData.voiceProps.noMute)
- // this.socketSendMessage('changeVoiceStatus', {
- // status: getApp().globalData.voiceProps.noMute ? 0 : 2
- // })
- // this.data.socketOptions.voiceStatus = 1
- // this.socketSendMessage('changeVoiceStatus', {status: noMute ? 0 : 2})
- }
- const socketOptions = this.data.socketOptions
- getApp().globalData.roomId = socketOptions.roomId
- const user = data.roomsPerson.find(user => user.userId == socketOptions.userId)
- if (!user) {
- return
- }
- if (data.roomsPerson.length <= 1) {
- return
- }
- user.noMute = getApp().globalData.voiceProps.noMute
- getApp().setVoiceProps({
- ...user,
- action: 'startCall'
- })
- // this.socketSendMessage('changeVoiceStatus', {
- // status: getApp().globalData.voiceProps.noMute ? 0 : 2
- // })
- },
- stopCall() {
- console.error('stopCall')
- getApp().setVoiceProps({
- noMute: false,
- action: 'stopCall'
- })
- if (this.runManager) {
- // this.recorderManager.stop()
- this.runManager = false
- }
- },
- handleSomeOneLeave(data) {
- if (data.roomsPerson.length <= 1) {
- // this.stopCall()
- }
- },
- async newRoom(data) {
- if (data.roomId) return;
- this.stopCall()
- getApp().globalData.rtcParams = []
- getApp().globalData.pusher = ''
- if (this.data.join && !this.options.join) {
- wx.switchTab({
- url: '/pages/index/index',
- })
- return;
- }
-
- this.role = this.data.canShow ? 'leader' : 'customer'
- let options = await this.getSocketOptions(this.mcode)
- this.socketSendMessage('clientSyncAction', {
- type: 'newRoom',
- data: options
- })
- setTimeout(async () => {
- this.wssSuccess = false
- this.socketStop && this.socketStop()
- this.data.many = !!this.data.canShow
-
- this.setData({
- peopleCount: this.data.many ? manyCount : 5
- })
- let base = this.base
- let socketOptions = await this.socketStart({
- options
- })
- let url = this.getUrl(base, socketOptions, false) + (this.urlPj || '')
- this.base = base
- this.setData({
- url,
- socketOptions,
- })
- this.joinUrl()
-
- this.setData({ socketOptions })
- this.loadConponSuccess = true
- this.readySendCouponCtrl()
- }, 300)
- },
- async exit() {
- this.stopCall()
- getApp().globalData.rtcParams = []
- getApp().globalData.pusher = ''
- this.socketStop && this.socketStop()
- this.role = 'leader'
- let base = this.base
- let socketOptions = await this.socketStart({
- sceneId: this.mcode
- })
- let url = this.getUrl(base, socketOptions, false) + (this.urlPj || '')
- this.base = base
- wx.nextTick(() => {
- setTimeout(() => {
- this.setData({
- url,
- loadUrl: true,
- socketOptions,
- showCommodityCtrl: false,
- hideWebView: false,
- reload: true
- })
- this.joinUrl()
- }, 500)
- })
- },
- clearDebuger() {
- this.setData({
- debugerInfo: ''
- })
- },
- async mic() {
- let noMute = getApp().globalData.voiceProps.noMute
-
-
- // noMute true 静音
- // enableTalk false 静音
- // if (!!getApp().globalData.voiceProps.force === !!noMute)
- // return
- // if (!getApp().globalData.voiceProps.force && (!this.data.socketOptions.voiceStatus || noMute)) return;
- if (!this.data.socketOptions.voiceStatus) {
- let voiceStatus = await this.authorizeRecord()
- if (voiceStatus) {
- this.data.socketOptions.voiceStatus = 1
- noMute = false
- } else {
- noMute = true
- }
- } else {
- noMute = !noMute
- }
- getApp().globalData.voiceProps.noMute = noMute
- this.socketSendMessage('changeVoiceStatus', {
- status: noMute ? 0 : 2
- })
- getApp().setVoiceProps({
- noMute
- })
- wx.showToast({
- title: `已${noMute ? '关闭' : '开启'}麦克风`,
- })
- },
- callPhone() {
- wx.makePhoneCall({
- phoneNumber: '400-2586366',
- })
- this.setData({
- showContact: false
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- let {
- id,
- newPicUrl
- } = this.data
- if (res.from === 'button') {
- this.setData({
- sendShare: false
- })
-
- return {
- title: '【好友邀请】一起来逛店吧!',
- imageUrl: newPicUrl,
- path: `/pages/webview/index?id=${id}&join=true&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}`,
- }
- } else {
- return {
- imageUrl: newPicUrl,
- path: `/pages/webview/index?id=${id}&join=false`,
- }
- }
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- console.log('on onUnload')
- this.socketSendMessage('stopCall', {})
- this.stopCall()
- this.socketStop()
- getApp().globalData.pusher = ''
- },
- cart(data) {
- this.setData({
- showCommodityCtrl: data.data
- })
- },
- share() {
- const companyName = `良房一廳`
- const vrLink = `/pages/webview/index`
- const img_url = this.data.newPicUrl || 'http://video.cgaii.com/new4dage/images/images/home_2_a.jpg'
- const shareImg = img_url
- let id = this.data.id
- this.count = this.count || 0
- console.log(`/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}`);
- wx.navigateTo({
- url: `/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${id}`,
- })
- },
- back(data) {
- if (data.sender !== 'h5') return;
- wx.switchTab({
- url: '/pages/index/index'
- })
- this.setData({
- showCommodityCtrl: false
- })
- },
- service() {
- this.setData({
- showContact: true,
- showCommodity: false,
- showCoupon: false
- })
- },
- invite(data) {
- if (data.sender !== 'h5') return;
- this.setData({
- sendShare: true,
- count: ++this.data.count
- })
- },
- coupon(data) {
- if (data.sender !== 'h5') return;
- this.setData({
- showContact: false,
- showCommodity: false,
- showCoupon: true
- })
- },
- liveGotoGood(ev) {
- let id = ev.currentTarget.dataset.item.goodsId
- wx.navigateTo({
- url: '/pages/goods/goods?id=' + id,
- })
- },
- gotoGoodsDOM(event) {
- this.gotoGoods(event.currentTarget.dataset.item.hotIdList[0])
- },
- gotoGoodsSocket(data) {
- this.gotoGoods(data.data)
- },
- gotoGoods(id) {
- console.log('---', id)
- this.socketSendMessage('clientSyncAction', {
- type: 'openTag',
- data: id
- })
- this.setData({
- showCommodity: false
- })
- this.joinUrl()
- },
- // 加入购物车
- addCard(data) {
- wx.navigateTo({
- url: '/pages/goods/goods?id=' + data.data
- // url: '/pages/goods/goods?id=' + data.data + '&oper=addCard',
- })
- },
- // 立即购买
- buyGoods(data) {
- wx.navigateTo({
- url: '/pages/goods/goods?id=' + data.data
- // url: '/pages/goods/goods?id=' + data.data + '&oper=buyGoods',
- })
- },
- showCommodityFn() {
- this.setData({
- showCommodity: true,
- showContact: false,
- showCoupon: false
- })
- this.joinUrl()
- },
- hideComodity() {
- this.setData({
- showCommodity: false
- })
- this.joinUrl()
- },
- hideCoupon() {
- this.setData({
- showCoupon: !this.data.showCoupon
- })
- },
- async receive(ev) {
- let item = ev.target.dataset.item
- try {
- // wx.showToast({
- // title: '领取优惠卷',
- // })
- // return;
- if (item.hasReceived || item.number <= item.receiveNumber) return;
- let res = await util.request(api.CouponExchange, {
- couponId: item.id
- })
- if (res.code === 0) {
- wx.showToast({
- title: '已成功领取',
- success: () => {
- this.setData({
- showCoupon: false
- })
- wx.nextTick(() => {
- this.setData({
- coupons: this.data.coupons.map(citem => {
- return {
- ...citem,
- hasReceived: citem.id === item.id ? true : citem.hasReceived
- }
- }),
- showCoupon: true
- })
- })
- }
- })
- } else if (res.errno === 401) {
- getApp().setLoginProps(false)
- } else {
- wx.showToast({
- title: res.msg,
- })
- }
- } catch (e) {
- console.error(e)
- wx.showToast({
- icon: 'none',
- title: '领取失败',
- })
- }
- },
- async getCouponList(id) {
- const success = (res) => {
- this.setData({
- coupons: res.data.list.map(item => {
- item.typeMoney = item.typeMoney.toString()
- item.fontSize = item.typeMoney.length === 3 ? '90rpx' :
- item.typeMoney.length === 4 ? '70rpx' : '130rpx'
- return item
- })
- })
- this.loadConponSuccess = true
- this.readySendCouponCtrl()
- }
- let res = await util.request(api.BrandCouponList, {
- brandId: id,
- pageNum: 1,
- pageSize: 10000
- }, 'GET')
- console.log(res)
- if (res.code === 0) {
- success(res)
- } else {
- let res = await util.request(api.UNBrandCouponList, {
- brandId: id,
- pageNum: 1,
- pageSize: 10000
- }, 'GET')
- success(res)
- }
- },
- ready() {
- this.wssSuccess = true
- this.readySendCouponCtrl()
- },
- readySendCouponCtrl() {
-
- if (this.wssSuccess && this.loadConponSuccess) {
- this.loadConponSuccess = false
-
- this.socketSendMessage('clientSyncAction', {
- type: 'showCoupon',
- data: this.data.coupons.length > 0
- })
- }
- },
- getBrand: function (id, code) {
- this.getGoodsCount(code, id)
- return;
- let that = this;
- util.request(api.SueneCategory, {
- sceneNum: code
- }, 'GET').then(function (res) {
- if (res.code === 0) {
- const comtypes = res.list.map(item => {
- item.width = (item.name.length + (item.num.toString().length / 2) + 2) * 16
- return {
- ...item
- }
- })
- that.setData({
- comWidth: comtypes.reduce((a, b) => a + b.width + 10, 0),
- comtypes,
- thumComtypes: (!isIos && comtypes.length > 3) ? comtypes.slice(0, 3) : null,
- currTypeId: comtypes.length > 0 && comtypes[0].category_id
- });
- wx.showToast({
- title: 'currTypeId' + that.data.currTypeId.length,
- })
- that.data.currTypeId && that.getGoodsList(id, that.data.currTypeId);
- }
- });
- },
- getGoodsCount(code, id) {
- util.request(api.GoodsNumCount, {
- isDelete: 0,
- isOnSale: 1,
- brandId: id
- }, 'GET')
- .then(res => {
- if (res.code === 0) {
- this.setData({
- goodsCount: res.data
- })
- }
- this.getCouponList(id)
- })
- },
- getGoodsList(id, category_id) {
- var that = this;
- if (!(this.data.navList && this.data.navList.length)) {
- that.navDatas = {}
- let navDatas = this.data.navList = this.data.comtypes
- // util.request(api.GoodsCategory, { id: category_id })
- // .then(function (res) {
- // if (res.errno == 0) {
- // let navDatas = res.data.brotherCategory
- // that.setData({
- // navList: navDatas,
- // currTypeId: category_id
- // });
- that.navDatas = {}
- navDatas.forEach(item => {
- util.request(api.GoodsList, {
- brandId: id,
- categoryId: item.category_id,
- page: that.data.page,
- size: that.data.size
- })
- .then(res => {
- if (res.errno === 0) {
- that.navDatas[item.category_id] = res.data.goodsList
- }
- })
- })
- // }
- // })
- }
- if (that.navDatas[category_id]) {
- if (!isIos) {
- let showCommodity = that.data.showCommodity
- that.setData({
- showCommodity: false
- })
- setTimeout(() => {
- wx.nextTick(() => {
- that.setData({
- goodsList: that.navDatas[category_id],
- currTypeId: category_id,
- showCommodity: showCommodity
- });
- })
- }, 500)
- } else {
- that.setData({
- goodsList: that.navDatas[category_id],
- currTypeId: category_id,
- });
- }
- } else {
- console.error('诱惑去啦')
- util.request(api.GoodsList, {
- brandId: id,
- categoryId: category_id,
- page: that.data.page,
- size: that.data.size
- })
- .then(function (res) {
- if (res.errno === 0) {
- that.setData({
- goodsList: res.data.goodsList,
- currTypeId: category_id
- });
- // this.data.navList
- }
- });
- }
- },
- getBrandDetail: function (id, cb) {
- util.request(api.BrandDetail, {
- id: id
- }).then((res) => {
- let base = res.data.brand.sceneUrl
- // let base = 'http://192.168.0.109:8081' + res.data.brand.sceneUrl.substr(res.data.brand.sceneUrl.indexOf('/grave.html'))
- // let base = 'http://192.168.0.109:8080/shop.html?m=t-7Uqj9Fq&origin=fashilong'
- res.data.brand.canShow = !!res.data.brand.canShow
- // res.data.brand.canShow = false
- if (res.errno === 0) {
- let url = base + "&sid=" + id
- this.setData({
- id: id,
- newPicUrl: res.data.brand.appListPicUrl,
- sceneNum: res.data.brand.sceneNum,
- canShow: res.data.brand.canShow,
- contractPhone: res.data.brand.contractPhone
-
- })
- if (this.data.many === void 0) {
- this.data.many = !!res.data.brand.canShow
- }
- this.setData({
- peopleCount: this.data.many ? manyCount : 5,
- })
-
- if (!res.data.brand.canShow) {
- this.role = 'customer'
- } else if (!this.options.join){
- this.role = 'leader'
- }
- cb(url, urlToJson(url).m, )
- }
- });
- },
- selectType(ev) {
- this.getGoodsList(this.options.id, ev.target.dataset.item.category_id)
- },
- hideCS() {
- this.setData({
- showCommodity: false,
- showCoupon: false,
- showContact: false
- })
- },
- hideContact() {
- this.setData({
- showContact: false
- })
- },
- calcShare() {
- // this.exit()
- this.setData({
- sendShare: false
- })
- },
- contactKf() {
- let keys = Object.keys(this.navDatas)
- let goodsId = this.navDatas[keys[0]][0].id
- let user = wx.getStorageSync('userinfoDetail')
- util.request(api.AddTalkCount, {
- goodsId,
- viewId: user && user.userId || '',
- sceneNum: this.data.sceneNum
- }, 'get')
- this.hideAlert && this.hideAlert()
- this.hideContact && this.hideContact()
- },
- onHide() {
- this.socketSendMessage('changeOnlineStatus', { status: false })
-
- this.pauseVideo = true
- this.joinUrl()
- }
- }
|