liveDetail.nvue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view class="container" :style="'height: '+windowHeight+'px;'">
  3. <jhlive
  4. ref="jhlive" class="jhlive"
  5. :sdkAppID="sdkAppID" :secretKey="secretKey" :userId="userId" :roomId="roomId"
  6. :isAuthor="isAuthor" :linkMic="linkMic"
  7. :avatar="avatar" :subtitle="subtitle" :title="title"
  8. :showSwitch="true" :showBeauty="true" :btns="btns" @onBtnClick="onBtnClick"
  9. :showIm="true" :imStatus="imStatus" :imMsgs="imMsgs" @onImSend="onImSend" />
  10. <uni-popup ref="popup" animation type="bottom">
  11. <view class="popup-box">
  12. <view class="popup-close">
  13. <text class="popup-close-text" @click="$refs.popup.close()">收起</text>
  14. <text class="popup-close-text" @click="bindGood">绑定</text>
  15. </view>
  16. <scroll-view v-if="true" scroll-y="true" class="good-box2">
  17. <view class="goods-row2" v-for="(item, index) in goodsList" :key="index">
  18. <view class="good-check">
  19. <view @click="checkGoods(item)">
  20. <!-- #ifdef MP-WEIXIN -->
  21. <text class="iconfont good-check-iconfont" :class="item.check ? 'iconqueding' : 'iconfeigouxuan'" ></text>
  22. <!-- #endif -->
  23. <!-- #ifdef APP-PLUS -->
  24. <text class="nvue-iconfont good-check-iconfont" :style="{fontFamily:'nvueIconfont'}">{{item.check ? '&#xe626;' : '&#xe646;'}}</text>
  25. <!-- #endif -->
  26. </view>
  27. </view>
  28. <view class="good-card2">
  29. <view class="goods-img-box2">
  30. <image class="goods-img2" :src="item.imgPath" mode="aspectFill"></image>
  31. </view>
  32. <view class="goods-info2">
  33. <view>
  34. <text class="goods-name2">{{item.productName}}</text>
  35. </view>
  36. <text class="goods-sales2">销量:{{item.sellCount}}</text>
  37. <text class="price2">原价:{{item.originalPrice}}</text>
  38. <view class="goods-number2">
  39. <text class="goods-icon2">¥</text>
  40. <text class="goods-icon2">{{item.bizPrice}}/{{item.unit}}</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </uni-popup>
  48. <u-top-tips ref="uTips"></u-top-tips>
  49. </view>
  50. </template>
  51. <script>
  52. import jhlive from "@/jhlive/jhlive";
  53. import Jhim from "@/jhim/jhim.js";
  54. import permision from "@/utils/permission.js";
  55. const NET = require('@/utils/request')
  56. const API = require('@/config/api')
  57. export default {
  58. components: {
  59. jhlive,
  60. },
  61. data() {
  62. return {
  63. windowWidth: 0,
  64. windowHeight: 0,
  65. liveId: '',
  66. userData: {},
  67. videoUrl: '',
  68. goodsList: [],
  69. goodsIds: [],
  70. btns: [{picture:"../static/images/live-good.png",title:''}],
  71. isAuthor: true,
  72. linkMic: false,
  73. sdkAppID: API.sdkAppID,
  74. secretKey: API.secretKey,
  75. userId: '',
  76. userName: '',
  77. roomId: '',
  78. avatar: "../static/images/loginLogo.png",
  79. title: "加载中",
  80. subtitle: "0人在观看",
  81. isLiveFav: false,
  82. imStatus: '',
  83. imMsgs: [],
  84. }
  85. },
  86. onLoad(options) {
  87. this.liveId = options.liveId
  88. this.userData = uni.getStorageSync("userData");
  89. this.userId = this.userData.userId;
  90. this.userName = this.userData.userName;
  91. let info = uni.getSystemInfoSync();
  92. this.windowWidth = info.windowWidth;
  93. this.windowHeight = info.windowHeight;
  94. // 假数据
  95. // this.goodsList.push({
  96. // productId: 1336146105292816384,
  97. // tenantCode: null,
  98. // imgPath: 'https: //www.qianjiadi.com:443/file/2020/12/2af4eb48-35c4-4aa7-80c9-ab7a7cb49984.jpg',
  99. // productName: '测试拍卖商品zxw111',
  100. // sellCount: 0,
  101. // owner: 1,
  102. // productType: 2,
  103. // originalPrice: 1.00,
  104. // bizPrice: 0.01,
  105. // unit: '个'
  106. // },{
  107. // productId: 1336146105292816386,
  108. // tenantCode: null,
  109. // imgPath: 'https: //www.qianjiadi.com:443/file/2020/12/2af4eb48-35c4-4aa7-80c9-ab7a7cb49984.jpg',
  110. // productName: '测试拍卖商品zxw222',
  111. // sellCount: 0,
  112. // owner: 1,
  113. // productType: 2,
  114. // originalPrice: 1.00,
  115. // bizPrice: 0.01,
  116. // unit: '个'
  117. // })
  118. this.goodsIds = this.goodsList.map(site => {
  119. return site.productId
  120. }).join(',')
  121. this.goodsList.forEach(site => {
  122. site.check = this.goodsIds.indexOf(site.productId) != -1
  123. })
  124. },
  125. onReady() {
  126. // this.isAuthor = true;
  127. // this.linkMic = false;
  128. // this.userId = "123";
  129. // this.name = 'test';
  130. // this.roomId = '1';
  131. // this.$nextTick(() => this.enterRoom());
  132. // return;
  133. this.init();
  134. },
  135. // #ifdef APP-PLUS
  136. beforeCreate() {
  137. let domModule = weex.requireModule('dom');
  138. domModule.addRule('fontFace',{
  139. 'fontFamily': "nvueIconfont",
  140. 'src': "url('https://at.alicdn.com/t/font_2119167_43jbldmjpr3.ttf')"
  141. })
  142. },
  143. // #endif
  144. onUnload() {
  145. this.exitRoom();
  146. },
  147. methods: {
  148. init() {
  149. NET.request(API.startStream + 2, 'GET').then(res => {
  150. this.avatar = res.data.imgUrl;
  151. this.title = res.data.liveName;
  152. this.roomId = String(res.data.roomId);
  153. this.$nextTick(() => {
  154. permision.checkAndRequestPermissions(['scope.camera', 'scope.record']).then(()=>{
  155. this.enterRoom();
  156. }, ()=>{
  157. uni.showToast({
  158. title: '获取权限失败',
  159. duration: 2000,
  160. })
  161. })
  162. });
  163. }).catch(res => {
  164. uni.showToast({
  165. title: error.data.msg,
  166. duration: 2000
  167. });
  168. })
  169. },
  170. enterRoom() {
  171. this.jhim = Jhim.getInstance(this.userId, this.sdkAppID, this.secretKey);
  172. this.jhim.login(this.userName, this.avatar).then(()=>{
  173. this.jhimgroup = this.jhim.createGroup(this.roomId);
  174. this.jhimgroup
  175. .on(this.onImText, this.jhim.TYPES.MSG_TEXT)
  176. .on(this.onImCustomMessage, this.jhim.TYPES.MSG_CUSTOM)
  177. .on(this.onImGroupTip, this.jhim.TYPES.MSG_GRP_TIP)
  178. .onReady(this.onImGroupReady)
  179. .join(this.isAuthor)
  180. })
  181. this.$refs.jhlive && this.$refs.jhlive.enterRoom();
  182. },
  183. onImText(e) {
  184. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  185. type: 'text',
  186. name: v.nick,
  187. text: v.payload.text
  188. }))];
  189. },
  190. onImCustomMessage() {
  191. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  192. type: v.payload.description,
  193. text: v.payload.data
  194. }))];
  195. },
  196. onImGroupTip(e) {
  197. this.jhimgroup.getProfile().then(v=>{
  198. this.subtitle = v.memberCount + '人在观看';
  199. });
  200. },
  201. onImGroupReady(e) {
  202. this.imStatus = e?'':'登录中...';
  203. },
  204. onImSend(text) {
  205. this.jhimgroup.sendText(text).then(msg => {
  206. this.imMsgs.push({
  207. type: 'text',
  208. name: msg.nick,
  209. text: msg.payload.text
  210. });
  211. this.$refs.jhlive && this.$refs.jhlive.cleanImInput();
  212. });
  213. },
  214. exitRoom() {
  215. this.jhimgroup.off(this.onImText);
  216. this.jhimgroup.off(this.onImCustomMessage);
  217. this.jhimgroup.off(this.onImGroupTip);
  218. this.jhimgroup.offReady(this.onImGroupReady);
  219. this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout().then(()=>this.jhim.destroy()));
  220. this.$refs.jhlive && this.$refs.jhlive.exitRoom();
  221. NET.request(API.creatLive, {
  222. liveId: this.liveId,
  223. liveStatus: 2
  224. }, 'GET').then(res => {}).catch(res => {
  225. this.$refs.uTips.show({
  226. title: '关闭直播失败',
  227. type: 'warning',
  228. })
  229. })
  230. },
  231. onBtnClick(index, item) {
  232. if(index === 0) {
  233. this.$refs.popup.open()
  234. // 打开弹窗
  235. NET.request(API.getBindedLiveGoods, {
  236. liveId: this.liveId
  237. }, 'GET').then(res => {
  238. let goodsIds = res.data.map(site => {
  239. return site.productId
  240. }).join(',')
  241. this.getAllGoods(goodsIds)
  242. }).catch(res => {
  243. this.$refs.uTips.show({
  244. title: '获取已绑定商品失败',
  245. type: 'warning',
  246. })
  247. })
  248. }
  249. },
  250. // 获取可绑定商品
  251. getAllGoods(goodsIds) {
  252. NET.request(API.getVideoGoods, {}, 'GET').then(res => {
  253. res.data.forEach(site => {
  254. site.check = goodsIds.indexOf(site.productId) != -1
  255. })
  256. this.goodsList = res.data
  257. }).catch(res => {
  258. this.$refs.uTips.show({
  259. title: '获取商品失败',
  260. type: 'warning',
  261. })
  262. })
  263. },
  264. // 绑定商品
  265. bindGood() {
  266. NET.request(API.bindLiveGoods, {
  267. liveId: this.liveId,
  268. prudoctIds: this.goodsList.filter(site => site.check).map(site => {
  269. return site.productId
  270. })
  271. }, 'POST').then(res => {
  272. this.$refs.popup.close()
  273. this.$refs.uTips.show({
  274. title: '设置成功',
  275. type: 'success',
  276. })
  277. }).catch(res => {
  278. this.$refs.uTips.show({
  279. title: '设置失败',
  280. type: 'warning',
  281. })
  282. })
  283. },
  284. // 勾选商品
  285. checkGoods(site) {
  286. console.log(site)
  287. site.check = !site.check
  288. }
  289. },
  290. }
  291. </script>
  292. <style>
  293. .nvue-iconfont {
  294. font-family: "nvueIconfont";
  295. font-size: 16px;
  296. font-style: normal;
  297. -webkit-font-smoothing: antialiased;
  298. -moz-osx-font-smoothing: grayscale;
  299. }
  300. </style>
  301. <style lang="less" scoped>
  302. .container {
  303. position: relative;
  304. display: flex;
  305. flex-direction: column;
  306. align-items: stretch;
  307. width: 750rpx;
  308. }
  309. .jhlive {
  310. width: 750rpx;
  311. flex: 1;
  312. }
  313. .jhimlive {
  314. width: 400rpx;
  315. position: absolute;
  316. bottom: 10px;
  317. left: 10px;
  318. // background-color: blue;
  319. }
  320. .popup-open {
  321. width: 50px;
  322. height: 50px;
  323. position: fixed;
  324. bottom: 15px;
  325. right: 15px;
  326. background-color: #52A63A;
  327. border-radius: 50%;
  328. text-align: center;
  329. line-height: 50px;
  330. }
  331. .iconzhibo-shangpin {
  332. color: #FFFFFF;
  333. font-size: 34px;
  334. }
  335. .popup-box {
  336. background-color: #FFFFFF;
  337. width: 750rpx;
  338. height: 750rpx;
  339. // border-radius: 10px 10px 0 0;
  340. border-top-left-radius:10px;
  341. border-top-right-radius: 10px;
  342. }
  343. .popup-close {
  344. padding: 10px;
  345. line-height: 16px;
  346. display: flex;
  347. flex-direction: row;
  348. justify-content: space-between;
  349. }
  350. .popup-close-text{
  351. color: #52A63A;
  352. font-size: 15px;
  353. font-family: PingFang SC;
  354. }
  355. .good-check {
  356. width: 30px;
  357. height: 114px;
  358. line-height: 114px;
  359. margin-right: 10px;
  360. }
  361. .good-check-iconfont {
  362. font-size: 40px;
  363. text-align: center;
  364. color: #51A539;
  365. line-height: 114px;
  366. }
  367. .good-box2 {
  368. width: 750rpx;
  369. height: 750rpx;
  370. padding: 0 0 10px 0;
  371. overflow: visible;
  372. }
  373. .goods-row2:first-child {
  374. margin-top: 12px;
  375. }
  376. .goods-row2 {
  377. width: 700rpx;
  378. height: 114px;
  379. display: flex;
  380. flex-direction: row;
  381. flex-wrap: nowrap;
  382. background-color: #FFFFFF;
  383. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  384. border-radius: 5px;
  385. margin: 0 15px 10px 15px;
  386. }
  387. .good-card2 {
  388. display: flex;
  389. flex-direction: row;
  390. flex-wrap: nowrap;
  391. }
  392. .goods-img-box2 {
  393. margin-right: 15px;
  394. }
  395. .goods-img2 {
  396. width: 114px;
  397. height: 114px;
  398. object-fit: cover;
  399. }
  400. .goods-info2 {
  401. width: 180px;
  402. flex: 1;
  403. padding-top: 10px;
  404. }
  405. .goods-name2 {
  406. line-height: 15px;
  407. overflow: hidden;
  408. display: -webkit-box;
  409. -webkit-line-clamp: 2;
  410. -webkit-box-orient: vertical;
  411. word-wrap: break-word;
  412. text-overflow: ellipsis;
  413. font-size: 15px;
  414. font-family: PingFang SC;
  415. color: #333333;
  416. }
  417. .goods-sales2 {
  418. font-size: 12px;
  419. font-family: PingFang SC;
  420. color: #666666;
  421. line-height: 15px;
  422. margin: 8px 0 8px 0;
  423. }
  424. .price2 {
  425. font-size: 12px;
  426. text-decoration: line-through;
  427. color: #A67954;
  428. }
  429. .goods-number-bottom2 {
  430. display: flex;
  431. flex-direction: row;
  432. }
  433. .goods-number2 {
  434. display: flex;
  435. flex-direction: row;
  436. white-space: nowrap;
  437. line-height: 24px;
  438. }
  439. .goods-number-left2 {
  440. font-size: 12px;
  441. color: #666666;
  442. }
  443. .goods-icon2 {
  444. font-size: 14px;
  445. font-family: PingFang SC;
  446. color: #52A63A;
  447. }
  448. .goods-spec2 {
  449. font-size: 24px;
  450. font-family: PingFang SC;
  451. color: #52A63A;
  452. }
  453. </style>