liveDetail.nvue 11 KB

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