liveDetail.nvue 10 KB

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