socket.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. const {
  2. io
  3. } = require('./socket.io-v4.msgpack.js');
  4. var user = require('./services/user.js');
  5. const api = require('/config/api.js');
  6. const util = require('/utils/util.js');
  7. const UNLOGIN = 'NO_LOGIN'
  8. const btoa = require('./utils/btoa');
  9. const manyCount = 50
  10. import remote from './config.js'
  11. var app = getApp();
  12. var isIos = false
  13. wx.getSystemInfo({
  14. success: function (res) {
  15. isIos = res.platform == "ios"
  16. }
  17. })
  18. const debounce = (fn, wait) => {
  19. let callback = fn;
  20. let timerId = null;
  21. function debounced() {
  22. let context = this;
  23. let args = arguments;
  24. clearTimeout(timerId);
  25. timerId = setTimeout(function () {
  26. callback.apply(context, args);
  27. }, wait);
  28. }
  29. return debounced;
  30. }
  31. let urlToJson = (url = window.location.href) => { // 箭头函数默认传值为当前页面url
  32. let obj = {},
  33. index = url.indexOf('?'), // 看url有没有参数
  34. params = url.substr(index + 1); // 截取url参数部分 id = 1 & type = 2
  35. if (index != -1) { // 有参数时
  36. let parr = params.split('&'); // 将参数分割成数组 ["id = 1 ", " type = 2"]
  37. for (let i of parr) { // 遍历数组
  38. let arr = i.split('='); // 1) i id = 1 arr = [id, 1] 2)i type = 2 arr = [type, 2]
  39. obj[arr[0]] = arr[1]; // obj[arr[0]] = id, obj.id = 1 obj[arr[0]] = type, obj.type = 2
  40. }
  41. }
  42. return obj;
  43. }
  44. export default {
  45. joinUrl() {
  46. let url = this.data.url;
  47. //隐藏部分
  48. // if (this.data.url && /smobile.html/.test(this.data.url)) {
  49. // const newUrl = this.data.url.replace('smobile.html', 'shop.html')
  50. // url = newUrl
  51. // this.setData({
  52. // url: newUrl
  53. // });
  54. // }
  55. let options = {
  56. API_BASE_URL: api.API_BASE_URL,
  57. "url": url,
  58. // "url": 'http://192.168.0.112:8080',
  59. "reload": this.data.reload,
  60. "token": wx.getStorageSync('token'),
  61. "code": this.mcode,
  62. "brandId": this.options.id,
  63. "open": this.data.showCommodity,
  64. "pauseVideo": this.pauseVideo,
  65. "bottom": this.data.bottom || 0,
  66. socket: {
  67. socketHost: remote.socketHost,
  68. path: '/new-zfb',
  69. options: {
  70. ...this.data.socketOptions,
  71. // nickname: encodeURI(encodeURI(this.data.socketOptions.nickname))
  72. nickname: encodeURIComponent(encodeURIComponent(this.data.socketOptions.nickname))
  73. }
  74. }
  75. }
  76. // let base = 'http://127.0.0.1:5500/index.html'
  77. // let base = remote.viewHost + '/shop-container/shop.html'
  78. let sponsor = !!this.data.canShow
  79. if (this.data.join && !this.options.join) {
  80. sponsor = false
  81. }
  82. // 33是从我的房间出来的
  83. if (Number(this.data.type) === 33) {
  84. sponsor = true;
  85. }
  86. // debugger
  87. // remote.viewHost
  88. let hostUrl
  89. if (options.url.indexOf('www.4dkankan.com') != -1) {
  90. hostUrl = 'https://www.4dkankan.com/shop-container-zfb/'
  91. } else if (options.url.indexOf('test.4dkankan.com') != -1) {
  92. hostUrl = 'https://test.4dkankan.com/shop-container-zfb/'
  93. } else {
  94. // hostUrl = 'https://zfb.4dkankan.com/shop-container/'
  95. // hostUrl = remote.viewHost + '/shop-container/'
  96. hostUrl = remote.viewHost + '/shop-container-v4/'
  97. }
  98. // let base = remote.viewHost + '/shop-container/fashilong.html?env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
  99. let base = hostUrl + 'fashilong.html?time=' + Date.now() + '&env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
  100. // let base = remote.viewHost + '/shop.html'
  101. this.data.reload = false
  102. this.data.showCommodity = false
  103. //上线前隐藏Vlog
  104. // options.url = options.url + '&vlog';
  105. if (!this.data.webviewUrl) {
  106. console.log(base)
  107. this.setData({
  108. 'webviewUrl': base + '#' + JSON.stringify(options)
  109. })
  110. } else {
  111. this.socketSendMessage('clientSyncAction', {
  112. sender: 'h5',
  113. type: 'hashChange',
  114. data: options
  115. })
  116. }
  117. },
  118. onShow() {
  119. this.setData({
  120. isIos,
  121. showComtypesAllTab: false
  122. })
  123. // wx.showToast({
  124. // title: '测试--socket.connected' + this.socket.connected,
  125. // })
  126. const onlineAction = () => {
  127. this.pauseVideo = false
  128. this.joinUrl()
  129. // debugger
  130. this.socketSendMessage('changeOnlineStatus', {
  131. status: 1
  132. })
  133. }
  134. console.warn("socketInstance-1", this.socketInstance);
  135. if (this.socketInstance) {
  136. if (!this.socketInstance.connected) {
  137. // wx.showToast({
  138. // title: 'socketInstance-2',
  139. // icon: 'none',
  140. // duration: 5000
  141. // })
  142. // this.socketInstance.connect();
  143. // wx.showModal({
  144. // title: '提示',
  145. // content: '欧克',
  146. // showCancel: false,
  147. // confirmColor: '#0075DC',
  148. // success: function (res) {}
  149. // })
  150. setTimeout(onlineAction, 300)
  151. } else {
  152. // wx.showToast({
  153. // title: 'socketInstance-3',
  154. // icon: 'none',
  155. // duration: 5000
  156. // })
  157. onlineAction();
  158. }
  159. }
  160. // if (this.socketSendMessage) {
  161. // this.pauseVideo = false
  162. // this.joinUrl()
  163. // // debugger
  164. // this.socketSendMessage('changeOnlineStatus', {
  165. // status: 1
  166. // })
  167. // }
  168. },
  169. changeShowComtypesAllTab(ev) {
  170. this.setData({
  171. showCommodity: false
  172. })
  173. setTimeout(() => {
  174. this.setData({
  175. showComtypesAllTab: ev.currentTarget.dataset.show,
  176. showCommodity: true
  177. })
  178. }, 100)
  179. },
  180. async authorizeRecord() {
  181. let isAuth = await new Promise((r, j) => {
  182. wx.authorize({
  183. scope: 'scope.record',
  184. success: () => r(true),
  185. fail: () => r(false)
  186. })
  187. })
  188. if (isAuth) return true
  189. let res = await new Promise(r => {
  190. wx.showModal({
  191. title: '提示',
  192. content: '您未授权录音,说话功能将无法使用',
  193. showCancel: true,
  194. confirmText: "授权",
  195. confirmColor: "#52a2d8",
  196. success: res => r(res),
  197. fail: () => r(false)
  198. })
  199. })
  200. if (!res || res.cancel) return;
  201. isAuth = await new Promise((r) => {
  202. wx.openSetting({
  203. success: res => r(res.authSetting['scope.record']),
  204. fail: () => r(false)
  205. })
  206. })
  207. return isAuth
  208. },
  209. // 获取录音权限状态
  210. async getAuthorizeRecordStatus() {
  211. const isAuth = await new Promise((r, j) => {
  212. wx.authorize({
  213. scope: 'scope.record',
  214. success: () => r(true),
  215. fail: () => r(false)
  216. })
  217. })
  218. return Promise.resolve(isAuth)
  219. },
  220. async agetUserInfo() {
  221. const res = await util.request(api.UserInfo)
  222. if (res.errno === 401) {
  223. return {
  224. userId: UNLOGIN,
  225. avatar: ''
  226. }
  227. } else {
  228. const data = res.data
  229. data.region = data.city ? data.city.split(',') : []
  230. data.birthday = data.birthday || '1990-01-01'
  231. if (!data.nickname || !data.avatar || !data.mobile) {
  232. this.setData({
  233. isNotPersonalfullpack: true
  234. })
  235. }
  236. data.nickname = data.nickname ? data.nickname : data.username
  237. data.avatar = data.avatar ? data.avatar : 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
  238. return data
  239. }
  240. },
  241. async getUserInfo() {
  242. let userInfo = wx.getStorageSync('userInfo');
  243. let token = wx.getStorageSync('token');
  244. if (userInfo && userInfo.userId && token) {
  245. let info = await this.agetUserInfo()
  246. return {
  247. ...userInfo,
  248. ...info,
  249. avatarUrl: info.avatar
  250. };
  251. } else {
  252. return {
  253. userId: UNLOGIN,
  254. avatar: ''
  255. }
  256. }
  257. // let detail
  258. // let isAuth = await new Promise((r, j) => {
  259. // wx.authorize({
  260. // scope: 'scope.userInfo',
  261. // success: () => r(true),
  262. // fail: () => r(false)
  263. // })
  264. // })
  265. // if (!isAuth) {
  266. // this.setData({userAuth: true})
  267. // detail = await new Promise(r => {
  268. // this.bindGetUserInfo = (e) => {
  269. // if (e.detail.userInfo) {
  270. // this.setData({userAuth: false})
  271. // console.log('gei', e.detail)
  272. // r(e.detail)
  273. // }
  274. // }
  275. // })
  276. // } else {
  277. // detail = await new Promise(r => {
  278. // wx.getUserInfo({
  279. // success: res => r(res),
  280. // fail: () => r(false)
  281. // })
  282. // })
  283. // }
  284. // try {
  285. // let res = await user.loginByWeixin(detail)
  286. // app.globalData.userInfo = res.data.userInfo;
  287. // app.globalData.token = res.data.token;
  288. // return res.data.userInfo
  289. // } catch(e) {
  290. // return false
  291. // }
  292. },
  293. login() {
  294. getApp().setLoginProps(false)
  295. },
  296. async getSocketOptions(sceneId, roomId) {
  297. //TODO
  298. console.log('this.data.type', this.data.type)
  299. // debugger;
  300. let result
  301. if (Number(this.data.type) === 33) {
  302. result = await util.request(api.enterRoom, {
  303. businessId: roomId
  304. }, 'POST', 'application/json')
  305. if (result.code !== 200) {
  306. wx.showModal({
  307. content: result.error,
  308. complete: () => {
  309. if (result.message && result.message.isAnchor == 0) {
  310. wx.switchTab({
  311. url: '/pages/index/index',
  312. })
  313. } else {
  314. wx.redirectTo({
  315. url: '/pages/roomManger/roomManger',
  316. });
  317. }
  318. }
  319. })
  320. return
  321. }
  322. }
  323. const capacities = !!result ? result.message.capacities : 50 // 房间限制人数
  324. const {
  325. isAnchor,
  326. assistant,
  327. } = !!result ? result.message : {}
  328. let userInfo = await this.getUserInfo()
  329. // console.log('---', userInfo)
  330. // this.setData({
  331. // userInfoa: userInfo.nickname.split('').join(' ')
  332. // })
  333. userInfo.nickname = userInfo.nickname.replace(/[^\u4E00-\u9FA5A-Za-z0-9]/g, '')
  334. if (userInfo.nickname == "") {
  335. userInfo.nickname = "口"
  336. }
  337. // this.role !== 'leader'
  338. // let roomType
  339. // if ((!this.data.canShow && !this.data.join) || (this.data.join && !this.options.join)) {
  340. // // roomType = '1v1'
  341. // if (this.options.roomId) {
  342. // this.role = 'leader'
  343. // }
  344. // console.log('**************')
  345. // console.log(this.options)
  346. // }
  347. let isAllowMic // 真正MIC权, 房主与 授权一个 要在房间isAllowMic开启
  348. if (Number(isAnchor) === 1) {
  349. this.role = "leader"
  350. isAllowMic = 1
  351. } else {
  352. this.role = 'customer'
  353. isAllowMic = 0
  354. }
  355. // 助手改用isAssistant作为flag, role因为V3不能新增角色,只支持leader/customer。
  356. let isAssistant
  357. if (assistant && assistant.userId && assistant.userId == userInfo.userId) {
  358. isAssistant = true;
  359. } else {
  360. isAssistant = false
  361. }
  362. console.log('进入房间角色, 是否助手 %s', this.role, isAssistant);
  363. const isAuthMic = await this.getAuthorizeRecordStatus();
  364. // console.log('当前用户录音权限状态', isAuthMic)
  365. this.setData({
  366. isAllowMic,
  367. isAuthMic
  368. })
  369. const assistantId = (assistant && assistant.userId) ? assistant.userId : '';
  370. if (capacities) {
  371. this.setData({
  372. peopleCount: capacities
  373. })
  374. } else {
  375. this.setData({
  376. peopleCount: manyCount
  377. })
  378. }
  379. return {
  380. role: this.role,
  381. userId: userInfo.userId,
  382. // roomType,
  383. avatar: userInfo.avatarUrl,
  384. nickname: userInfo.nickname,
  385. voiceStatus: getApp().globalData.voiceProps.noMute ? 0 : 2,
  386. isAuthMic: isAuthMic ? 1 : 0,
  387. isAllowMic: isAllowMic,
  388. roomId: roomId,
  389. sceneNumber: sceneId,
  390. onlineStatus: 1,
  391. assistantId: assistantId,
  392. isAssistant: isAssistant ? 1 : 0,
  393. oid: userInfo.weixin_openid,
  394. userLimitNum: capacities || 50
  395. }
  396. },
  397. async socketStart({
  398. sceneId,
  399. roomId,
  400. options
  401. }) {
  402. if (!options) {
  403. options = await this.getSocketOptions(sceneId, roomId)
  404. }
  405. console.log('小程序参数', options)
  406. if (!options.roomId) {
  407. return Promise.resolve(false)
  408. }
  409. // 真正进入统计
  410. if (this.data.inviterId) {
  411. // wx.showToast({
  412. // title: '邀请人ID:' + this.data.inviterId,
  413. // })
  414. }
  415. if (options.roomId !== '888888') {
  416. util.request(api.trackRoom, {
  417. roomId: options.roomId,
  418. inviterId: this.data.inviterId || '',
  419. type: 0
  420. }, 'POST', 'application/json')
  421. }
  422. let userInfo = await this.getUserInfo()
  423. let socket = io(remote.socketHost, {
  424. path: '/new-zfb',
  425. transport: ['websocket'],
  426. extraHeaders: {
  427. "oid": userInfo.weixin_openid
  428. },
  429. query: {
  430. ...options,
  431. isClient: true,
  432. from: 2
  433. }
  434. });
  435. this.socketInstance = socket
  436. console.error('新建socket Room', options.roomId)
  437. this.setData({
  438. socketStatus: 0,
  439. })
  440. socket.on('connect', () => this.setData({
  441. socketStatus: 1
  442. }))
  443. socket.on('connect_error', () => this.setData({
  444. socketStatus: -1
  445. }))
  446. socket.on('connect_timeout', () => this.setData({
  447. socketStatus: -1
  448. }))
  449. socket.on('disconnect', () => this.setData({
  450. socketStatus: -1
  451. }))
  452. socket.on('reconnect', () => {
  453. // wx.showToast({
  454. // title: '重连',
  455. // })
  456. this.setData({
  457. socketStatus: this.data.socketStatus
  458. })
  459. let noMute = getApp().globalData.voiceProps.noMute
  460. this.socketSendMessage('changeVoiceStatus', {
  461. status: noMute ? 0 : 2
  462. })
  463. this.socketSendMessage('changeOnlineStatus', {
  464. status: 1
  465. })
  466. })
  467. socket.on('reconnect_failed', () => this.setData({
  468. socketStatus: -1
  469. }))
  470. socket.on('error', () => this.setData({
  471. socketStatus: -1
  472. }))
  473. socket.on('roomIn', config => {
  474. let enableTalk = config.roomsConfig.enableTalk !== false
  475. let noMute = getApp().globalData.voiceProps.noMute
  476. getApp().globalData.voiceProps.force = enableTalk
  477. if (!enableTalk && !noMute) {
  478. if (this.role !== 'leader') {
  479. // this.mic()
  480. }
  481. }
  482. })
  483. this.socketSendMessage = (event, obj) => {
  484. console.error('发送 socket Room', options.roomId, event, obj)
  485. socket && socket.emit(event, obj)
  486. }
  487. socket.on('clientSyncAction', (data) => {
  488. console.log('调用', data.type, '方法', data)
  489. if (this[data.type]) {
  490. this[data.type](data)
  491. } else if (data.type == 'wx-subscribe') {
  492. this.getUrlCode(data.data)
  493. } else {
  494. console.error('没有', data.type, '方法')
  495. }
  496. })
  497. socket.on('action', (data) => {
  498. if (data.type === 'navigateToGoods') {
  499. this.navigateToGoodsAction(data.data)
  500. }
  501. })
  502. socket.on('changeRoomEnableTalk', config => {
  503. if (this.role !== 'leader') {
  504. this.changeRoomEnableTalk(config)
  505. }
  506. })
  507. socket.on('startCall', this.startCall.bind(this))
  508. socket.on('stopCall', (data) => {
  509. console.log('on stopCall')
  510. this.stopCall(data)
  511. })
  512. this.handleSomeOneInRoom = this.handleSomeOneInRoom.bind(this)
  513. // socket.on('someOneInRoom', debounce(this.handleSomeOneInRoom, 100))
  514. socket.on('someOneInRoom', debounce(this.handleSomeOneInRoom, 100))
  515. socket.on('someOneLeaveRoom', (user, data) => {
  516. this.handleSomeOneLeave(user)
  517. })
  518. socket.on('roomClose', (data) => {
  519. console.log('on roomClose')
  520. this.stopCall(data)
  521. })
  522. socket.on('autoReJoin', (data) => {
  523. console.log('on autoReJoin')
  524. if ('roomId' in data) {
  525. options.roomId = Number(data.roomId)
  526. }
  527. })
  528. // 有MIC通知,主要是其他用户禁MIC 移到中间层处理。
  529. // socket.on('beHasMic', (data) => {
  530. // const socketOptions = this.data.socketOptions
  531. // if (data.user) {
  532. // const isOther = (socketOptions.role !== 'leader' && (Number(socketOptions.userId) !== Number(data.user.userId)));
  533. // if (isOther) {
  534. // this.closeMic();
  535. // // wx.showToast({
  536. // // title: '关mic' + isOther
  537. // // })
  538. // }
  539. // }
  540. // })
  541. socket.on("beKicked", data => {
  542. const that = this
  543. if (data.userId && data.roomId) {
  544. const socketOptions = this.data.socketOptions
  545. const userId = data.userId
  546. const roomId = data.roomId
  547. // debugger
  548. if (socketOptions.userId == userId && this.options.roomId == roomId) {
  549. this.exitRoom();
  550. wx.showToast({
  551. title: '您已被踢出房间!',
  552. icon: 'none',
  553. complete: () => {
  554. setTimeout(() => {
  555. that.socketStop();
  556. wx.switchTab({
  557. url: '/pages/index/index',
  558. })
  559. }, 1000)
  560. }
  561. })
  562. }
  563. }
  564. });
  565. socket.on("roomMaximum", () => {
  566. this.setData({
  567. roomMaximum: true
  568. })
  569. });
  570. //全员退出
  571. socket.on('roomDisMiss', () => {
  572. // wx.showToast({
  573. // title: '全员退出',
  574. // });
  575. this.setData({
  576. roomDisMiss: true
  577. })
  578. try {
  579. this.exitRoomApi();
  580. } catch (error) {
  581. console.log('error', error)
  582. }
  583. // this.exitRoom();
  584. })
  585. //服务器未知错误重进
  586. socket.on('unKnowError', () => {
  587. this.setData({
  588. unKnowError: true
  589. })
  590. })
  591. //被动通知开关MIC 要3秒后
  592. socket.on('serverOnMic', ({
  593. voiceStatus
  594. }) => {
  595. setTimeout(() => {
  596. if (Number(voiceStatus) === 2) {
  597. // wx.showToast({
  598. // title: '开MIC',
  599. // icon:'none'
  600. // })
  601. this.openMic();
  602. }
  603. if (Number(voiceStatus) === 0) {
  604. // wx.showToast({
  605. // title: '关MIC',
  606. // icon:'none'
  607. // })
  608. this.closeMic();
  609. }
  610. }, 3000)
  611. });
  612. this.socketStop = () => {
  613. if (socket) {
  614. socket.close()
  615. console.error('断开 并滞空 socket Room', options.roomId)
  616. this.setData({
  617. socketStatus: 2
  618. })
  619. socket = null
  620. }
  621. }
  622. return options
  623. },
  624. getUrlCode(url) {
  625. this.socketSendMessage('clientSyncAction', {
  626. sender: 'wx',
  627. type: 'wx-subscribe-result',
  628. data: 3020
  629. })
  630. // wx.request({
  631. // url: url, //仅为示例,并非真实的接口地址
  632. // method: 'get',
  633. // success: (res) => {
  634. // let code = -1
  635. // if (typeof res.data.code != 'undefined') {
  636. // code = res.data.code
  637. // }
  638. // this.socketSendMessage('clientSyncAction', {
  639. // sender: 'wx',
  640. // type: 'wx-subscribe-result',
  641. // data: code
  642. // })
  643. // },
  644. // fail: (err) => {
  645. // console.log(err)
  646. // }
  647. // })
  648. },
  649. changeRoomEnableTalk(data) {
  650. console.log(data)
  651. let noMute = getApp().globalData.voiceProps.noMute
  652. getApp().globalData.voiceProps.force = data.enableTalk
  653. // noMute true 静音
  654. // enableTalk false 静音
  655. if (!!data.enableTalk === !!noMute) {
  656. this.mic()
  657. }
  658. },
  659. navigateToGoods({
  660. data
  661. }) {
  662. // wx.showToast({
  663. // title: JSON.stringify(data).substr(40)
  664. // })
  665. this.navigateToGoodsAction(data)
  666. },
  667. navigateToGoodsAction(id) {
  668. wx.navigateTo({
  669. url: '/pages/goods/goods?id=' + id,
  670. })
  671. },
  672. getUrl(url, socketOptions, isJoin) {
  673. url += '&room_id=' + socketOptions.roomId + '&user_id=' + socketOptions.userId + '&origin=fashilong'
  674. if (isJoin) {
  675. url += '&role=' + this.role + '&shopping'
  676. } else {
  677. url += '&role=' + this.role
  678. }
  679. console.error(url)
  680. console.log(isJoin)
  681. return url
  682. },
  683. navigateToMiniProgram(data) {
  684. wx.showModal({
  685. title: '温馨提示',
  686. content: '即将跳到其他小程序,是否继续?',
  687. showCancel: true, //是否显示取消按钮
  688. cancelText: "取消", //默认是“取消”
  689. confirmText: "确定", //默认是“确定”
  690. success: function (res) {
  691. if (res.cancel) {
  692. //点击取消,wx.navigateBack
  693. } else {
  694. wx.navigateToMiniProgram(data.data)
  695. }
  696. },
  697. fail: function (res) {
  698. //接口调用失败的回调函数,wx.navigateBack
  699. },
  700. complete: function (res) {
  701. //接口调用结束的回调函数(调用成功、失败都会执行)
  702. },
  703. })
  704. },
  705. async handleSomeOneInRoom(data) {
  706. if (data && data.user) {
  707. console.log('handleSomeOneInRoom', data)
  708. this.startCall(data)
  709. }
  710. },
  711. async startCall(data) {
  712. //TODO 触发三次
  713. console.log('startCall-data', data)
  714. // if( this.role =='leader'){
  715. this.setData({
  716. shareStatus: 1
  717. })
  718. if (!data) return;
  719. this.setData({
  720. surplus: this.data.peopleCount - data.roomsPerson.length
  721. })
  722. //undefined是未授权,状态为3
  723. let voiceStatus
  724. if (!this.isAuthorizeRecord) {
  725. const unAuth = await this.authorizeRecord();
  726. if (typeof unAuth === 'undefined') {
  727. // debugger
  728. voiceStatus = 3
  729. } else {
  730. voiceStatus = Number(unAuth)
  731. }
  732. }
  733. //限制只有主持人才可以开麦
  734. // if (this.role == 'leader') {
  735. // if (!this.isAuthorizeRecord) {
  736. // const voiceStatus = Number(await this.authorizeRecord())
  737. // this.isAuthorizeRecord = true
  738. // // getApp().setVoiceProps({
  739. // // noMute: !voiceStatus
  740. // // })
  741. // // console.log(getApp().globalData.voiceProps.noMute)
  742. // // this.socketSendMessage('changeVoiceStatus', {
  743. // // status: getApp().globalData.voiceProps.noMute ? 0 : 2
  744. // // })
  745. // // this.data.socketOptions.voiceStatus = 1
  746. // // this.socketSendMessage('changeVoiceStatus', {status: noMute ? 0 : 2})
  747. // }
  748. // }
  749. const socketOptions = this.data.socketOptions
  750. getApp().globalData.roomId = socketOptions.roomId
  751. const user = data.roomsPerson.find(user => user.userId == socketOptions.userId)
  752. if (!user) {
  753. return
  754. }
  755. //屏蔽有人进来才开麦克风
  756. // if (data.roomsPerson.length <= 1) {
  757. // return
  758. // }
  759. if (user && user.userId) {
  760. this.setData({
  761. userId: user.userId
  762. })
  763. }
  764. user.noMute = getApp().globalData.voiceProps.noMute
  765. getApp().setVoiceProps({
  766. ...user,
  767. action: 'startCall'
  768. })
  769. // this.socketSendMessage('changeVoiceStatus', {
  770. // status: getApp().globalData.voiceProps.noMute ? 0 : 2
  771. // })
  772. // }
  773. },
  774. stopCall() {
  775. console.error('stopCall')
  776. this.setData({
  777. shareStatus: 0
  778. })
  779. getApp().setVoiceProps({
  780. noMute: false,
  781. action: 'stopCall'
  782. })
  783. if (this.runManager) {
  784. // this.recorderManager.stop()
  785. this.runManager = false
  786. }
  787. },
  788. handleSomeOneLeave(data) {
  789. if (data.roomsPerson.length <= 1) {
  790. // this.stopCall()
  791. }
  792. this.setData({
  793. surplus: this.data.peopleCount - data.roomsPerson.length
  794. })
  795. },
  796. //deprecated
  797. async newRoomBk(data) {
  798. if (data.roomId) return;
  799. this.stopCall()
  800. getApp().globalData.rtcParams = []
  801. getApp().globalData.pusher = ''
  802. if (this.data.join && !this.options.join) {
  803. wx.switchTab({
  804. url: '/pages/index/index',
  805. })
  806. return;
  807. }
  808. this.role = this.data.canShow ? 'leader' : 'customer'
  809. let options = await this.getSocketOptions(this.mcode)
  810. this.socketSendMessage('clientSyncAction', {
  811. type: 'newRoom',
  812. data: options
  813. })
  814. setTimeout(async () => {
  815. this.wssSuccess = false
  816. this.socketStop && this.socketStop()
  817. this.data.many = !!this.data.canShow
  818. // this.setData({
  819. // // peopleCount: this.data.many ? manyCount : 5
  820. // peopleCount: manyCount
  821. // })
  822. let base = this.base
  823. let socketOptions = await this.socketStart({
  824. options
  825. })
  826. let url = this.getUrl(base, socketOptions, false) + (this.urlPj || '')
  827. this.base = base
  828. this.setData({
  829. url,
  830. socketOptions,
  831. })
  832. this.joinUrl()
  833. this.setData({
  834. socketOptions
  835. })
  836. this.loadConponSuccess = true
  837. this.readySendCouponCtrl()
  838. }, 300)
  839. },
  840. // 真正退出房间
  841. async exitRoom() {
  842. const roomId = this.data.socketOptions.roomId;
  843. const role = this.role;
  844. const result = await util.request(api.exitRoom, {
  845. businessId: roomId
  846. }, 'POST', 'application/json');
  847. this.socketSendMessage('stopCall', {
  848. from: 2
  849. })
  850. this.stopCall();
  851. this.socketStop();
  852. if (role === 'leader') {
  853. wx.redirectTo({
  854. url: '/pages/roomManger/roomManger',
  855. });
  856. } else {
  857. wx.switchTab({
  858. url: '/pages/index/index'
  859. });
  860. }
  861. },
  862. // 一些情况下单调API退出
  863. exitRoomApi() {
  864. const roomId = this.data.socketOptions.roomId;
  865. const role = this.role;
  866. util.request(api.exitRoom, {
  867. businessId: roomId
  868. }, 'POST', 'application/json');
  869. },
  870. async exit() {
  871. // this.stopCall()
  872. getApp().globalData.rtcParams = []
  873. getApp().globalData.pusher = ''
  874. this.socketStop && this.socketStop()
  875. this.role = 'leader'
  876. let base = this.base
  877. let socketOptions = await this.socketStart({
  878. sceneId: this.mcode
  879. })
  880. let url = this.getUrl(base, socketOptions, false) + (this.urlPj || '')
  881. this.base = base
  882. wx.nextTick(() => {
  883. setTimeout(() => {
  884. this.setData({
  885. url,
  886. loadUrl: true,
  887. socketOptions,
  888. showCommodityCtrl: false,
  889. hideWebView: false,
  890. reload: true
  891. })
  892. this.joinUrl()
  893. }, 500)
  894. })
  895. },
  896. clearDebuger() {
  897. this.setData({
  898. debugerInfo: ''
  899. })
  900. },
  901. async mic({
  902. data
  903. }) {
  904. if (Number(data.user.isAllowMic) === 1) {
  905. let noMute = getApp().globalData.voiceProps.noMute
  906. // debugger
  907. // noMute true 静音
  908. // enableTalk false 静音
  909. // if (!!getApp().globalData.voiceProps.force === !!noMute)
  910. // return
  911. // if (!getApp().globalData.voiceProps.force && (!this.data.socketOptions.voiceStatus || noMute)) return;
  912. if (!this.data.socketOptions.voiceStatus) {
  913. let voiceStatus = await this.authorizeRecord()
  914. if (voiceStatus) {
  915. this.data.socketOptions.voiceStatus = 1
  916. noMute = false
  917. } else {
  918. noMute = true
  919. }
  920. } else {
  921. noMute = !noMute
  922. }
  923. getApp().globalData.voiceProps.noMute = noMute
  924. this.socketSendMessage('changeVoiceStatus', {
  925. status: noMute ? 0 : 2,
  926. user: data.user
  927. })
  928. getApp().setVoiceProps({
  929. noMute
  930. })
  931. wx.showToast({
  932. title: `已${noMute ? '关闭' : '开启'}麦克风`,
  933. })
  934. }
  935. },
  936. closeMic() {
  937. getApp().globalData.voiceProps.noMute = true
  938. this.socketSendMessage('changeVoiceStatus', {
  939. status: 0,
  940. })
  941. getApp().setVoiceProps({
  942. noMute: true
  943. })
  944. },
  945. openMic() {
  946. getApp().globalData.voiceProps.noMute = false
  947. this.socketSendMessage('changeVoiceStatus', {
  948. status: 2,
  949. })
  950. getApp().setVoiceProps({
  951. noMute: false
  952. })
  953. },
  954. callPhone() {
  955. wx.makePhoneCall({
  956. phoneNumber: this.data.contractPhone,
  957. })
  958. this.setData({
  959. showContact: false
  960. })
  961. },
  962. /**
  963. * 用户点击右上角分享
  964. */
  965. onShareAppMessage: function (res) {
  966. let {
  967. id,
  968. newPicUrl
  969. } = this.data
  970. const socketOptions = this.data.socketOptions
  971. if (res.from === 'button') {
  972. this.setData({
  973. sendShare: false
  974. })
  975. const userId = socketOptions.userId
  976. const share = {
  977. title: '【好友推荐】一起来云逛吧',
  978. imageUrl: newPicUrl,
  979. path: `/pages/webview/index?id=${id}&type=${this.data.type}&join=true&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}&inviterId=${userId}`,
  980. }
  981. console.log('分享', share);
  982. return share
  983. } else {
  984. return {
  985. imageUrl: newPicUrl,
  986. path: `/pages/webview/index?id=${id}&type=${this.data.type}&join=false&inviterId=${userId}`,
  987. }
  988. }
  989. },
  990. /**
  991. * 生命周期函数--监听页面卸载
  992. */
  993. onUnload: function () {
  994. console.log('on onUnload')
  995. // this.socketSendMessage('stopCall', {})
  996. // this.stopCall()
  997. this.socketStop && this.socketStop()
  998. getApp().globalData.pusher = ''
  999. },
  1000. cart(data) {
  1001. this.setData({
  1002. showCommodityCtrl: data.data
  1003. })
  1004. },
  1005. share() {
  1006. console.log('share-debug')
  1007. const companyName = `指房宝(杭州)科技有限公司`
  1008. const vrLink = `/pages/webview/index`
  1009. const img_url = this.data.newPicUrl || 'http://video.cgaii.com/new4dage/images/images/home_2_a.jpg'
  1010. const shareImg = img_url
  1011. this.count = this.count || 0
  1012. console.log('share-debug many:%s shareStatus: %s', !!this.data.many, this.data.shareStatus);
  1013. if (this.data.many && this.data.shareStatus == 1) {
  1014. //开启一起逛时候的分享
  1015. console.log(`share-debug: /pages/shareRoom/shareRoom?img_url=${btoa(img_url)}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}&inviterId=${this.data.userId}`)
  1016. console.log('share-debug', this.data.socketOptions)
  1017. wx.navigateTo({
  1018. url: `/pages/shareRoom/shareRoom?img_url=${btoa(img_url)}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}&roomId=${this.data.socketOptions.roomId}&many=${!!this.data.many}&inviterId=${this.data.userId}`,
  1019. })
  1020. } else {
  1021. console.log(`share-debug: /pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}`);
  1022. wx.navigateTo({
  1023. url: `/pages/shared/shared?img_url=${btoa(img_url)}&shareImg=${btoa(shareImg)}&companyName=${companyName}&vrLink=${btoa(vrLink)}&id=${this.data.id}&type=${this.data.type}`,
  1024. })
  1025. }
  1026. },
  1027. back(data) {
  1028. if (data.sender !== 'h5') return;
  1029. wx.switchTab({
  1030. url: '/pages/index/index'
  1031. })
  1032. this.setData({
  1033. showCommodityCtrl: false
  1034. })
  1035. },
  1036. service() {
  1037. this.setData({
  1038. showContact: true,
  1039. showCommodity: false,
  1040. showCoupon: false
  1041. })
  1042. },
  1043. invite(data) {
  1044. if (data.sender !== 'h5') return;
  1045. // 分享房间进入统计
  1046. if (this.data.socketOptions.roomId !== '888888') {
  1047. util.request(api.trackRoom, {
  1048. roomId: this.data.socketOptions.roomId,
  1049. type: 1,
  1050. }, 'POST', 'application/json')
  1051. }
  1052. this.setData({
  1053. sendShare: true,
  1054. count: ++this.data.count
  1055. })
  1056. },
  1057. coupon(data) {
  1058. if (data.sender !== 'h5') return;
  1059. this.setData({
  1060. showContact: false,
  1061. showCommodity: false,
  1062. showCoupon: true
  1063. })
  1064. },
  1065. liveGotoGood(ev) {
  1066. let id = ev.currentTarget.dataset.item.goodsId
  1067. wx.navigateTo({
  1068. url: '/pages/goods/goods?id=' + id,
  1069. })
  1070. },
  1071. gotoGoodsDOM(event) {
  1072. this.gotoGoods(event.currentTarget.dataset.item.hotIdList[0])
  1073. },
  1074. gotoGoodsSocket(data) {
  1075. this.gotoGoods(data.data)
  1076. },
  1077. gotoGoods(id) {
  1078. console.log('---', id)
  1079. this.socketSendMessage('clientSyncAction', {
  1080. type: 'openTag',
  1081. data: id
  1082. })
  1083. this.setData({
  1084. showCommodity: false
  1085. })
  1086. this.joinUrl()
  1087. },
  1088. addCard(event) {
  1089. wx.navigateTo({
  1090. url: '/pages/goods/goods?id=' + event.currentTarget.dataset.id + '&oper=addCard',
  1091. })
  1092. },
  1093. buyGoods(event) {
  1094. wx.navigateTo({
  1095. url: '/pages/goods/goods?id=' + event.currentTarget.dataset.id + '&oper=buyGoods',
  1096. })
  1097. },
  1098. showCommodityFn() {
  1099. this.setData({
  1100. showCommodity: true,
  1101. showContact: false,
  1102. showCoupon: false
  1103. })
  1104. this.joinUrl()
  1105. },
  1106. hideComodity() {
  1107. this.setData({
  1108. showCommodity: false
  1109. })
  1110. this.joinUrl()
  1111. },
  1112. hideCoupon() {
  1113. this.setData({
  1114. showCoupon: !this.data.showCoupon
  1115. })
  1116. },
  1117. async receive(ev) {
  1118. let item = ev.target.dataset.item
  1119. try {
  1120. // wx.showToast({
  1121. // title: '领取优惠卷',
  1122. // })
  1123. // return;
  1124. if (item.hasReceived || item.number <= item.receiveNumber) return;
  1125. let res = await util.request(api.CouponExchange, {
  1126. couponId: item.id
  1127. })
  1128. if (res.code === 0) {
  1129. wx.showToast({
  1130. title: '已成功领取',
  1131. success: () => {
  1132. this.setData({
  1133. showCoupon: false
  1134. })
  1135. wx.nextTick(() => {
  1136. this.setData({
  1137. coupons: this.data.coupons.map(citem => {
  1138. return {
  1139. ...citem,
  1140. hasReceived: citem.id === item.id ? true : citem.hasReceived
  1141. }
  1142. }),
  1143. showCoupon: true
  1144. })
  1145. })
  1146. }
  1147. })
  1148. } else if (res.errno === 401) {
  1149. getApp().setLoginProps(false)
  1150. } else {
  1151. wx.showToast({
  1152. title: res.msg,
  1153. })
  1154. }
  1155. } catch (e) {
  1156. console.error(e)
  1157. wx.showToast({
  1158. icon: 'none',
  1159. title: '领取失败',
  1160. })
  1161. }
  1162. },
  1163. async getCouponList(id) {
  1164. const success = (res) => {
  1165. this.setData({
  1166. coupons: res.data.list.map(item => {
  1167. item.typeMoney = item.typeMoney.toString()
  1168. item.fontSize = item.typeMoney.length === 3 ? '90rpx' :
  1169. item.typeMoney.length === 4 ? '70rpx' : '130rpx'
  1170. return item
  1171. })
  1172. })
  1173. this.loadConponSuccess = true
  1174. this.readySendCouponCtrl()
  1175. }
  1176. let res = await util.request(api.BrandCouponList, {
  1177. brandId: id,
  1178. pageNum: 1,
  1179. pageSize: 10000
  1180. }, 'GET')
  1181. console.log(res)
  1182. if (res.code === 0) {
  1183. success(res)
  1184. } else {
  1185. let res = await util.request(api.UNBrandCouponList, {
  1186. brandId: id,
  1187. pageNum: 1,
  1188. pageSize: 10000
  1189. }, 'GET')
  1190. success(res)
  1191. }
  1192. },
  1193. ready() {
  1194. this.wssSuccess = true
  1195. this.readySendCouponCtrl()
  1196. },
  1197. readySendCouponCtrl() {
  1198. if (this.wssSuccess && this.loadConponSuccess) {
  1199. this.loadConponSuccess = false
  1200. this.socketSendMessage('clientSyncAction', {
  1201. type: 'showCoupon',
  1202. data: this.data.coupons.length > 0
  1203. })
  1204. }
  1205. },
  1206. getBrand: function (id, code) {
  1207. this.getGoodsCount(code, id)
  1208. return;
  1209. },
  1210. getGoodsCount(code, id) {
  1211. util.request(api.GoodsNumCount, {
  1212. isDelete: 0,
  1213. isOnSale: 1,
  1214. brandId: id
  1215. }, 'GET')
  1216. .then(res => {
  1217. if (res.errno === 0) {
  1218. this.setData({
  1219. goodsCount: res.data
  1220. })
  1221. }
  1222. this.getCouponList(id)
  1223. })
  1224. },
  1225. getGoodsList(id, category_id) {
  1226. var that = this;
  1227. if (!(this.data.navList && this.data.navList.length)) {
  1228. that.navDatas = {}
  1229. let navDatas = this.data.navList = this.data.comtypes
  1230. // util.request(api.GoodsCategory, { id: category_id })
  1231. // .then(function (res) {
  1232. // if (res.errno == 0) {
  1233. // let navDatas = res.data.brotherCategory
  1234. // that.setData({
  1235. // navList: navDatas,
  1236. // currTypeId: category_id
  1237. // });
  1238. that.navDatas = {}
  1239. navDatas.forEach(item => {
  1240. util.request(api.GoodsList, {
  1241. brandId: id,
  1242. categoryId: item.category_id,
  1243. page: that.data.page,
  1244. size: that.data.size
  1245. })
  1246. .then(res => {
  1247. if (res.errno === 0) {
  1248. that.navDatas[item.category_id] = res.data.goodsList
  1249. }
  1250. })
  1251. })
  1252. // }
  1253. // })
  1254. }
  1255. if (that.navDatas[category_id]) {
  1256. if (!isIos) {
  1257. let showCommodity = that.data.showCommodity
  1258. that.setData({
  1259. showCommodity: false
  1260. })
  1261. setTimeout(() => {
  1262. wx.nextTick(() => {
  1263. that.setData({
  1264. goodsList: that.navDatas[category_id],
  1265. currTypeId: category_id,
  1266. showCommodity: showCommodity
  1267. });
  1268. })
  1269. }, 500)
  1270. } else {
  1271. that.setData({
  1272. goodsList: that.navDatas[category_id],
  1273. currTypeId: category_id,
  1274. });
  1275. }
  1276. } else {
  1277. console.error('诱惑去啦')
  1278. util.request(api.GoodsList, {
  1279. brandId: id,
  1280. categoryId: category_id,
  1281. page: that.data.page,
  1282. size: that.data.size
  1283. })
  1284. .then(function (res) {
  1285. if (res.errno === 0) {
  1286. that.setData({
  1287. goodsList: res.data.goodsList,
  1288. currTypeId: category_id
  1289. });
  1290. // this.data.navList
  1291. }
  1292. });
  1293. }
  1294. },
  1295. getBrandDetail: function (id, type, cb) {
  1296. console.log('getBrandDetail-params', id, type)
  1297. util.request(api.BrandDetail, {
  1298. id: id,
  1299. type: type,
  1300. }).then((res) => {
  1301. console.log('getBrandDetail', res)
  1302. let base = res.data.brand.sceneUrl
  1303. // let base = 'http://192.168.0.112:8080/shop.html?m=t-7Uqj9Fq&origin=fashilong'
  1304. if (res.errno === 0) {
  1305. let url = base + "&sid=" + id
  1306. // debugger
  1307. this.setData({
  1308. id: id,
  1309. newPicUrl: res.data.brand.appListPicUrl,
  1310. sceneNum: res.data.brand.sceneNum,
  1311. canShow: res.data.brand.canShow,
  1312. contractPhone: res.data.brand.contractPhone,
  1313. contactInfo: {
  1314. contactPhone: res.data.brand.contactPhone || '',
  1315. contactHead: res.data.brand.contactHead || '',
  1316. contactCompanyName: res.data.brand.contactCompanyName || '',
  1317. contactNickName: res.data.brand.contactNickName || '',
  1318. brands: res.data.brand.brands || []
  1319. }
  1320. })
  1321. if (this.data.many === void 0) {
  1322. this.data.many = !!res.data.brand.canShow
  1323. }
  1324. this.setData({
  1325. // peopleCount: this.data.many ? manyCount : 5,
  1326. peopleCount: manyCount
  1327. })
  1328. if (!res.data.brand.canShow) {
  1329. this.role = 'customer'
  1330. } else if (!this.options.join) {
  1331. this.role = 'leader'
  1332. }
  1333. cb(url, urlToJson(url).m, )
  1334. }
  1335. });
  1336. },
  1337. sendContactInfo() {
  1338. // this.socketSendMessage('getContactInfo', {
  1339. // contactInfo: this.data.contactInfo,
  1340. // })
  1341. this.socketSendMessage('clientSyncAction', {
  1342. type: 'getContactInfo',
  1343. contactInfo: this.data.contactInfo
  1344. })
  1345. },
  1346. goToCase({
  1347. data
  1348. }) {
  1349. console.log('data', data)
  1350. wx.showModal({
  1351. title: '提示',
  1352. content: `是否跳转到新的场景?`,
  1353. showCancel: true,
  1354. confirmColor: "#52a2d8",
  1355. success: res => {
  1356. if (res.confirm) {
  1357. wx.navigateTo({
  1358. url: `/pages/webview/index?id=${data.id}&type=32`,
  1359. })
  1360. }
  1361. },
  1362. fail: () => {
  1363. }
  1364. })
  1365. },
  1366. selectType(ev) {
  1367. this.getGoodsList(this.options.id, ev.target.dataset.item.category_id)
  1368. },
  1369. hideCS() {
  1370. this.setData({
  1371. showCommodity: false,
  1372. showCoupon: false,
  1373. showContact: false
  1374. })
  1375. },
  1376. hideContact() {
  1377. this.setData({
  1378. showContact: false
  1379. })
  1380. },
  1381. calcShare() {
  1382. // this.exit()
  1383. this.setData({
  1384. sendShare: false
  1385. })
  1386. },
  1387. contactKf() {
  1388. let keys = Object.keys(this.navDatas)
  1389. let goodsId = this.navDatas[keys[0]][0].id
  1390. let user = wx.getStorageSync('userinfoDetail')
  1391. util.request(api.AddTalkCount, {
  1392. goodsId,
  1393. viewId: user && user.userId || '',
  1394. sceneNum: this.data.sceneNum
  1395. }, 'get')
  1396. this.hideAlert && this.hideAlert()
  1397. this.hideContact && this.hideContact()
  1398. },
  1399. onHide() {
  1400. this.socketSendMessage('changeOnlineStatus', {
  1401. status: 0
  1402. })
  1403. this.pauseVideo = true
  1404. this.joinUrl()
  1405. }
  1406. }