liveControl.vue 17.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
<!-- 控制台 -->
<template>
  <div class="live-room live-control">
    <div class="container">
      <div class="box">
        <p class="edit-title">直播控制台</p>
        <div class="head-box flex-start">
          <img class="head-img" :src="editForm.shareImgUrl" />
          <div>
            <p class="head-title m-b-18">{{ editForm.name }}</p>
            <p class="txt m-b-18">开播时间:{{ editForm.startTime + '-' + editForm.endTime }}</p>
            <p class="txt m-b-18">房间号:{{ editForm.id }}</p>
            <p class="txt m-b-18">
              <span class="m-r-20">主播:{{ editForm.anchorName }}</span>
              <span>微信号:{{ editForm.anchorWechat }}</span>
            </p>
            <p class="count-down" v-if="countDown">倒计时{{ countDown }}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="box">
        <div class="content">
          <p class="edit-title no-border">直播数据</p>
          <GLTable :tableParams="liveTableParams" :tableData="liveDataTable" :hasPage="false">
            <span slot="coverImgUrl" slot-scope="scope">
              <img class="img-60" :src="scope.scope.coverImgUrl" />
            </span>
          </GLTable>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="box">
        <div class="content">
          <p class="edit-title">商品数据</p>
          <div class="flex pro-data">
            <div class="w-25">
              <p>直播成交总金额</p>
              <p class="price">¥{{ editForm.saleAmtTotal || '0' }}</p>
            </div>
            <div class="w-25">
              <p>累计推送次数</p>
              <p class="price">{{ editForm.pushNum }}</p>
            </div>
            <div class="w-25">
              <p>商品点击人数</p>
              <p class="price">{{ editForm.clickUserNum }}</p>
            </div>
            <div class="w-25">
              <p>商品点击次数</p>
              <p class="price">{{ editForm.clickNum }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="box">
        <div class="content">
          <p class="edit-title no-border">商品配置</p>
          <div class="flex">
            <el-form :inline="true" :model="searchConfigForm">
              <el-form-item label="商品名称:">
                <el-input :size="size" v-model="searchConfigForm.name" placeholder="请输入商品名称" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <el-button :size="size" type="primary" @click="handleConfigSearch">查询</el-button>
                <el-button :size="size" @click="handleConfigReset">重置</el-button>
              </el-form-item>
            </el-form>
            <el-form>
              <el-form-item>
                <el-button v-if="![103, 107].includes(editForm.liveStatus)" type="primary" size="mini" @click="handleConfigImport">导入商品</el-button>
              </el-form-item>
            </el-form>
          </div>
          <GLTable ref="controlConfigRef" :searchForm="searchConfigForm" :tableParams="tableParams" :getListApi="getControlImportListApi" :pageConf="pageConf" :beforeSearchFn="beforeConfigSearchFn">
            <span slot="coverImgUrl" slot-scope="scope">
              <img class="img-60" :src="scope.scope.coverImgUrl" />
            </span>
            <span class="table-btns" slot="auth-button" slot-scope="scope" :data="scope.scope">
              <el-button v-if="editForm.liveStatus == '101'" type="text" @click="handlePush(scope.scope.id)">{{ targetId === scope.scope.id ? '已推送' + pushCountDown + 's' : '推送' }}</el-button>
              <!-- <el-button type="text" @click="handlePush(scope.scope.id)">{{ targetId === scope.scope.id ? '已推送' + pushCountDown + 's' : '推送' }}</el-button> -->
              <el-button v-show="!targetId" type="text" @click="handleUpOrDown(scope.scope)">{{ scope.scope.onSale == '1' ? '下架' : '上架' }}</el-button>
              <el-button v-show="!targetId" type="text" @click="handleDelete(scope.scope)">删除</el-button>
            </span>
          </GLTable>
        </div>
      </div>
    </div>
    <div class="container edit-container">
      <div class="box">
        <div class="content">
          <p class="edit-title">直播设置</p>
          <div class="flex">
            <div>
              <p class="edit-title no-border">直播间禁言</p>
              <p class="txt">
                开启后,所有观众无法在直播间发表评论。
                <el-switch :disabled="editForm.liveStatus != '102'" :size="size" v-model="editForm.closeComment" active-value="1" inactive-value="0" @change="handleChangeComment"></el-switch>
                <!-- <el-switch :size="size" v-model="editForm.closeComment" active-value="1" inactive-value="0" @change="handleChangeComment"></el-switch> -->
              </p>
            </div>
            <div>
              <p class="edit-title no-border">直播回放</p>
              <p class="txt">
                开启后,观众可在直播结束页面查看本场直播。
                <el-switch :disabled="[103, 107].includes(editForm.liveStatus)" :size="size" v-model="editForm.closeReplay" active-value="1" inactive-value="0" @change="handleChangeReplay"></el-switch>
                <!-- <el-switch :size="size" v-model="editForm.closeReplay" active-value="1" inactive-value="0" @change="handleChangeReplay"></el-switch> -->
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <el-button type="primary" @click="handleBack">返回</el-button>
    </div>
    <select-muti-pro-dialog v-if="isMutiSelectVisible" :isMutiSelectVisible="isMutiSelectVisible" :searchForm="searchWaitForm" :getListApi="getWaitImportListApi" :selectedProList="selectedProList" @handleMutiSelectConfirm="handleMutiSelectConfirm" @handleMutiSelectClose="handleMutiSelectClose">
      <!-- <template slot="search">
        <div class="flex">
          <el-form :inline="true" :model="searchWaitForm">
            <el-form-item label="商品名称:">
              <el-input :size="size" v-model="searchWaitForm.name" placeholder="请输入商品名称" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-button :size="size" type="primary" @click="handleConfigSearch">查询</el-button>
              <el-button :size="size" @click="handleConfigReset">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </template> -->
    </select-muti-pro-dialog>
  </div>
</template>

<script>
import { getControlInfoApi, getControlImportListApi, getWaitImportListApi, importGoodsApi, updateCommentApi, updateReplayApi, controlUpOrDownApi, controlDeleteApi } from '@/api/modules/liveRoom'
// import selectMutiProDialog from './selectMutiProDialog'
import { liveStatusList } from '@/common/constant'
import selectMutiProDialog from '@/components/select-muti-pro'
export default {
  name: 'liveControl',
  data() {
    return {
      size: 'small',
      countDown: 0,
      timer: null,
      isFirst: true,
      editForm: {},
      // 直播数据 - 表格
      liveDataTable: [],
      liveTableParams: {
        tableColumns: [
          {
            label: '商品名称',
            prop: 'goodsName',
            line: 2
          },
          {
            label: '商品图片',
            prop: 'coverImgUrl',
            addHtml: 'coverImgUrl'
          },
          {
            label: '成交单量',
            prop: 'saleNum',
            line: 1
          },
          {
            label: '成交金额',
            prop: 'saleAmt',
            line: 1
          },
          {
            label: '来源门店',
            prop: 'merchantName',
            line: 2
          }
        ]
      },
      // 导入商品
      isMutiSelectVisible: false,
      searchWaitForm: {},
      selectedProList: [],
      getWaitImportListApi: getWaitImportListApi,
      // 商品配置 - 表格
      getControlImportListApi: getControlImportListApi,
      searchConfigForm: {},
      pushTimer: null,
      pushCountDown: 0,
      targetId: '',
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '商品图片',
            prop: 'coverImgUrl',
            addHtml: 'coverImgUrl'
          },
          {
            label: '商品标题',
            prop: 'name',
            line: 2
          },
          {
            label: '商品价格',
            prop: 'price',
            line: 1,
            formatter: cellValue => {
              return cellValue.price2 && cellValue.price1 != cellValue.price2 ? (cellValue.price1 / 100).toFixed(2) + '-' + (cellValue.price2 / 100).toFixed(2) : (cellValue.price1 / 100).toFixed(2)
            }
          },
          {
            label: '状态',
            prop: 'onSale',
            width: '80',
            formatter: cellValue => {
              return {
                0: '下架',
                1: '上架'
              }[cellValue.onSale]
            }
          },
          {
            label: '点击次数',
            prop: 'clickNumber',
            line: 1
          },
          {
            label: '点击人数',
            prop: 'clickUserNumber',
            line: 1
          },
          {
            label: '来源门店',
            prop: 'merchantName',
            line: 2
          }
        ]
      },
      baseDataList: {
        liveStatusList: liveStatusList
      }
    }
  },

  components: {
    selectMutiProDialog
  },

  computed: {},

  mounted() {
    this.routeInfo = this.$route.params
    this.searchWaitForm = {
      id: this.routeInfo.id
    }
    this.getInfo()
  },
  beforeDestroy() {
    this.timer && clearInterval(this.timer)
    this.pushTimer && clearInterval(this.pushTimer)
  },

  methods: {
    getInfo(fn, noChangeList = []) {
      getControlInfoApi({ id: this.routeInfo.id }).then(res => {
        // liveStatus 直播间状态101:直播中,102:未开始,103已结束,104禁播,105:暂停,106:异常,107:已过期
        this.editForm = res
        this.liveDataTable = res.liveStatisticsDTOList
        this.editForm.closeComment = res.closeComment + ''
        this.editForm.closeReplay = res.closeReplay + ''
        this.isFirst = true
        console.log(this.editForm)
        this.countDownTime()
        fn && fn()
      })
    },
    beforeConfigSearchFn() {
      return new Promise(resolve => {
        this.searchConfigForm.id = this.$route.params.id
        resolve()
      })
    },
    handleConfigSearch() {
      this.$refs.controlConfigRef.refreshTable()
    },
    handleConfigReset() {
      this.searchConfigForm.name = ''
      this.handleConfigSearch()
    },
    countDownTime() {
      this.isFirst ? (this.isFirst = false) : (this.editForm.systemTimestamp = this.editForm.systemTimestamp + 1)
      clearInterval(this.timer)
      if (new Date() < new Date(this.editForm.startTime)) {
        this.timer = setInterval(() => {
          var leftTime = new Date(this.editForm.startTime) - new Date()
          //计算剩余的天数
          var days = parseInt(leftTime / 1000 / 60 / 60 / 24, 10)
          //计算剩余的小时
          var hours = parseInt((leftTime / 1000 / 60 / 60) % 24, 10)
          //计算剩余的分钟
          var minutes = parseInt((leftTime / 1000 / 60) % 60, 10)
          //计算剩余的秒数
          var seconds = parseInt((leftTime / 1000) % 60, 10)
          // days = this.checkTime(days)
          // hours = this.checkTime(hours)
          // minutes = this.checkTime(minutes)
          // seconds = this.checkTime(seconds)
          this.countDown = (days ? days + '天' : '') + hours + '小时' + minutes + '分' + seconds + '秒'
          this.countDownTime()
        }, 1000)
      }
    },
    //将0-9的数字前面加上0,例1变为01
    // checkTime(i) {
    //   if (i < 10) {
    //     i = '0' + i
    //   }
    //   return i
    // },
    handlePush(id) {
      if (!this.targetId) {
        this.targetId = id
        this.pushTimeDown()
      }
    },
    pushTimeDown() {
      clearInterval(this.pushTimer)
      if (this.pushCountDown != 60) {
        this.pushTimer = setInterval(() => {
          this.pushCountDown++
          this.pushTimeDown()
        }, 1000)
      } else {
        this.targetId = ''
        this.pushCountDown = 0
      }
    },
    handleUpOrDown(row) {
      var upOrDownTxt = row.onSale == '1' ? '下架' : '上架'
      this.$messageBox.confirm('是否'+upOrDownTxt+'该商品?', upOrDownTxt, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error',
        callback: action => {
          if (action == 'confirm') {
            controlUpOrDownApi({ roomId: this.editForm.roomId, goodsId: row.id }).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                this.handleConfigSearch()
              }
            })
          }
        }
      })
    },
    handleDelete(row) {
      this.$messageBox.confirm('是否删除该商品?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error',
        callback: action => {
          if (action == 'confirm') {
            controlDeleteApi({ roomId: this.editForm.roomId, goodsId: row.id }).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                this.handleConfigSearch()
              }
            })
          }
        }
      })
    },
    handleConfigImport() {
      var that = this
      this.getInfo(() => {
        if ([103, 107].includes(this.editForm.liveStatus)) {
          this.$message({
            message: '直播' + that.baseDataList.liveStatusList.find(item => item.confId == this.editForm.liveStatus).confName + ',不能导入商品',
            type: 'info'
          })
          return true
        }
        this.isMutiSelectVisible = !this.isMutiSelectVisible
      })
    },
    handleMutiSelectConfirm(selectedProInfo) {
      var params = {
        roomId: this.routeInfo.id,
        goodsIds: selectedProInfo.map(item => item.id)
      }
      console.log(params)
      importGoodsApi(params).then(res => {
        this.$message({
          message: res.code == '0' ? '操作成功' : '操作失败',
          type: res.code == '0' ? 'success' : 'error'
        })
        if (res.code == '0') {
          this.handleConfigReset()
        }
      })
    },
    handleMutiSelectClose() {
      this.handleConfigImport()
    },
    // liveStatus 直播间状态101:直播中,102:未开始,103已结束,104禁播,105:暂停,106:异常,107:已过期
    handleChangeComment(val) {
      this.getInfo(() => {
        if (this.editForm.liveStatus != 102) {
          // this.$message({
          //   message: '当前直播间不处于未开始状态,不能开启禁言',
          //   type: 'info'
          // })
          return true
        }
        var params = {
          id: this.routeInfo.id,
          banComment: val
        }
        updateCommentApi(params).then(res => {
          this.$message({
            message: res.code == '0' ? '操作成功' : '操作失败',
            type: res.code == '0' ? 'success' : 'error'
          })
          if (res.code != '0') {
            this.editForm.closeComment = val ? '0' : '1'
          } else {
            this.editForm.closeComment = val
          }
        })
      })
    },
    handleChangeReplay(val) {
      this.getInfo(() => {
        if ([103, 107].includes(this.editForm.liveStatus)) {
          // this.$message({
          //   message: '不能改变回播状态',
          //   type: 'info'
          // })
          return true
        }
        var params = {
          id: this.routeInfo.id,
          closeReplay: val
        }
        updateReplayApi(params).then(res => {
          this.$message({
            message: res.code == '0' ? '操作成功' : '操作失败',
            type: res.code == '0' ? 'success' : 'error'
          })
          if (res.code != '0') {
            this.editForm.closeReplay = val ? '0' : '1'
          } else {
            this.editForm.closeReplay = val
          }
        })
      })
    },
    handleBack() {
      this.$router.push({
        path: '/liveRoom/liveRoomList'
      })
    }
  }
}
</script>
<style>
/* .live-control {
  padding: 20px;
} */
/* .live-control p {
  margin: 0 0 10px 0;
  color: #666666;
} */
/* .live-control .box {
  padding: 10px;
  border: 1px solid #cccccc;
} */
.live-control {
  font-size: 16px;
  color: #333333;
}
.live-control .flex-start {
  display: flex;
  justify-content: flex-start;
}
.live-control .no-border{
  border: 0;
}
.live-control .m-b-18 {
  margin-bottom: 18px;
}
.live-control .m-r-20 {
  margin-right: 20px;
}
.live-control .head-box {
  position: relative;
  padding: 32px 10px 17px;
}
.live-control .head-box .head-title {
  line-height: 20px;
  font-weight: bold;
}
.live-control .txt {
  font-size: 14px;
  line-height: 20px;
  color: #666666;
}
.live-control .head-box .count-down {
  position: absolute;
  right: 20px;
  top: 100px;
  font-size: 20px;
  color: #5850FF;
}
.live-control .head-box .head-img {
  width: 170px;
  height: 136px;
  padding-right: 20px;
}
.live-control .pro-data {
  padding: 40px 20px;
}
.pro-data .w-25 {
  width: 25%;
  text-align: center;
}
.live-control .pro-data .price {
  font-size: 30px;
  margin-top: 20px;
}
</style>