socket.js 39 KB

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