index.vue 8.22 KB
<template>
  <div class="layout">
    <div class="top-box">
      <template v-if="userInfo.staffAvatar">
        <div class="avatar text-center">
          <img :src="userInfo.staffAvatar" />
        </div>
      </template>
      <template v-else>
        <div class="sprite-icon icon-default-avatar"></div>
      </template>
      <div class="name text-hide">Hi {{userInfo.userName}}</div>
      <div class="text">营销素材发给客户后,客户的阅读行为将会<br />主动通知你,系统并自动给客户打上指定标签</div>
      <search-box
        @search="search"
        :keyword="materialName"
        :showDropdown="false"
        placeholder="输入关键词"
        @focus="focus"
      ></search-box>
    </div>
    <div class="content">
      <template v-if="flag">
        <template v-if="nothing">
          <scroll-view
            :class="['list-box']"
            @ReachBottom="onReachBottom"
            ref="scrollView"
          >
            <div :class="['box',{'search-style':searchStyle}]">
              <template v-if="!searchStyle">
                <template v-for="(i,index) in list">
                  <div
                    :key="index"
                    class="item"
                    @click="jump(i.id)"
                  >
                    <img
                      class="bg"
                      :src="itemBgUrl[index % 2 == 0 ? 0: 1]"
                    />
                    <div class="text">
                      <div class="name text-hide">{{i.materialGroupName}}</div>
                      {{i.materialNum || 0}}
                    </div>
                  </div>
                </template>
              </template>
              <template v-else>
                <template v-if="list.materialGroupListRpcResponses && list.materialGroupListRpcResponses.length">
                  <template v-for="i in list.materialGroupListRpcResponses">
                    <div
                      class="search-item"
                      :key="i.id"
                    >
                      <div
                        class="group flex"
                        @click="jump(i.id)"
                      >
                        <div class="sprite-icon icon-file"></div>
                        {{i.materialGroupName}}
                        <div class="arrow">
                          <img src="https://img01.glsx.com.cn/weapp/resource/scrm-mobile/psd/arrow.png" />
                        </div>
                      </div>
                    </div>
                  </template>
                </template>
                <template v-if="list.materialToCRpcResponses && list.materialToCRpcResponses.length">
                  <template v-for="i in list.materialToCRpcResponses">
                    <div
                      class="search-item"
                      :key="i.id"
                    >
                      <psd
                        :item="i"
                        @send="sendMessage"
                        @share="shareToExternalMoments"
                      />
                    </div>
                  </template>
                </template>
              </template>
            </div>
          </scroll-view>
        </template>
        <template v-else>
          <nothing
            class="nothing-box"
            image="https://img01.glsx.com.cn/weapp/resource/scrm-mobile/psd/index-nothing.png"
          >暂无可用素材组</nothing>
        </template>
      </template>
    </div>
    <!-- <div class="input-tab"></div> -->
  </div>
</template>

<script type='text/ecmascript-6'>
import Nothing from './Nothing'
import Psd from './Psd'
import { marketingApi } from '@/api'
import { shareMixin } from '@/mixins'
export default {
  name: '',
  mixins: [shareMixin],
  components: { Nothing, Psd },
  data () {
    return {
      itemBgUrl: [
        'https://img01.glsx.com.cn/weapp/resource/scrm-mobile/psd/item-1.png',
        'https://img01.glsx.com.cn/weapp/resource/scrm-mobile/psd/item-2.png'
      ],
      flag: false,
      list: [],
      userInfo: window.vm.getLocalStorage('dj_scrm_userInfo'),
      materialName: '',
      searchStyle: false,
      nothing: false
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    jump (groupId) {
      let { corpId } = this.getLocalStorage('dj_scrm_corpId')
      let query = `?groupId=${groupId}&sessionId=${this.getSessionId()}&corpId=${corpId}`
      let url = window.location.origin || `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`
      let path = ['prod', 'production'].includes(process.env.NODE_ENV)
        ? 'dj-scrm-wx-work-attachment-psd' //测试、生产
        : 'dj-scrm-wx-work-main-lwk' //本地调试(可变更)
      window.location.href = `/${path}/#/psd/list${query}`
    },
    onReachBottom (e) {
      this.$refs.scrollView.finished = true
    },
    search (e) {
      this.materialName = e
      this.getList()
    },
    focus () {
      /** */
    },
    getList () {
      this.flag = false
      this.list = []
      let { materialName } = this
      let target = 'getPsdGroupList'
      if (materialName) target = 'getPsdList'
      this.showLoading()
      marketingApi[target]({ materialName }).then(data => {
        this.searchStyle = materialName ? true : false
        console.log(materialName ? '素材列表' : '素材组', data)
        this.list = data
        this.hideLoading()
        this.flag = true
        this.nothing = materialName ? data.materialGroupListRpcResponses || data.materialToCRpcResponses : data.length
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.layout {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  .top-box {
    width: 375px;
    height: 222px;
    background: var(--themeColor);
    font-size: 14px;
    color: #ffffff;
    position: relative;
    .avatar {
      position: absolute;
      left: 24px;
      top: 17px;
      width: 40px;
      height: 40px;
      border-radius: 100%;
      overflow: hidden;
    }
    .icon-default-avatar {
      position: absolute;
      left: 20px;
      top: 13px;
      border-radius: 100%;
      overflow: hidden;
    }
    .name {
      padding: 17px 34px 8px 72px;
      font-size: 18px;
      font-weight: 600;
    }
    .text {
      padding-left: 72px;
    }
    /deep/.search-box {
      box-shadow: none;
    }
    /deep/.van-search {
      padding: 16px 24px 0;
      background: var(--themeColor);
    }
  }
  .content {
    position: relative;
    top: -69px;
    background: #f7f7f7;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    .list-box {
      height: calc(100vh - 180px);
      padding-bottom: 50px;
      box-sizing: border-box;
      .box {
        display: grid;
        grid-template-columns: repeat(2, 152px);
        justify-content: space-between;
        gap: 20px 0;
        box-sizing: border-box;
        padding: 24px;
      }
      .search-style {
        display: block;
        padding: 16px;
        .search-item {
          margin-bottom: 10px;
          .group {
            height: 54px;
            background: #ffffff;
            box-shadow: 0px 3px 10px 0px rgba(223, 228, 234, 0.81);
            border-radius: 4px;
            margin-bottom: 10px;
            box-sizing: border-box;
            padding: 0 20px;
            font-size: 12px;
            color: #333333;
            .sprite-icon {
              margin-right: 10px;
            }
            .arrow {
              margin-left: auto;
              width: 7px;
              height: 10px;
            }
          }
        }
      }
      .item {
        width: 155px;
        height: 155px;
        position: relative;
        font-size: 12px;
        color: #666666;
        .bg {
          position: absolute;
          left: 0;
          top: 0;
        }
        .text {
          position: relative;
          z-index: 2;
          padding: 89px 15px 0;
          .name {
            margin-bottom: 2.5px;
            font-size: 14px;
            color: #333333;
            font-weight: 600;
          }
        }
      }
    }
    .nothing-box {
      height: calc(100vh - 180px);
    }
  }
  .input-tab {
    width: 100%;
    height: 42.52px;
    background: #096;
    position: fixed;
    bottom: 50%;
    transform: translateY(-50%);
    left: 0;
    z-index: 2;
  }
}
</style>