chooseBook.vue 4.57 KB
<template>
  <div class="choose-book-page content-bg">
    <div class="modify-top"></div>
    <div class="belong-school">
      <template v-if="kg_id">
        <van-row align="center" justify="center" style="position: relative; top: 50%; transform: translateY(-50%);">
          <van-col span="2">
            <van-image v-if="kgInfo.logo" round width="2rem" height="2rem" lazy-load :src="kgInfo.logo" style="vertical-align: text-bottom;">
              <template v-slot:error>加载失败</template>
            </van-image>
            <van-image v-else round width="2rem" height="2rem" lazy-load :src="icon_avatar" style="vertical-align: text-bottom;">
              <template v-slot:error>加载失败</template>
            </van-image>
          </van-col>
          <van-col span="22">
            <p class="title">{{ kgInfo.name }}</p>
          </van-col>
        </van-row>
      </template>
    </div>
    <div style="position: relative;">
      <div class="ding left"></div>
      <div style="position: relative; z-index: 100;">
        <van-row>
          <van-col span="4"></van-col>
          <van-col span="16">
            <my-button type="custom" :custom-style="styleObject">幼儿园爱心书籍</my-button>
          </van-col>
          <van-col span="4"></van-col>
        </van-row>
      </div>
      <div class="ding right"></div>
    </div>
    <div class="book-list">
      <template v-for="(item, key) in kgInfo.book_list" :key="key">
        <book-card type="C" :item="item" @on-click="onClick(item)"></book-card>
      </template>
      <van-empty
        v-if="!kgInfo.book_list.length"
        class="custom-image"
        :image="no_image"
        description="暂无书籍信息"
      />
    </div>
    <div style="height: 1rem;"></div>
    <shortcut-fixed type="C" :item="shortcutItem"></shortcut-fixed>
  </div>
</template>

<script setup>
import Cookies from 'js-cookie'

import no_image from '@images/que-shuju@2x.png'
import icon_avatar from '@images/que-logo@2x.png'

import MyButton from '@/components/MyButton/index.vue'
import BookCard from '@/components/BookCard/index.vue'
import ShortcutFixed from '@/components/ShortcutFixed/index.vue'

import { bookFn } from '@/composables/useBookList.js'

import { ref, reactive, nextTick } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import _ from 'lodash'
import axios from '@/utils/axios';
import { Toast } from 'vant';

const $route = useRoute();
const $router = useRouter();

const { kg_id, kgInfo } = bookFn($route)

// 配置快捷跳转条
const shortcutItem = ref([]);
if (Cookies.get('userType') === 'client') {
  shortcutItem.value = ['home', 'me']
} else {
  shortcutItem.value = ['me']
}

// 自定义按钮颜色样式
const styleObject = reactive({
  backgroundColor: '#F4675A',
  color: '#FFFFFF',
  borderColor: '#F4675A'
})

// 跳转书籍详情页
const onClick = (item) => {
    /**
    * 获取默认儿童信息
    * @returns name, perf_id, kg_id
    */
    axios.get('/srv/?a=default_perf', {
      params: {
        book_id: item.id
      }
    })
    .then(res => {
      if (res.data.code === 1) {
        // 缓存缺省儿童信息
        Cookies.set('default_perf', JSON.stringify(res.data.data))
        $router.push({
          path: '/client/bookDetail',
          query: {
            id: item.id
          }
        });
      } else {
        console.warn(res);
        if (!res.data.show) return false;
        Toast({
          icon: 'close',
          message: res.data.msg
        });
      }
    })
    .catch(err => {
      console.error(err);
    });
}
</script>

<script>
import mixin from 'common/mixin';

export default {
  mixins: [mixin.init],
  data() {
    return {

    }
  },
  mounted() {

  },
  methods: {

  }
}
</script>

<style lang="less" scoped>
@import url('@css/content-bg.less');
:global(.custom-image .van-empty__image) {
  // margin-top: 15vh;
  width: 10vh;
  height: 10vh;
}
.choose-book-page {
  .belong-school {
    padding: 1.5rem;
    height: 3rem;
    .title {
      color: #222222;
      display: inline-block;
      vertical-align: super;
      margin-left: 1rem;
    }

  }

  .book-list {
    margin: 1rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 1);
    box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.13);
  }

  .ding {
    z-index: 69;
    position: absolute;
    top: 2.5rem;
    width: 1rem;
    height: 3rem;
    background-image: url('@images/ding-left@2x.png');
    background-size: contain;
    background-repeat: no-repeat;

    &.left {
      left: 8rem;
    }

    &.right {
      right: 8rem;
    }
  }
}
</style>