bookDetail.vue 10.6 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
<template>
  <div class="book-detail-page content-bg">
    <div class="modify-top"></div>
    <div class="book-detail">
      <div style="text-align: center;">
        <van-image width="220" height="220" :src="bookInfo.cover" />
      </div>
      <div class="book-intro">
        <p class="book-post">{{ bookInfo.name }}</p>
        <div id="book-intro" :class="{ 'van-multi-ellipsis--l3': isToggle }">{{ bookInfo.note }}</div>
        <div v-if="hasToggle">
          <div v-if="isToggle" @click="onToggle(false)" class="book-toggle-icon">展开&nbsp;
            <van-icon style="vertical-align: middle;" size="0.9rem" :name="icon_down" />
          </div>
          <div v-else @click="onToggle(true)" class="book-toggle-icon">折叠&nbsp;
            <van-icon style="vertical-align: middle;" size="0.9rem" :name="icon_up" />
          </div>
        </div>
      </div>

      <van-sticky>
        <div class="book-video-title">
          <van-row>
            <van-col span="12">
              作品演绎
              <div style="background-color: #F9D95C; width: 70px; height: 4px;"></div>
            </van-col>
            <van-col span="12">
              <div style="font-size: 1rem; color: #999999; text-align: right;">
                <van-icon :name="icon_video" />
                {{ bookInfo.total }}个作品
              </div>
            </van-col>
          </van-row>
        </div>
        <div class="book-video-language">
          <van-row>
            <van-col span="6">
              <div @click="toggleLanguage('mandarin')" :class="[checkMandarin ? 'checked' : 'uncheck']">普通话</div>
            </van-col>
            <van-col span="6">
              <div @click="toggleLanguage('localism')" :class="[checkLocalism ? 'checked' : 'uncheck']">方言</div>
            </van-col>
            <van-col span="12" v-if="checkLocalism" @click="showPicker = true">
              <div class="choose-wrapper">
                <div class="text">
                  &nbsp;{{ chooseLanguage.text }}
                </div>
                <div class="icon">
                  <van-icon name="arrow-down" />&nbsp;
                </div>
              </div>
            </van-col>
          </van-row>
          <van-popup v-model:show="showPicker" round position="bottom">
            <van-picker :columns="columns" :columns-field-names="{ text: 'text', value: 'val', children: 'children' }"
              @cancel="showPicker = false" @confirm="onConfirm" />
          </van-popup>
        </div>
      </van-sticky>

      <div class="book-video-list">
        <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
          <template v-for="item in prod_list" :key="item" style="height: 3rem;">
            <video-card :item="item"></video-card>
          </template>
        </van-list>
      </div>
    </div>
    <div style="height: 5rem;"></div>
    <div class="book-bar">
      <div @click="onSubscribe" class="text">
        <van-icon v-if="!bookInfo.is_subscribe" :name="icon_subscribed" size="1.25rem" style="margin: 0 auto;" />
        <van-icon v-else :name="icon_unsubscribe" size="1.25rem" style="margin: 0 auto;" />
        <span style="font-size: 0.85rem;">订阅</span>
      </div>
      <div class="button">
        <my-button @on-click="toDonate" type="plain">爱心捐书</my-button>
      </div>
      <div class="button">
        <my-button @on-click="uploadVideo" type="primary">上传作品</my-button>
      </div>
    </div>
    <shortcut-fixed type="C" :item="['home', 'me']"></shortcut-fixed>
  </div>

  <!-- 写评论时,如果没有实名认证提示弹框 -->
  <notice-overlay :show="showNotice" text="前往认证" @on-submit="onSubmit" @on-close="onClose">
    <div style="color: #333333;">
      <p>您还没有实名认证</p>
      <p>请前往个人中心进行实名认证</p>
    </div>
  </notice-overlay>

  <donate-book :showPopup="showDonate" :item="donateItem" @on-close="closeDonate"></donate-book>

</template>

<script setup>
import Cookies from 'js-cookie'
import { useVideoList } from '@/composables/useVideoList.js'

import MyButton from '@/components/MyButton/index.vue'
import VideoCard from '@/components/VideoCard/index.vue'
import NoticeOverlay from '@/components/NoticeOverlay/index.vue'
import DonateBook from '@/components/DonateBook/index.vue'

import icon_video from '@images/video.png'
import icon_up from '@images/icon-guanbi@2x.png'
import icon_down from '@images/icon-zhankai@2x.png'
import icon_subscribed from '@images/icon-dingyue01@2x.png'
import icon_unsubscribe from '@images/icon-dingyue02@2x.png'

import ShortcutFixed from '@/components/ShortcutFixed/index.vue'
import tools from '@/common/tool'
import { ref, reactive, onMounted, nextTick, onActivated } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from '@/utils/axios';
import $ from 'jquery'
import _ from 'lodash'
import { Toast } from 'vant';
const $route = useRoute();
const $router = useRouter();

const { toggleLanguage, onLoad, columns, prod_list, finished, loading, bookInfo, showPicker, checkLocalism, checkMandarin, onConfirm, chooseLanguage } = useVideoList($route);

// 判断是否显示简介的展开图标
const hasToggle = ref(false); // 判断是否有展开文字,默认没有
const isToggle = ref(true); // 判断展开状态,默认展开

/**
 * 展开/折叠
 * @param {*} v 
 */
const onToggle = (v) => {
  isToggle.value = v
}

onMounted(() => {
  // 判断是否显示简介的展开图标
  nextTick(() => {
    hasToggle.value = tools.hasEllipsis('book-intro');
  })
})

/**
 * 书籍订阅
 */
const onSubscribe = () => {
  axios.post('/srv/?a=add_subscribe', {
    book_id: $route.query.id
  })
    .then(res => {
      if (res.data.code === 1) {
        if (res.data.msg === 'add subscribe OK') {
          bookInfo.value.is_subscribe = true;
          Toast.success('订阅成功')
        } else {
          bookInfo.value.is_subscribe = false;
          Toast.success('取消订阅')
        }
      } else {
        console.warn(res);
        Toast({
          icon: 'close',
          message: res.data.msg
        });
      }
    })
    .catch(err => {
      console.error(err);
    })
}

/*************** 捐书模块START ***************/
const donateItem = ref({})
// 弹出捐赠弹框模块
const showDonate = ref(false);

const toDonate = () => {
  showDonate.value = true;
  // 捐书数据
  donateItem.value = {
    book_id: $route.query.id,
    avatar: bookInfo.value.cover,
    name: bookInfo.value.name,
    price: bookInfo.value.price
  }
}

const closeDonate = (v) => {
  showDonate.value = v;
}
/**********************************/

// 跳转个人中心
const onSubmit = () => {
  $router.push({
    path: '/me/index'
  });
}

/**
 * 上传作品回调
 */

// 未实名认证提示
const showNotice = ref(false)
const onClose = () => { // 关闭提示框回调
  showNotice.value = false;
}

const uploadVideo = () => {
  axios.get('/srv/?a=can_upload')
    .then(res => {
      if (res.data.code === 1) {
        // 实名认证标识
        if (res.data.data.can_upload) {
          // 已读隐私条例,直接跳转上传页面
          if (Cookies.get('privacy_notice')) {
            // x_field_1是金数据表单传入的参数,家长上传的格式为:book_id-perf_id,perf_id是当前缺省的儿童id
            let default_perf = Cookies.get('default_perf') ? JSON.parse(Cookies.get('default_perf')) : '';
            let str = `${$route.query.id}-${default_perf.perf_id}`
            location.href = `https://jinshuju.net/f/NAGn1D?x_field_1=${str}`;
          } else {
            $router.push({
              path: '/client/privacyNotice'
            })
          }
        } else {
          // 如果没有实名认证需要提示用户实名认证
          showNotice.value = true;
        }
      } else {
        console.warn(res);
        Toast({
          icon: 'close',
          message: res.data.msg
        });
      }
    })
    .catch(err => {
      console.error(err);
    })
}

onActivated(() => { // keepAlive重置后执行回调
  onLoad()
});
</script>

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

export default {
  mixins: [mixin.init],
  data() {
    return {
    }
  },
  created() {
  },
  methods: {
  }
}
</script>

<style lang="less" scoped>
@import url('@css/content-bg.less');

.book-detail-page {
  // overflow: auto;

  .book-detail {
    margin: 1rem;
    // margin-top: 1.25rem;
    margin-top: 0;
    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);

    .book-intro {
      padding: 1rem;

      .book-post {
        color: #222222;
        font-size: 1.25rem;
        font-weight: bold;
      }

      #book-intro {
        color: #333333;
        margin-top: 0.25rem;
      }

      .book-toggle-icon {
        text-align: right;
        color: #713610;
        font-size: 1rem;
      }
    }

    .book-video-title {
      background-color: #F7F7F7;
      padding: 1rem 1.5rem;
    }

    .book-video-language {
      padding: 1rem;
      background-color: white;

      .uncheck {
        background: #F7F7F7;
        border-radius: 15px;
        padding: 0.5rem;
        text-align: center;
        color: #222222;
        margin: 0 0.25rem;
      }

      .checked {
        background: #F9D95C;
        border-radius: 15px;
        padding: 0.5rem;
        text-align: center;
        color: #222222;
        margin: 0 0.25rem;
      }

      .choose-wrapper {
        background: #F7F7F7;
        border-radius: 15px;
        padding: 0.5rem;
        text-align: center;
        color: #B0B0B0;
        margin: 0 0.25rem;

        .text {
          display: inline-block;
          text-align: left;
          width: 80%;
        }

        .icon {
          display: inline-block;
          text-align: right;
          width: 20%;
        }
      }
    }
  }

  .book-bar {
    z-index: 999;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    box-sizing: content-box;
    background-color: white;
    padding: 1rem;

    .text {
      display: flex;
      flex-direction: column;
      justify-content: center;
      min-width: 3rem;
      color: #713610;
      text-align: center;
    }

    .button {
      display: flex;
      flex-direction: column;
      justify-content: center;
      flex: 1;
      padding: 0 0.5rem;
    }
  }
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: auto;
  text-align: center;
}

.block {
  width: 80%;
  // height: 25rem;
  background-color: #fff;
  border-radius: 10px;
  padding: 1rem;
  position: relative;
  margin-top: 1rem;
  margin-bottom: 5rem;
}
</style>