liveDetail.nvue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. :showFav="true" :isFav="isLiveFav" @onLiveFav=""
  9. :showSwitch="false" :showBeauty="false" :showLike="false" :btns="btns" @onBtnClick="onBtnClick"
  10. :showIm="true" :imStatus="imStatus" :imMsgs="imMsgs" @onImSend="onImSend" />
  11. <uni-popup ref="popup" animation type="bottom">
  12. <view class="popup-box">
  13. <view class="popup-close">
  14. <text class="popup-close-text" @click="$refs.popup.close()">收起</text>
  15. </view>
  16. <scroll-view scroll-y="true" class="good-box">
  17. <view class="goods-row" v-for="(item, index) in goodsList" :key="index" @click="goToGoodDetails(item)">
  18. <view class="goods-img-box">
  19. <image class="goods-img" :src="item.imgPath" mode="aspectFill"></image>
  20. </view>
  21. <view class="goods-info">
  22. <view>
  23. <text class="goods-name">{{item.productName}}</text>
  24. </view>
  25. <text class="goods-sales">{{item.sellCount}}人付款</text>
  26. <text class="price">原价:{{item.originalPrice}}</text>
  27. <view class="goods-number-bottom">
  28. <view class="goods-number">
  29. <!-- <text class="goods-number-left">惊爆价:</text> -->
  30. <text class="goods-icon">¥</text>
  31. <text class="goods-spec">{{item.bizPrice}}</text>
  32. </view>
  33. <view class="more-button">
  34. <!-- #ifdef APP-PLUS -->
  35. <text class="nvue-iconfont more-button-iconfont" :style="{fontFamily:'nvueIconfont'}">&#xe623;</text>
  36. <!-- #endif -->
  37. <!-- #ifdef MP-WEIXIN -->
  38. <text class="iconfont more-button-iconfont icongengduo"></text>
  39. <!-- #endif -->
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. </view>
  46. </uni-popup>
  47. </view>
  48. </template>
  49. <script>
  50. import jhlive from "@/jhlive/jhlive";
  51. import Jhim from "@/jhim/jhim.js";
  52. const NET = require('@/utils/request');
  53. const API = require('@/config/api');
  54. export default {
  55. components: {
  56. jhlive
  57. },
  58. data() {
  59. return {
  60. windowWidth: 0,
  61. windowHeight: 0,
  62. liveId: '',
  63. userData: {},
  64. videoUrl: '',
  65. goodsList: [],
  66. goodsIds: [],
  67. btns: [{picture:"../static/images/live-good.png",title:''}],
  68. isAuthor: false,
  69. linkMic: false,
  70. sdkAppID: API.sdkAppID,
  71. secretKey: API.secretKey,
  72. userId: '',
  73. userName: '',
  74. roomId: '',
  75. avatar: "../static/images/loginLogo.png",
  76. title: "加载中",
  77. subtitle: "0人在观看",
  78. isLiveFav: false,
  79. imStatus: '',
  80. imMsgs: [],
  81. }
  82. },
  83. onLoad(options) {
  84. this.roomId = options.roomId;
  85. this.liveId = options.liveId;
  86. this.videoUrl = uni.getStorageSync("videoUrl").replace("http://", "https://");
  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. onReady() {
  95. this.isAuthor = false;
  96. this.linkMic = true;
  97. this.userId = "22";
  98. this.userName = "ss";
  99. this.title = 'test';
  100. this.roomId = '11';
  101. this.$nextTick(() => this.enterRoom());
  102. return;
  103. this.init();
  104. },
  105. onUnload() {
  106. this.exitRoom();
  107. },
  108. methods: {
  109. init() {
  110. NET.request(API.getLiveGoodsDetail + options.liveId, {}, 'GET').then(res => {
  111. this.goodsList = res.data
  112. }).catch(res => {
  113. uni.showToast({
  114. title: '获取商品列表失败',
  115. type: 'warning',
  116. })
  117. })
  118. this.avatar = uni.getStorageSync("liveImgUrl");
  119. this.title = uni.getStorageSync("liveName");
  120. this.$nextTick(() => this.enterRoom());
  121. },
  122. enterRoom() {
  123. this.jhim = Jhim.getInstance(this.userId, this.sdkAppID, this.secretKey);
  124. this.jhim.login(this.userName, this.avatar).then(()=>{
  125. this.jhimgroup = this.jhim.createGroup(this.roomId);
  126. this.jhimgroup
  127. .on(this.onImText, this.jhim.TYPES.MSG_TEXT)
  128. .on(this.onImCustomMessage, this.jhim.TYPES.MSG_CUSTOM)
  129. .on(this.onImGroupTip, this.jhim.TYPES.MSG_GRP_TIP)
  130. .onReady(this.onImGroupReady)
  131. .join(this.isAuthor)
  132. })
  133. this.$refs.jhlive && this.$refs.jhlive.enterRoom();
  134. },
  135. onImText(e) {
  136. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  137. type: 'text',
  138. name: v.nick,
  139. text: v.payload.text
  140. }))];
  141. },
  142. onImCustomMessage() {
  143. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  144. type: v.payload.description,
  145. text: v.payload.data
  146. }))];
  147. },
  148. onImGroupTip(e) {
  149. this.subtitle = e[0].payload.userIDList.length + '人在观看';
  150. },
  151. onImGroupReady(e) {
  152. this.imStatus = e?'':'登录中...';
  153. },
  154. onImSend(text) {
  155. this.jhimgroup.sendText(text).then(msg => {
  156. this.imMsgs.push({
  157. type: 'text',
  158. name: msg.nick,
  159. text: msg.payload.text
  160. });
  161. this.$refs.jhlive && this.$refs.jhlive.cleanImInput();
  162. });
  163. },
  164. onLiveFav(isFav) {
  165. },
  166. exitRoom() {
  167. this.jhimgroup.off(this.onImText);
  168. this.jhimgroup.off(this.onImCustomMessage);
  169. this.jhimgroup.off(this.onImGroupTip);
  170. this.jhimgroup.offReady(this.onImGroupReady);
  171. this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout());
  172. this.$refs.jhlive && this.$refs.jhlive.exitRoom();
  173. },
  174. onBtnClick(index, item) {
  175. if(index === 0) {
  176. this.$refs.popup.open()
  177. }
  178. },
  179. goToGoodDetails(item) {
  180. uni.navigateTo({
  181. url: '/pagesGood/goodDetails?goodId=' + item.productId
  182. });
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="less" scoped>
  188. .container {
  189. position: relative;
  190. display: flex;
  191. flex-direction: column;
  192. align-items: stretch;
  193. width: 750rpx;
  194. }
  195. .jhlive {
  196. width: 750rpx;
  197. flex: 1;
  198. }
  199. .jhimlive {
  200. width: 400rpx;
  201. position: absolute;
  202. bottom: 10px;
  203. left: 10px;
  204. }
  205. .popup-open {
  206. width: 50px;
  207. height: 50px;
  208. position: fixed;
  209. bottom: 15px;
  210. right: 15px;
  211. background-color: #52A63A;
  212. border-radius: 50%;
  213. text-align: center;
  214. line-height: 50px;
  215. }
  216. .iconzhibo-shangpin {
  217. color: #FFFFFF;
  218. font-size: 34px;
  219. text-align: center;
  220. line-height: 50px;
  221. }
  222. .popup-box {
  223. background-color: #FFFFFF;
  224. width: 750rpx;
  225. height: 750rpx;
  226. border-top-left-radius: 10px;
  227. border-top-right-radius: 10px;
  228. }
  229. .popup-close {
  230. padding: 10px;
  231. line-height: 16px;
  232. }
  233. .popup-close-text {
  234. color: #52A63A;
  235. font-size: 15px;
  236. font-family: PingFang SC;
  237. text-align: left;
  238. }
  239. .good-box {
  240. width: 750rpx;
  241. height: 230px;
  242. padding: 0 0 10px 0;
  243. overflow: visible;
  244. }
  245. .goods-row:first-child {
  246. margin-top: 12px;
  247. }
  248. .goods-row {
  249. width: 700rpx;
  250. height: 104px;
  251. display: flex;
  252. flex-direction: row;
  253. flex-wrap: nowrap;
  254. background-color: #FFFFFF;
  255. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  256. border-radius: 5px;
  257. margin: 0 15px 10px 15px;
  258. }
  259. .goods-img-box {
  260. margin-right: 15px;
  261. }
  262. .goods-img {
  263. width: 104px;
  264. height: 104px;
  265. object-fit: cover;
  266. }
  267. .goods-info {
  268. flex: 1;
  269. padding-top: 10px;
  270. }
  271. .goods-name {
  272. line-height: 15px;
  273. overflow: hidden;
  274. display: -webkit-box;
  275. -webkit-line-clamp: 2;
  276. -webkit-box-orient: vertical;
  277. word-wrap: break-word;
  278. text-overflow: ellipsis;
  279. font-size: 15px;
  280. font-family: PingFang SC;
  281. color: #333333;
  282. }
  283. .goods-sales {
  284. font-size: 12px;
  285. font-family: PingFang SC;
  286. color: #666666;
  287. line-height: 15px;
  288. margin: 8px 0 8px 0;
  289. }
  290. .price {
  291. font-size: 12px;
  292. text-decoration: line-through;
  293. color: #A67954;
  294. }
  295. .goods-number-bottom {
  296. display: flex;
  297. flex-direction: row;
  298. }
  299. .goods-number {
  300. display: flex;
  301. flex-direction: row;
  302. white-space: nowrap;
  303. line-height: 24px;
  304. }
  305. .goods-number-left {
  306. font-size: 12px;
  307. color: #666666;
  308. }
  309. .goods-icon {
  310. font-size: 14px;
  311. font-family: PingFang SC;
  312. color: #52A63A;
  313. }
  314. .goods-spec {
  315. font-size: 24px;
  316. font-family: PingFang SC;
  317. color: #52A63A;
  318. }
  319. .more-button {
  320. width: 24px;
  321. height: 24px;
  322. position: absolute;
  323. right: 16px;
  324. }
  325. .more-button-iconfont {
  326. font-size: 36px;
  327. color: #999999;
  328. text-align: center;
  329. }
  330. </style>