liveDetail.nvue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. :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. beforeCreate() {
  106. let domModule = weex.requireModule('dom');
  107. domModule.addRule('fontFace',{
  108. 'fontFamily': "nvueIconfont",
  109. 'src': "url('https://at.alicdn.com/t/font_2119167_43jbldmjpr3.ttf')"
  110. })
  111. },
  112. onUnload() {
  113. this.exitRoom();
  114. },
  115. methods: {
  116. init() {
  117. NET.request(API.getLiveGoodsDetail + this.liveId, {}, 'GET').then(res => {
  118. this.goodsList = res.data
  119. }).catch(res => {
  120. uni.showToast({
  121. title: '获取商品列表失败',
  122. type: 'warning',
  123. })
  124. })
  125. this.avatar = uni.getStorageSync("liveImgUrl");
  126. this.title = uni.getStorageSync("liveName");
  127. this.$nextTick(() => this.enterRoom());
  128. },
  129. enterRoom() {
  130. this.jhim = Jhim.getInstance(this.userId, this.sdkAppID, this.secretKey);
  131. this.jhim.login(this.userName, this.avatar).then(()=>{
  132. this.jhimgroup = this.jhim.createGroup(this.roomId);
  133. this.jhimgroup
  134. .on(this.onImText, this.jhim.TYPES.MSG_TEXT)
  135. .on(this.onImCustomMessage, this.jhim.TYPES.MSG_CUSTOM)
  136. .on(this.onImGroupTip, this.jhim.TYPES.MSG_GRP_TIP)
  137. .onReady(this.onImGroupReady)
  138. .join(this.isAuthor)
  139. })
  140. this.$refs.jhlive && this.$refs.jhlive.enterRoom();
  141. },
  142. onImText(e) {
  143. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  144. type: 'text',
  145. name: v.nick,
  146. text: v.payload.text
  147. }))];
  148. },
  149. onImCustomMessage() {
  150. this.imMsgs = [...this.imMsgs, ...e.map(v=>({
  151. type: v.payload.description,
  152. text: v.payload.data
  153. }))];
  154. },
  155. onImGroupTip(e) {
  156. this.subtitle = e[0].payload.userIDList.length + '人在观看';
  157. },
  158. onImGroupReady(e) {
  159. this.imStatus = e?'':'登录中...';
  160. },
  161. onImSend(text) {
  162. this.jhimgroup.sendText(text).then(msg => {
  163. this.imMsgs.push({
  164. type: 'text',
  165. name: msg.nick,
  166. text: msg.payload.text
  167. });
  168. this.$refs.jhlive && this.$refs.jhlive.cleanImInput();
  169. });
  170. },
  171. onLiveFav(isFav) {
  172. },
  173. exitRoom() {
  174. this.jhimgroup.off(this.onImText);
  175. this.jhimgroup.off(this.onImCustomMessage);
  176. this.jhimgroup.off(this.onImGroupTip);
  177. this.jhimgroup.offReady(this.onImGroupReady);
  178. this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout());
  179. this.$refs.jhlive && this.$refs.jhlive.exitRoom();
  180. },
  181. onBtnClick(index, item) {
  182. if(index === 0) {
  183. this.$refs.popup.open()
  184. }
  185. },
  186. goToGoodDetails(item) {
  187. uni.navigateTo({
  188. url: '/pagesGood/goodDetails?goodId=' + item.productId
  189. });
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="less" scoped>
  195. .container {
  196. position: relative;
  197. display: flex;
  198. flex-direction: column;
  199. align-items: stretch;
  200. width: 750rpx;
  201. }
  202. .jhlive {
  203. width: 750rpx;
  204. flex: 1;
  205. }
  206. .jhimlive {
  207. width: 400rpx;
  208. position: absolute;
  209. bottom: 10px;
  210. left: 10px;
  211. }
  212. .popup-open {
  213. width: 50px;
  214. height: 50px;
  215. position: fixed;
  216. bottom: 15px;
  217. right: 15px;
  218. background-color: #52A63A;
  219. border-radius: 50%;
  220. text-align: center;
  221. line-height: 50px;
  222. }
  223. .iconzhibo-shangpin {
  224. color: #FFFFFF;
  225. font-size: 34px;
  226. text-align: center;
  227. line-height: 50px;
  228. }
  229. .popup-box {
  230. background-color: #FFFFFF;
  231. width: 750rpx;
  232. height: 750rpx;
  233. border-top-left-radius: 10px;
  234. border-top-right-radius: 10px;
  235. }
  236. .popup-close {
  237. padding: 10px;
  238. line-height: 16px;
  239. }
  240. .popup-close-text {
  241. color: #52A63A;
  242. font-size: 15px;
  243. font-family: PingFang SC;
  244. text-align: left;
  245. }
  246. .good-box {
  247. width: 750rpx;
  248. height: 230px;
  249. padding: 0 0 10px 0;
  250. overflow: visible;
  251. }
  252. .goods-row:first-child {
  253. margin-top: 12px;
  254. }
  255. .goods-row {
  256. width: 700rpx;
  257. height: 104px;
  258. display: flex;
  259. flex-direction: row;
  260. flex-wrap: nowrap;
  261. background-color: #FFFFFF;
  262. box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  263. border-radius: 5px;
  264. margin: 0 15px 10px 15px;
  265. }
  266. .goods-img-box {
  267. margin-right: 15px;
  268. }
  269. .goods-img {
  270. width: 104px;
  271. height: 104px;
  272. object-fit: cover;
  273. }
  274. .goods-info {
  275. flex: 1;
  276. padding-top: 10px;
  277. }
  278. .goods-name {
  279. line-height: 15px;
  280. overflow: hidden;
  281. display: -webkit-box;
  282. -webkit-line-clamp: 2;
  283. -webkit-box-orient: vertical;
  284. word-wrap: break-word;
  285. text-overflow: ellipsis;
  286. font-size: 15px;
  287. font-family: PingFang SC;
  288. color: #333333;
  289. }
  290. .goods-sales {
  291. font-size: 12px;
  292. font-family: PingFang SC;
  293. color: #666666;
  294. line-height: 15px;
  295. margin: 8px 0 8px 0;
  296. }
  297. .price {
  298. font-size: 12px;
  299. text-decoration: line-through;
  300. color: #A67954;
  301. }
  302. .goods-number-bottom {
  303. display: flex;
  304. flex-direction: row;
  305. }
  306. .goods-number {
  307. display: flex;
  308. flex-direction: row;
  309. white-space: nowrap;
  310. line-height: 24px;
  311. }
  312. .goods-number-left {
  313. font-size: 12px;
  314. color: #666666;
  315. }
  316. .goods-icon {
  317. font-size: 14px;
  318. font-family: PingFang SC;
  319. color: #52A63A;
  320. }
  321. .goods-spec {
  322. font-size: 24px;
  323. font-family: PingFang SC;
  324. color: #52A63A;
  325. }
  326. .more-button {
  327. width: 24px;
  328. height: 24px;
  329. position: absolute;
  330. right: 16px;
  331. }
  332. .more-button-iconfont {
  333. font-size: 36px;
  334. color: #999999;
  335. text-align: center;
  336. }
  337. </style>