123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- <template>
- <view class="container" :style="'height: '+windowHeight+'px;'">
- <jhlive
- ref="jhlive" class="jhlive"
- :sdkAppID="sdkAppID" :secretKey="secretKey" :userId="userId" :roomId="roomId"
- :isAuthor="isAuthor" :linkMic="linkMic"
- :avatar="avatar" :subtitle="subtitle" :title="title"
- :showSwitch="true" :showBeauty="true" :btns="btns" @onBtnClick="onBtnClick"
- :showIm="true" :imStatus="imStatus" :imMsgs="imMsgs" @onImSend="onImSend" />
- <uni-popup ref="popup" animation type="bottom">
- <view class="popup-box">
- <view class="popup-close">
- <text class="popup-close-text" @click="$refs.popup.close()">收起</text>
- <text class="popup-close-text" @click="bindGood">绑定</text>
- </view>
- <scroll-view v-if="true" scroll-y="true" class="good-box2">
- <view class="goods-row2" v-for="(item, index) in goodsList" :key="index">
- <view class="good-check">
- <view @click="checkGoods(item)">
- <!-- #ifdef MP-WEIXIN -->
- <text class="iconfont good-check-iconfont" :class="item.check ? 'iconqueding' : 'iconfeigouxuan'" ></text>
- <!-- #endif -->
- <!-- #ifdef APP-PLUS -->
- <text class="nvue-iconfont good-check-iconfont" :style="{fontFamily:'nvueIconfont'}">{{item.check ? '' : ''}}</text>
- <!-- #endif -->
- </view>
- </view>
- <view class="good-card2">
- <view class="goods-img-box2">
- <image class="goods-img2" :src="item.imgPath" mode="aspectFill"></image>
- </view>
- <view class="goods-info2">
- <view>
- <text class="goods-name2">{{item.productName}}</text>
- </view>
- <text class="goods-sales2">销量:{{item.sellCount}}</text>
- <text class="price2">原价:{{item.originalPrice}}</text>
- <view class="goods-number2">
- <text class="goods-icon2">¥</text>
- <text class="goods-icon2">{{item.bizPrice}}/{{item.unit}}</text>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </uni-popup>
- <u-top-tips ref="uTips"></u-top-tips>
- </view>
- </template>
- <script>
- import jhlive from "@/jhlive/jhlive";
- import Jhim from "@/jhim/jhim.js";
- import permision from "@/utils/permission.js";
- const NET = require('@/utils/request')
- const API = require('@/config/api')
- export default {
- components: {
- jhlive,
- },
- data() {
- return {
- windowWidth: 0,
- windowHeight: 0,
- liveId: '',
- userData: {},
- videoUrl: '',
- goodsList: [],
- goodsIds: [],
- btns: [{picture:"../static/images/live-good.png",title:''}],
- isAuthor: true,
- linkMic: false,
- sdkAppID: API.sdkAppID,
- secretKey: API.secretKey,
- userId: '',
- userName: '',
- roomId: '',
- avatar: "../static/images/loginLogo.png",
- title: "加载中",
- subtitle: "0人在观看",
- isLiveFav: false,
- imStatus: '',
- imMsgs: [],
- }
- },
- onLoad(options) {
- this.liveId = options.liveId
- this.userData = uni.getStorageSync("userData");
- this.userId = this.userData.userId;
- this.userName = this.userData.userName;
- let info = uni.getSystemInfoSync();
- this.windowWidth = info.windowWidth;
- this.windowHeight = info.windowHeight;
- // 假数据
- // this.goodsList.push({
- // productId: 1336146105292816384,
- // tenantCode: null,
- // imgPath: 'https: //www.qianjiadi.com:443/file/2020/12/2af4eb48-35c4-4aa7-80c9-ab7a7cb49984.jpg',
- // productName: '测试拍卖商品zxw111',
- // sellCount: 0,
- // owner: 1,
- // productType: 2,
- // originalPrice: 1.00,
- // bizPrice: 0.01,
- // unit: '个'
- // },{
- // productId: 1336146105292816386,
- // tenantCode: null,
- // imgPath: 'https: //www.qianjiadi.com:443/file/2020/12/2af4eb48-35c4-4aa7-80c9-ab7a7cb49984.jpg',
- // productName: '测试拍卖商品zxw222',
- // sellCount: 0,
- // owner: 1,
- // productType: 2,
- // originalPrice: 1.00,
- // bizPrice: 0.01,
- // unit: '个'
- // })
- this.goodsIds = this.goodsList.map(site => {
- return site.productId
- }).join(',')
- this.goodsList.forEach(site => {
- site.check = this.goodsIds.indexOf(site.productId) != -1
- })
- },
- onReady() {
- // this.isAuthor = true;
- // this.linkMic = false;
- // this.userId = "123";
- // this.name = 'test';
- // this.roomId = '1';
- // this.$nextTick(() => this.enterRoom());
- // return;
- this.init();
- },
- // #ifdef APP-PLUS
- beforeCreate() {
- let domModule = weex.requireModule('dom');
- domModule.addRule('fontFace',{
- 'fontFamily': "nvueIconfont",
- 'src': "url('https://at.alicdn.com/t/font_2119167_43jbldmjpr3.ttf')"
- })
- },
- // #endif
- onUnload() {
- this.exitRoom();
- },
- methods: {
- init() {
- NET.request(API.startStream + 2, 'GET').then(res => {
- this.avatar = res.data.imgUrl;
- this.title = res.data.liveName;
- this.roomId = String(res.data.roomId);
- this.$nextTick(() => {
- permision.checkAndRequestPermissions(['scope.camera', 'scope.record']).then(()=>{
- this.enterRoom();
- }, ()=>{
- uni.showToast({
- title: '获取权限失败',
- duration: 2000,
- })
- })
- });
- }).catch(res => {
- uni.showToast({
- title: error.data.msg,
- duration: 2000
- });
- })
- },
- enterRoom() {
- this.jhim = Jhim.getInstance(this.userId, this.sdkAppID, this.secretKey);
- this.jhim.login(this.userName, this.avatar).then(()=>{
- this.jhimgroup = this.jhim.createGroup(this.roomId);
- this.jhimgroup
- .on(this.onImText, this.jhim.TYPES.MSG_TEXT)
- .on(this.onImCustomMessage, this.jhim.TYPES.MSG_CUSTOM)
- .on(this.onImGroupTip, this.jhim.TYPES.MSG_GRP_TIP)
- .onReady(this.onImGroupReady)
- .join(this.isAuthor)
- })
- this.$refs.jhlive && this.$refs.jhlive.enterRoom();
- },
- onImText(e) {
- this.imMsgs = [...this.imMsgs, ...e.map(v=>({
- type: 'text',
- name: v.nick,
- text: v.payload.text
- }))];
- },
- onImCustomMessage() {
- this.imMsgs = [...this.imMsgs, ...e.map(v=>({
- type: v.payload.description,
- text: v.payload.data
- }))];
- },
- onImGroupTip(e) {
- this.jhimgroup.getProfile().then(v=>{
- this.subtitle = v.memberCount + '人在观看';
- });
- },
- onImGroupReady(e) {
- this.imStatus = e?'':'登录中...';
- },
- onImSend(text) {
- this.jhimgroup.sendText(text).then(msg => {
- this.imMsgs.push({
- type: 'text',
- name: msg.nick,
- text: msg.payload.text
- });
- this.$refs.jhlive && this.$refs.jhlive.cleanImInput();
- });
- },
- exitRoom() {
- this.jhimgroup.off(this.onImText);
- this.jhimgroup.off(this.onImCustomMessage);
- this.jhimgroup.off(this.onImGroupTip);
- this.jhimgroup.offReady(this.onImGroupReady);
- this.jhimgroup.exit(this.isAuthor).then(()=>this.jhim.logout().then(()=>this.jhim.destroy()));
- this.$refs.jhlive && this.$refs.jhlive.exitRoom();
- NET.request(API.creatLive, {
- liveId: this.liveId,
- liveStatus: 2
- }, 'GET').then(res => {}).catch(res => {
- this.$refs.uTips.show({
- title: '关闭直播失败',
- type: 'warning',
- })
- })
-
- },
- onBtnClick(index, item) {
- if(index === 0) {
- this.$refs.popup.open()
- // 打开弹窗
- NET.request(API.getBindedLiveGoods, {
- liveId: this.liveId
- }, 'GET').then(res => {
- let goodsIds = res.data.map(site => {
- return site.productId
- }).join(',')
- this.getAllGoods(goodsIds)
- }).catch(res => {
- this.$refs.uTips.show({
- title: '获取已绑定商品失败',
- type: 'warning',
- })
- })
- }
- },
- // 获取可绑定商品
- getAllGoods(goodsIds) {
- NET.request(API.getVideoGoods, {}, 'GET').then(res => {
- res.data.forEach(site => {
- site.check = goodsIds.indexOf(site.productId) != -1
- })
- this.goodsList = res.data
- }).catch(res => {
- this.$refs.uTips.show({
- title: '获取商品失败',
- type: 'warning',
- })
- })
- },
- // 绑定商品
- bindGood() {
- NET.request(API.bindLiveGoods, {
- liveId: this.liveId,
- prudoctIds: this.goodsList.filter(site => site.check).map(site => {
- return site.productId
- })
- }, 'POST').then(res => {
- this.$refs.popup.close()
- this.$refs.uTips.show({
- title: '设置成功',
- type: 'success',
- })
- }).catch(res => {
- this.$refs.uTips.show({
- title: '设置失败',
- type: 'warning',
- })
- })
- },
- // 勾选商品
- checkGoods(site) {
- console.log(site)
- site.check = !site.check
- }
- },
- }
- </script>
- <style>
- .nvue-iconfont {
- font-family: "nvueIconfont";
- font-size: 16px;
- font-style: normal;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
- </style>
- <style lang="less" scoped>
- .container {
- position: relative;
- display: flex;
- flex-direction: column;
- align-items: stretch;
- width: 750rpx;
- }
- .jhlive {
- width: 750rpx;
- flex: 1;
- }
- .jhimlive {
- width: 400rpx;
- position: absolute;
- bottom: 10px;
- left: 10px;
- // background-color: blue;
- }
- .popup-open {
- width: 50px;
- height: 50px;
- position: fixed;
- bottom: 15px;
- right: 15px;
- background-color: #52A63A;
- border-radius: 50%;
- text-align: center;
- line-height: 50px;
- }
- .iconzhibo-shangpin {
- color: #FFFFFF;
- font-size: 34px;
- }
- .popup-box {
- background-color: #FFFFFF;
- width: 750rpx;
- height: 750rpx;
- // border-radius: 10px 10px 0 0;
- border-top-left-radius:10px;
- border-top-right-radius: 10px;
- }
- .popup-close {
- padding: 10px;
- line-height: 16px;
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- }
- .popup-close-text{
- color: #52A63A;
- font-size: 15px;
- font-family: PingFang SC;
- }
- .good-check {
- width: 30px;
- height: 114px;
- line-height: 114px;
- margin-right: 10px;
- }
- .good-check-iconfont {
- font-size: 40px;
- text-align: center;
- color: #51A539;
- line-height: 114px;
- }
-
- .good-box2 {
- width: 750rpx;
- height: 750rpx;
- padding: 0 0 10px 0;
- overflow: visible;
- }
-
- .goods-row2:first-child {
- margin-top: 12px;
- }
-
- .goods-row2 {
- width: 700rpx;
- height: 114px;
- display: flex;
- flex-direction: row;
- flex-wrap: nowrap;
- background-color: #FFFFFF;
- box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
- border-radius: 5px;
- margin: 0 15px 10px 15px;
- }
- .good-card2 {
- display: flex;
- flex-direction: row;
- flex-wrap: nowrap;
- }
- .goods-img-box2 {
- margin-right: 15px;
- }
-
- .goods-img2 {
- width: 114px;
- height: 114px;
- object-fit: cover;
- }
-
- .goods-info2 {
- width: 180px;
- flex: 1;
- padding-top: 10px;
- }
-
- .goods-name2 {
- line-height: 15px;
- overflow: hidden;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- word-wrap: break-word;
- text-overflow: ellipsis;
- font-size: 15px;
- font-family: PingFang SC;
- color: #333333;
- }
-
- .goods-sales2 {
- font-size: 12px;
- font-family: PingFang SC;
- color: #666666;
- line-height: 15px;
- margin: 8px 0 8px 0;
- }
-
- .price2 {
- font-size: 12px;
- text-decoration: line-through;
- color: #A67954;
- }
-
- .goods-number-bottom2 {
- display: flex;
- flex-direction: row;
- }
-
- .goods-number2 {
- display: flex;
- flex-direction: row;
- white-space: nowrap;
- line-height: 24px;
- }
-
- .goods-number-left2 {
- font-size: 12px;
- color: #666666;
- }
-
- .goods-icon2 {
- font-size: 14px;
- font-family: PingFang SC;
- color: #52A63A;
- }
-
- .goods-spec2 {
- font-size: 24px;
- font-family: PingFang SC;
- color: #52A63A;
- }
- </style>
|