index.vue 23 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 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
<template>
  <div class="main-container">
    <div class="top">
      <!-- <el-button type="primary" @click="addMaterial(1)" :size="size">
        <i class="el-icon-plus"></i>
        创建营销素材
      </el-button> -->
      <GLButton :size="size" type="primary" fn="新增营销素材" class="el-icon-plus" @click="addMaterial(1)">创建营销素材</GLButton>
    </div>
    <span @click="showIntroductionDialog" class="introduc-word">
      功能介绍
      <!-- <i class="el-icon-arrow-right"></i> -->
    </span>
    <div class="container">
      <div class="search-form">
        <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="materialFormData" @handleOk="getListApi" @handleRest="handleReset"></GLCombiForm>
      </div>
      <div class="tabelList">
        <el-row>
          <el-col :span="5">
            <div class="left">
              <MaterialGroup ref="materialGroup" @openAddDialog="addDialogShow" :groupHeight="boxHeight" :eventBus="eventBus" @getList="getList" @getListApi="getListApi"></MaterialGroup>
            </div>
          </el-col>
          <el-col :span="19">
            <div class="right" :style="{ height: boxHeight + 'px' }">
              <div class="groupTitle">{{ materialGroupName }}(共{{ tableTotal }}条数据)</div>
              <GLTable ref="materialRef" :hasPage="false" :noDataImg="url" @refreshTable="getListApi" :layout="layout" :searchForm="searchForm" :tableParams="tableParams" :tableData="materialTableData" :pageConf="pageConf" :tableTotal="tableTotal" @sortChange="sortChange" :isCustomHead="true" :customHeadShowList="customHeadShowList">
                <!-- 素材内容 -->
                <div slot="materialContentRpcResponse" slot-scope="scope" style="text-align: center">
                  <!-- 素材为PDF -->
                  <span v-if="scope.scope.materialType == 1" class="material-content">
                    <img src="@/assets/material/pdf.png" style="margin-right:8px" alt="" />
                    <el-tooltip effect="dark" placement="top" :content="scope.scope.materialContentRpcResponse.materialName" :disabled="scope.scope.materialContentRpcResponse.materialName.length < 12">
                      <span class="hide-content">{{ scope.scope.materialContentRpcResponse.materialName }}</span>
                    </el-tooltip>
                  </span>
                  <!-- 素材为自定义链接 -->
                  <span v-if="scope.scope.materialType == 2"></span>
                  <!-- 素材为图文 -->
                  <span v-if="scope.scope.materialType == 3 || scope.scope.materialType == 4 || scope.scope.materialType == 5 || scope.scope.materialType == 6" class="material-content">
                    <!-- 图片 -->
                    <el-popover placement="top" trigger="hover" v-if="scope.scope.urlType == 'img'">
                      <div>
                        <img class="img-plus" :src="scope.scope.materialContentRpcResponse.materialUrl" alt="" />
                      </div>
                      <div slot="reference" class="urlContent">
                        <img style="margin-right:8px" :src="scope.scope.materialContentRpcResponse.materialUrl" alt="" />
                        <div class="videoMask" v-if="scope.scope.imgCount > 1">
                          <img src="@/assets/material/multi.png" alt="" />
                          <span>{{ scope.scope.imgCount }}</span>
                        </div>
                      </div>
                    </el-popover>
                    <!-- 视频 -->
                    <div class="urlContent" v-if="scope.scope.urlType == 'video'" @click="videoOpen(scope.scope)">
                      <video preload loop muted width="36" height="36">
                        <source :src="scope.scope.materialContentRpcResponse.materialUrl" type="video/mp4" />
                      </video>
                      <div class="videoMask">
                        <img src="@/assets/material/videoIcon.png" style="width: 22px;height: 22px;" alt="" />
                      </div>
                    </div>
                    <el-tooltip effect="dark" placement="top" :content="scope.scope.materialContentRpcResponse.materialName" :disabled="scope.scope.materialContentRpcResponse.materialName.length < 14">
                      <span class="hide-content">{{ scope.scope.materialContentRpcResponse.materialName }}</span>
                    </el-tooltip>
                  </span>
                </div>
                <!-- 状态 -->
                <div slot="status" class="dot" slot-scope="scope">
                  <div :class="materialStatus[scope.scope.status]"></div>
                  <span v-if="scope.scope.status == 0">启用</span>
                  <span v-if="scope.scope.status == -1">停用</span>
                  <span v-if="scope.scope.status == 1">草稿</span>
                </div>
                <!-- 类型 -->
                <div slot="materialType" slot-scope="scope">
                  <span v-if="scope.scope.materialType == 1">pdf文件</span>
                  <span v-if="scope.scope.materialType == 2">自定义链接</span>
                  <span v-if="scope.scope.materialType == 3">图文</span>
                  <span v-if="scope.scope.materialType == 4">视频</span>
                  <span v-if="scope.scope.materialType == 5">纯文字</span>
                  <span v-if="scope.scope.materialType == 6">纯图片</span>
                </div>
                <span slot="auth-button" slot-scope="scope">
                  <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
                </span>
              </GLTable>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <AddMaterialGroupDia :businessTypes="businessTypes" ref="addMaterialGroup" :dialogVisible="materialGroupDialog" :eventBus="eventBus"></AddMaterialGroupDia>
    <FunctionIntroduc :introductionDialog="introductionDialog" @closeIntroductDia="closeIntroductDia"></FunctionIntroduc>
    <VideoShowDia ref="VideoShowDia" :dialogVisible="dialogVisibleImg"></VideoShowDia>
  </div>
</template>

<script>
const materialStatus = {
  '0': 'normal',
  '1': 'draft',
  '-1': 'dot3'
}
import Vue from 'vue'
import url from '@/assets/empty.png'
import iconUrl from '@/assets/icon-circle-question.png'
import AddMaterialGroupDia from '@/views/material/components/addMaterialGroupDia'
import MaterialGroup from '@/views/material/components/materialGroup'
import FunctionIntroduc from '@/views/material/components/functionIntroduc'
import VideoShowDia from './components/videoDia.vue'
export default {
  name: 'materialList',
  components: {
    AddMaterialGroupDia,
    MaterialGroup,
    FunctionIntroduc,
    VideoShowDia
  },
  data() {
    return {
      dialogVisibleImg: false, // 视频弹框
      url,
      materialStatus: materialStatus,
      eventBus: new Vue(),
      searchForm: {
        groupId: '', // 素材组id
        materialType: '', // 素材类型
        businessType: '', // 业务类型
        status: '', // 状态
        materialName: '' // 素材名称
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      layout: 'sizes, prev, pager, next, jumper, ->, total',
      // 表格数据
      materialTableData: [],
      // 创建&编辑素材组弹框
      materialGroupDialog: false,
      // 功能介绍弹框
      introductionDialog: false,
      boxHeight: '',
      // 表格高度
      tableHeight: '',
      // 业务类型
      businessTypes: [],
      // 素材组名称
      materialGroupName: '',
      materialFormData: [
        {
          label: '业务类型',
          name: 'businessType',
          type: 'select',
          placeholder: '全部',
          optionList: [],
          optionId: 'id',
          optionLabel: 'businessName',
          optionsName: 'businessName'
        },
        {
          label: '素材类型',
          name: 'materialType',
          type: 'select',
          placeholder: '全部',
          optionList: [
            {
              optionId: '',
              optionLabel: '全部'
            },
            {
              optionId: 1,
              optionLabel: 'pdf'
            },
            // {
            //   optionId: 2,
            //   optionLabel: '自定义链接'
            // },
            {
              optionId: 3,
              optionLabel: '图文'
            },
            {
              optionId: 4,
              optionLabel: '视频'
            },
            {
              optionId: 5,
              optionLabel: '纯文字'
            },
            {
              optionId: 6,
              optionLabel: '纯图片'
            }
          ],
          optionId: 'optionId',
          optionLabel: 'optionLabel',
          optionsName: 'optionLabel'
        },
        {
          label: '状态',
          name: 'status',
          type: 'select',
          placeholder: '全部',
          optionList: [
            {
              optionId: '',
              optionLabel: '全部'
            },
            {
              optionId: 0,
              optionLabel: '启用'
            },
            {
              optionId: -1,
              optionLabel: '停用'
            },
            {
              optionId: 1,
              optionLabel: '草稿'
            }
          ],
          optionId: 'optionId',
          optionLabel: 'optionLabel',
          optionsName: 'optionLabel'
        },
        {
          label: '素材名称',
          name: 'materialName',
          type: 'input',
          placeholder: '请输入素材名称'
        }
      ],
      // 表格按钮
      tableButtonList: [
        {
          type: 'GLButton',
          name: '详情',
          attrs: {
            type: 'text',
            fn: '详情'
          },
          listeners: {
            click: this.handleDetail
          }
        },
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          listeners: {
            click: row => this.addMaterial(2, row)
          }
        },
        {
          type: 'GLButton',
          name: row => {
            return row.status == 0 ? '禁用' : '启用'
          },
          attrs: {
            type: 'text',
            fn: '禁用'
          },
          listeners: {
            click: this.handleForbid
          }
        },
        {
          type: 'GLButton',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除营销素材'
          },
          listeners: {
            click: this.handleDelete
          }
        }
      ],
      tableParams: {
        listName: 'data',
        tableOption: true,
        tableColumns: [
          {
            label: '素材内容',
            prop: 'materialContentRpcResponse',
            addHtml: 'materialContentRpcResponse',
            width: 270
          },
          {
            label: '状态',
            prop: 'status',
            addHtml: 'status',
            width: 120
          },
          {
            label: '类型',
            prop: 'materialType',
            addHtml: 'materialType',
            width: 100
          },
          {
            label: '发送次数',
            prop: 'sendNum',
            sortable: true,
            width: 130,
            formatter: cellVal => {
              return cellVal.sendNum
            },
            renderHeader: (h, { column, $index }) => {
              return h(
                'div',
                {
                  style: {
                    display: 'inline-flex',
                    'align-items': 'center',
                    padding: 0
                  }
                },
                [
                  '发送次数',
                  h(
                    'el-popover',
                    {
                      attrs: {
                        placement: 'top-start',
                        width: '240',
                        trigger: 'hover',
                        content: '统计该素材的发送次数(不包含在系统外部的转发次数)'
                      }
                    },
                    [
                      h('img', {
                        style: {
                          width: '17px',
                          height: '17px',
                          'vertical-align': 'middle'
                        },
                        attrs: {
                          src: iconUrl
                        },
                        slot: 'reference'
                      })
                    ]
                  )
                ]
              )
            }
          },
          {
            label: '阅读人数',
            prop: 'readNum',
            width: 130,
            sortable: true,
            formatter: cellVal => {
              return cellVal.readNum
            },
            renderHeader: (h, { column, $index }) => {
              return h(
                'div',
                {
                  style: {
                    display: 'inline-flex',
                    'align-items': 'center',
                    padding: 0
                  }
                },
                [
                  '阅读人数',
                  h(
                    'el-popover',
                    {
                      attrs: {
                        placement: 'top-start',
                        width: '240',
                        trigger: 'hover',
                        content: '阅读该素材的人数,内部员工除外。'
                      }
                    },
                    [
                      h('img', {
                        style: {
                          width: '17px',
                          height: '17px',
                          'vertical-align': 'middle'
                        },
                        attrs: {
                          src: iconUrl
                        },
                        slot: 'reference'
                      })
                    ]
                  )
                ]
              )
            }
          },
          {
            label: '更新时间',
            prop: 'updatedTime',
            width: 150,
            sortable: true,
            formatter: cellVal => {
              return cellVal.updatedTime
            }
          }
        ]
      },
      // 获取素材总条数
      tableTotal: 0
    }
  },
  mounted() {
    // 计算素材组&素材展示表格容器高度
    let clientHeight = document.documentElement.clientHeight
    let offTop = document.querySelector('.tabelList').offsetTop
    this.boxHeight = clientHeight - offTop - 80
    this.tableHeight = clientHeight - offTop - 135 + 'px'
    // this.findAllDictData('business_type')
    this.getListEntBusinessType()
    this.firstCome()
    this.getListApi()
  },
  methods: {
    // 判断是否第一次进入
    firstCome() {
      if (!window.sessionStorage.getItem('firstLogin')) {
        this.introductionDialog = true
        window.sessionStorage.setItem('firstLogin', 'true')
      }
    },

    videoOpen(scope) {
      console.log(scope)
      this.dialogVisibleImg = true
      let dialogSrc = scope.materialContentRpcResponse.materialUrl
      this.$refs.VideoShowDia.init(dialogSrc)
    },

    // 重置
    handleReset() {
      this.searchForm = {
        applicationType: '',
        materialType: '',
        businessType: '',
        status: '',
        materialName: ''
      }
      this.getListApi()
      this.$refs.materialGroup.currentIndex = null
    },
    // 获取所有业务类型
    // findAllDictData(dictType) {
    //   var params = {
    //     dictType
    //   }
    //   this.$apis.material.findAllDictData(params).then(res => {
    //     if (res) {
    //       this.businessTypes = res
    //       let idx = this.materialFormData.findIndex(item => item.name == 'businessType')
    //       res.unshift({
    //         dictValue: '',
    //         dictLabel: '全部'
    //       })
    //       this.materialFormData[idx].optionList = res
    //     }
    //   })
    // },
    getListEntBusinessType() {
      var params = {}
      // flag 0-跟进专员调用 1-素材调用
      params.flag = 1
      this.$apis.material.getListEntBusinessType(params).then(res => {
        if (res) {
          this.businessTypes = res
          let idx = this.materialFormData.findIndex(item => item.name == 'businessType')
          res.unshift({
            id: '',
            businessName: '全部'
          })
          this.materialFormData[idx].optionList = res
        }
      })
    },
    // 新增或编辑素材组弹框打开
    addDialogShow(addOrEdit, value, group) {
      this.materialGroupDialog = true
      this.$refs.addMaterialGroup.init(addOrEdit, value, group)
    },
    // 素材详情
    handleDetail(scope) {
      this.$router.push({
        path: '/material/materialDetail',
        query: {
          id: scope.id
        }
      })
    },
    // 素材禁用&启用
    handleForbid(scope) {
      var params = {}
      params.id = scope.id
      if (scope.status == 0) {
        params.status = -1
        this.secondConfirm('提示', '禁用素材,确定禁用此素材?', 'material', 'materialEdit', params)
      } else {
        params.status = 0
        this.secondConfirm('提示', '启用素材,确定启用此素材?', 'material', 'materialEdit', params)
      }
    },
    // 素材删除
    handleDelete(scope) {
      this.secondConfirm('提示', '删除素材,该素材将不再可以使用,是否继续删除?', 'material', 'materialDelete', { id: scope.id })
    },
    // 1-新增素材,2-编辑素材
    addMaterial(addOrEdit, scope) {
      var params = {
        addOrEdit: addOrEdit,
        $title: encodeURI(addOrEdit == 1 ? '创建营销素材' : '编辑营销素材')
      }
      addOrEdit != 1 && (params.id = scope.id)
      addOrEdit != 1 && (params.status = scope.status)
      this.$router.push({
        path: '/material/addMaterial',
        query: params
      })
    },
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      return params
    },
    // 获取素材列表
    getTableList(params) {
      this.$apis.material.materialList(params).then(res => {
        let data = res
        let tableData = []
        data.forEach(item => {
          // 根据素材类型是图文处理数据
          if (item.materialType == 3 || item.materialType == 4 || item.materialType == 5 || item.materialType == 6) {
            let html = decodeURIComponent(item.materialContentRpcResponse.materialUrl)
            let imgHtml = html.match(/<img.*?(?:>|\/>)/g)
            let videoHtml = html.match(/<video.*?(?:>|\/>)/g)
            if (imgHtml) {
              let imgSrc = imgHtml[0].match('<img[^<>]*? src="([^<>]*?)"')
              item.materialContentRpcResponse.materialUrl = imgSrc[1]
              item.urlType = 'img'
              item.imgCount = imgHtml.length
            }
            if (videoHtml) {
              let videoSrc = videoHtml[0].match('<video[^<>]*? src="([^<>]*?)"')
              item.materialContentRpcResponse.materialUrl = videoSrc[1]
              item.urlType = 'video'
            }
          }
          tableData.push(item)
        })
        this.materialTableData = tableData
        this.tableTotal = res.length
        this.$refs.materialRef.tableHeightValues = this.tableHeight
        // res.length ? (this.$refs.materialRef.tableHeightValues = this.tableHeight) : (this.$refs.materialRef.tableHeightValues = '230px')
      })
    },
    // 获取所有素材
    getListApi() {
      var params = this.getParams()
      // params.pageSize = this.$refs.materialRef.page.pageSize
      // params.pageNum = this.$refs.materialRef.page.pageNum
      params.pageSize = 1000000
      params.pageNum = 1
      params.groupId = ''
      this.getTableList(params)
      this.materialGroupName = '全部素材'
      // })
    },
    // 点击素材组获取素材组素材
    getList(params, item) {
      this.materialGroupName = item.materialGroupName
      this.getTableList(params)
    },
    // 功能介绍弹框
    showIntroductionDialog() {
      this.introductionDialog = true
    },
    closeIntroductDia(val) {
      this.introductionDialog = false
    },
    // 二次确认
    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis[apiModule][apiName](apiParams).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : '操作失败',
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                fn && fn()
                this.getListApi()
              }
            })
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.videoMask {
  position: absolute;
  display: flex;
  background: rgba(101, 101, 101, 0.6);
  color: #ffffff;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  img {
    position: relative;
    align-self: center;
    margin: auto;
  }
  span {
    position: absolute;
    top: 12px;
    right: 15px;
  }
}
.urlContent {
  margin-right: 8px;
  position: relative;
  width: 36px;
  height: 36px;
}
.search-form,
.left,
.right {
  background-color: #fff;
}
.el-popover {
  min-width: 100px;
}
.main-container {
  height: 100%;
  .top {
    display: inline-flex;
    span {
      margin-left: 16px;
      font-size: 16px;
      color: #5850ff;
    }
  }
}
ul {
  text-align: center;
  li {
    list-style: none;
    &:first-child {
      padding-bottom: 10px;
    }
  }
}
.container {
  margin-top: 10px;
  height: 100%;
  .search-form {
    padding: 20px 0 0 20px;
  }
  .tabelList {
    margin-top: 10px;
    height: 100%;
    .left {
      height: 100%;
      position: relative;
      border-right: 1px solid #e8e8ea;
    }
    .right {
      // overflow: auto;
      .groupTitle {
        padding: 20px 0 16px 19px;
        font-weight: 600;
      }
      .glsx-table {
        margin: 0 20px;
      }
    }
  }
}
.btn-more {
  margin-left: 10px;
}
.material-content {
  display: flex;
  align-items: center;
  // justify-content: space-between;
  .hide-content {
    text-align: left;
    display: inline-block;
    min-width: 100px;
    // max-width: 220px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  img {
    width: 36px;
    height: 36px;
  }
}
.img-plus {
  width: 200px;
  height: 200px;
}
.introduc-word {
  font-size: 14px;
  margin-left: 16px;
  color: #5850ff;
}
.pdf-title {
  text-align: right !important;
}
/deep/ .el-table .ascending .sort-caret.ascending {
  border-bottom-color: #5850ff;
}
/deep/ .el-table .descending .sort-caret.descending {
  border-top-color: #5850ff;
}
.select-pro {
  display: inline-block;
  padding-bottom: 20px;
}
/deep/ .el-switch__core {
  width: 32px !important;
}
/deep/ .el-table::before {
  background-color: transparent;
}
/deep/ .el-table__fixed-right::before {
  background-color: transparent;
}
</style>