materialModel.vue 11.9 KB
<!-- 素材弹窗 -->
<template>
  <glsx-dialog title="选择素材" :isVisible.sync="isMaterialVisible" width="1088px" @confirmDialog="handleMaterialConfirm" @closeDialog="handleMaterialClose" class="relateStore">
    <GLCombiForm ref="showSearch" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
    <div class="model-panel">
      <div class="model-item-panel" v-if="modelList.length > 0" v-loading="loading">
        <div class="model-item" :class="{ checked: selectItem.id == item.id }" v-for="(item, index) in modelList" :key="index" @click="handleSelectItem(item)">
          <el-tooltip effect="dark" placement="top" :content="item.materialContentRpcResponse.materialName" :disabled="item.materialContentRpcResponse.materialName.length < 16">
            <!-- <span class="hide-content">{{ item.materialContentRpcResponse.materialName }}</span> -->
            <div class="model-item-title" :title="item.materialContentRpcResponse.materialName">{{ item.materialContentRpcResponse ? item.materialContentRpcResponse.materialName : '-' }}</div>
          </el-tooltip>
          <!-- <img :src="item.materialContentRpcResponse.materialUrl" /> -->
          <!-- 素材内容 -->
          <!-- <div slot="materialContentRpcResponse" slot-scope="scope" style="text-align: center"> -->
          <!-- 素材为PDF -->
          <span v-if="item.materialType == 1" class="material-content">
            <!-- <el-tooltip effect="dark" placement="top" :content="item.materialContentRpcResponse.materialName" :disabled="item.materialContentRpcResponse.materialName.length < 16">
              <span class="hide-content">{{ item.materialContentRpcResponse.materialName }}</span>
            </el-tooltip> -->
            <img class="img-pdf" src="@/assets/material/pdf.png" alt="" />
            <p class="model-item-content">{{ item.materialContentRpcResponse.materialName }}.png</p>
          </span>
          <!-- 素材为自定义链接 -->
          <!-- <span v-if="item.materialType == 2"></span> -->
          <!-- 图文 -->
          <span v-if="item.materialType == 3" class="material-content">
            <!-- <el-tooltip effect="dark" placement="top" :content="item.materialContentRpcResponse.materialName" :disabled="item.materialContentRpcResponse.materialName.length < 16">
              <span>{{ item.materialContentRpcResponse.materialName }}</span>
            </el-tooltip> -->
            <!-- <el-popover placement="top" trigger="click">
              <div>
                <img style="width: 72px; height: 72px;" v-if="item.materialContentRpcResponse.materialUrl" :src="item.materialContentRpcResponse.materialUrl" alt="" />
                <img class="img-material" v-else src="@/assets/material/car.png" alt="" />
              </div>
              <span slot="reference">
                <img v-if="item.materialContentRpcResponse.materialUrl" class="img-material" :src="item.materialContentRpcResponse.materialUrl" />
                <img v-else class="img-material" src="@/assets/material/car.png" alt="" />
              </span>
            </el-popover> -->
            <img v-if="item.materialContentRpcResponse.materialUrl" class="img-material" :src="item.materialContentRpcResponse.materialUrl" />
            <img v-else class="img-material" src="@/assets/material/car.png" alt="" />
          </span>
        </div>
        <!-- </div> -->
      </div>
      <div class="model-item-empty" v-else v-loading="loading">
        <img src="@/assets/img/empty.png" />
        <div class="empty-item">暂无数据</div>
      </div>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[12, 24, 36, 48]" :page-size="pageSize" :total="tableTotal" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    </div>
  </glsx-dialog>
</template>

<script>
import glsxDialog from '@/components/glsx-dialog'
export default {
  name: 'materialModel',
  data() {
    return {
      searchForm: {
        groupId: '',
        materialType: ''
      },
      searchFormData: [
        {
          label: '素材分组',
          name: 'groupId',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'materialGroupName',
          optionsName: 'groupList'
        },
        {
          label: '素材类型',
          name: 'materialType',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'materialTypeList'
        }
      ],
      //   selectedData: [],
      //   selectingData: [],
      // needTip: ['editProduct'],
      modelList: [],
      selectItem: {
        id: ''
      },
      // 分页
      pageNum: 1,
      pageSize: 12,
      tableTotal: 0,
      baseData: {
        groupList: [],
        materialTypeList: [
          {
            confId: 1,
            confName: 'PDF'
          },
          // {
          //   confId: 2,
          //   confName: '自定义链接'
          // },
          {
            confId: 3,
            confName: '图文'
          }
        ]
      }
    }
  },

  props: {
    isMaterialVisible: {
      type: Boolean,
      default: false
    }
  },

  components: {
    glsxDialog
  },

  created() {
    this.getBaseData()
  },

  mounted() {
    this.getModelList()
  },

  methods: {
    getBaseData() {
      this.$apis.sop.getGroupListApi({}).then(res => {
        this.baseData.groupList = res
        this.getOptionsList('searchFormData')
      })
    },
    handleSelectItem(item) {
      this.selectItem = item
    },
    getModelList() {
      var params = {
        ...this.searchForm,
        status: 0,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      this.$apis.sop.getMaterialListApi(params).then(res => {
        this.modelList = res.data
        this.tableTotal = res.count
        let tableData = []
        this.modelList.forEach(item => {
          if (item.materialType != 3) {
            item.materialContentRpcResponse.materialUrl = ''
          }
          if (item.materialType == 3) {
            let html = decodeURIComponent(item.materialContentRpcResponse.materialUrl)
            let imgHtml = html.match(/<img.*?(?:>|\/>)/g)
            if (imgHtml) {
              let imgSrc = imgHtml[0].match('<img[^<>]*? src="([^<>]*?)"')
              item.materialContentRpcResponse.materialUrl = imgSrc[1]
            } else {
              item.materialContentRpcResponse.materialUrl = ''
            }
          }
          tableData.push(item)
        })
      })
    },
    handleReset() {
      this.searchForm = {
        groupId: '',
        materialType: ''
      }
      this.handleSearch()
    },
    handleSearch() {
      this.pageNum = 1
      this.getModelList()
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getModelList()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.getModelList()
    },
    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    handleMaterialConfirm() {
      this.$emit('handleMaterialConfirm', {
        objectId: this.selectItem.id,
        objectType: 10,
        objectName: this.selectItem.materialContentRpcResponse.materialName,
        additionalType: 1
      })
    },
    handleMaterialClose() {
      this.$emit('handleMaterialClose')
    }
  }
}
</script>
<style lang="scss" scoped>
.relateStore {
  /deep/ {
    .gl-operate {
      margin-left: 10px;
    }
  }
}
.model-panel {
  .model-panel-tab {
    display: flex;
    align-items: center;
    margin-bottom: 18px;
    label {
      font-size: 16px;
      font-weight: 400;
      color: #000000;
      line-height: 24px;
    }
    /deep/ {
      .el-checkbox:last-of-type {
        margin-right: 8px;
      }
      .el-tabs__nav {
        border: 0;
      }
      .el-tabs__header {
        border: 0;
        background-color: #f4f6fc;
        margin: 0px;
      }
      .el-tabs__item {
        border: none;
        width: 180px;
        height: 32px;
        line-height: 32px;
        margin: 2px;
        text-align: center;
      }
      .el-tabs__item.is-active {
        background-color: #fff;
        border-radius: 4px;
        font-weight: 600;
      }
      .el-pagination {
        padding: 5px;
      }
    }
  }
  .model-item-empty {
    > img {
      display: block;
      margin: 50px auto 0px;
      width: 60px;
      height: auto;
    }
    .empty-item {
      text-align: center;
      font-size: 14px;
      font-weight: 400;
      color: #000000;
      line-height: 22px;
      margin-bottom: 30px;
    }
  }
  .model-item-panel {
<<<<<<< HEAD
    display: grid;
    grid-template-columns: repeat(4, 25%);
    grid-row-gap: 10px;
=======
    // display: grid;
    // grid-template-columns: repeat(4, 25%);
    // grid-row-gap: 10px;
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
    max-height: 38vh;
    overflow: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    flex-direction: row;
    .model-item {
<<<<<<< HEAD
      width: 100%;
      // margin-right: 24px;
=======
      width: 240px;
      margin-right: 24px;
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
      margin-bottom: 24px;
      padding: 12px 16px;
      position: relative;
      text-align: center;
      // height: 128px;
      background: #ffffff;
      border-radius: 4px;
      border: 1px solid #e6e6e6;
      padding: 14px 24px;
      box-sizing: border-box;
      &:nth-child(4n) {
        margin-right: 0px;
      }
      &.checked {
        background: rgba(88, 80, 255, 0.1);
        border: 1px solid #5850ff;
      }
      &-qrcode {
        position: absolute;
        right: 10px;
        bottom: 10px;
        width: 60px;
        height: 60px;
        border: 1px solid #979797;
      }
      &-title {
        font-size: 18px;
        font-weight: 600;
        color: #333333;
        line-height: 25px;
        margin-bottom: 5px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
      .img-pdf {
        width: 40px;
        height: 40px;
        margin-top: 10px;
      }
      .img-material {
        width: 72px;
        height: 72px;
      }
      &-content {
        font-size: 12px;
        font-weight: 400;
        color: #666666;
        line-height: 16px;
        height: 16px;
        margin-top: 6px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        &.model-item-weight {
          line-height: 20px;
          height: 20px;
        }
        span {
          color: #5850ff;
          font-size: 20px;
        }
      }
      &-contents {
        line-height: 22px;
        height: 22px;
      }
    }
  }
}
</style>