cm-product-doc.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <template>
  2. <view class="product-doc hasBottom" :style="{ paddingBottom: isIphoneX ? '60rpx' : 0 }">
  3. <view class="category">
  4. <view class="category-title">图片资料</view>
  5. <view class="content">
  6. <view class="cm-none" v-if="imageArchiveList.length === 0">暂无相关资料</view>
  7. <template v-else>
  8. <view class="section" v-for="(item, index) in imageArchiveList" :key="index">
  9. <view class="cm-title">{{ item.title }}</view>
  10. <view class="cm-time">{{ $reg.formatDate('', item.addTime) }}</view>
  11. <view class="cm-img-list cm-list">
  12. <template v-if="item.imageList">
  13. <image
  14. :src="image.url"
  15. @click="previewImage(i, item.imageList)"
  16. mode="aspectFill"
  17. v-for="(image, i) in imageFormat(item.imageList)"
  18. :key="i"
  19. :style="image.style"
  20. ></image>
  21. </template>
  22. <template v-else>
  23. <image
  24. :src="defaultImage"
  25. mode="aspectFill"
  26. v-for="i in item.imageNum"
  27. :key="i"
  28. @click="checkPermission"
  29. ></image>
  30. </template>
  31. </view>
  32. </view>
  33. </template>
  34. </view>
  35. </view>
  36. <view class="category">
  37. <view class="category-title">视频资料</view>
  38. <view class="content">
  39. <view class="cm-none" v-if="videoArchiveList.length === 0">暂无相关资料</view>
  40. <template v-else>
  41. <view class="section" v-for="(item, index) in videoArchiveList" :key="index">
  42. <view class="cm-title">{{ item.title }}</view>
  43. <view class="cm-time">{{ $reg.formatDate('', item.addTime) }}</view>
  44. <view class="cm-video-list">
  45. <video
  46. :id="'myVideo' + index"
  47. :src="item.fileUrl"
  48. controls
  49. show-fullscreen-btn
  50. show-mute-btn
  51. play-btn-position="center"
  52. @play="handlePlayer('myVideo' + index)"
  53. v-if="item.fileUrl"
  54. ></video>
  55. <view class="cm-video-section" v-else>
  56. <image class="cm-video-cover" :src="videoCover"></image>
  57. <text class="cm-player-btn" @click="checkPermission()"></text>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. </view>
  63. </view>
  64. <view class="category cm-file">
  65. <view class="category-title">文件资料</view>
  66. <view class="content">
  67. <view class="cm-none" v-if="fileArchiveList.length === 0">暂无相关资料</view>
  68. <template v-else>
  69. <view class="section" v-for="(item, index) in fileArchiveList" :key="index">
  70. <image
  71. src="https://static.caimei365.com/app/img/icon2/PDF-app.png"
  72. v-if="/\.pdf$/.test(item.fileName)"
  73. ></image>
  74. <image
  75. src="https://static.caimei365.com/app/img/icon2/DOC-app.png"
  76. v-else-if="/\.doc$/.test(item.fileName)"
  77. ></image>
  78. <image src="https://static.caimei365.com/app/img/icon2/PPT-app.png" v-else></image>
  79. <view class="cm-desc">
  80. <view class="cm-title">{{ item.title }}</view>
  81. <view class="cm-bottom">
  82. <view class="cm-time">{{ $reg.formatDate('', item.addTime) }}</view>
  83. <view class="cm-preview" @click="previewFile(item)">预览文件</view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. </view>
  89. </view>
  90. <view
  91. class="cm-login"
  92. :class="{ maxBottom: !bottom && isIphoneX }"
  93. :style="{ bottom: bottom }"
  94. v-if="TipStatus"
  95. >
  96. <text>{{ TipStatus.text }}</text>
  97. <view class="cm-btn" @click="nextAction(TipStatus.redirect)">{{ TipStatus.btn }}</view>
  98. </view>
  99. <tui-modal
  100. :show="showModal"
  101. :content="TipStatus.text"
  102. shape="circle"
  103. :button="modalButton"
  104. fadeIn
  105. @click="handleModalClick"
  106. ></tui-modal>
  107. </view>
  108. </template>
  109. <script>
  110. import { mapState } from 'vuex'
  111. export default {
  112. props: {
  113. product: {
  114. type: Object,
  115. default: () => {}
  116. },
  117. archiveId: {
  118. type: Number,
  119. default: 0
  120. },
  121. bottom: {
  122. type: String,
  123. default: ''
  124. }
  125. },
  126. data() {
  127. return {
  128. userId: -1,
  129. prevVideoId: '',
  130. currentVideoId: '',
  131. videoContexts: [],
  132. modalButton: [
  133. {
  134. text: '取消',
  135. type: 'gray',
  136. plain: true //是否空心
  137. },
  138. {
  139. text: '确认',
  140. customStyle: {
  141. color: '#fff',
  142. bgColor: 'linear-gradient(90deg, #F28F31 0%, #E15616 100%)'
  143. },
  144. plain: false
  145. }
  146. ],
  147. showModal: false,
  148. //用户信息相关
  149. permission: 5, //用户权限 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  150. imageArchiveList: [], // 图片资料列表
  151. videoArchiveList: [], // 视频资料列表
  152. fileArchiveList: [], // 文件资料列表
  153. defaultImage: 'https://static.caimei365.com/app/img/icon2/PC-default.png', // 默认图片
  154. videoCover: 'https://static.caimei365.com/app/img/icon2/video-cover.png' //默认视频封面
  155. }
  156. },
  157. computed: {
  158. ...mapState(['isIphoneX']),
  159. //资料查看状态提示
  160. TipStatus: function() {
  161. // 资料权限
  162. const statusText = [
  163. false, // 正常访问
  164. { text: '请登录后查看!', btn: '去登录', redirect: '/pages/login/login' },
  165. { text: '请升级成为会员机构后方可查看!', btn: '去升级', redirect: '/pages/login/apply' },
  166. { text: '请升级成为医美会员机构后方可查看!', btn: '去升级', redirect: '/pages/login/apply' },
  167. { text: '需抵扣100采美豆方可查看!', btn: '去查看', redirect: 10 },
  168. { text: '无权限查看!', btn: '' }
  169. ]
  170. // 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  171. return statusText[this.permission]
  172. }
  173. },
  174. created() {
  175. this.userId = uni.getStorageSync('userInfo').userId || -1
  176. this.getDetail()
  177. },
  178. methods: {
  179. // 获取商品资料详情
  180. getDetail() {
  181. this.BeautyArchive.GetProdcutArchiveDetails({
  182. userId: this.userId,
  183. archiveId: this.archiveId
  184. }).then(res => {
  185. this.imageArchiveList = res.data.imageArchiveList
  186. this.videoArchiveList = res.data.videoArchiveList
  187. this.fileArchiveList = res.data.fileArchiveList
  188. this.permission = res.data.permission
  189. })
  190. },
  191. //采美豆抵扣
  192. searchArchiveByBean() {
  193. this.BeautyArchive.SearchArchiveByBeans({
  194. userId: this.userId,
  195. archiveId: this.archiveId
  196. })
  197. .then(res => {
  198. uni.showToast({
  199. duration: 1500,
  200. title: res.msg
  201. })
  202. setTimeout(()=>{
  203. //刷新资料列表
  204. this.getDetail()
  205. },1500)
  206. })
  207. .catch(err => {
  208. uni.showToast({
  209. icon:'none',
  210. duration: 1500,
  211. title: err.msg
  212. })
  213. })
  214. },
  215. // 视频播放
  216. handlePlayer(id) {
  217. if (this.checkPermission()) {
  218. this.handleStop(id)
  219. return
  220. }
  221. if (this.prevVideoId === id) return
  222. // this.handleFullScreen(id) // 点击播放时全屏
  223. this.prevVideoId = this.currentVideoId
  224. // 暂停上一个播放器
  225. this.handelPause(this.prevVideoId)
  226. // 保存当前播放器id
  227. this.currentVideoId = id
  228. },
  229. // 开始播放
  230. handelPlay(id) {
  231. if (!id) return
  232. const vContext = uni.createVideoContext(id, this)
  233. vContext.play()
  234. },
  235. // 暂停播放
  236. handelPause(id) {
  237. if (!id) return
  238. const vContext = uni.createVideoContext(id, this)
  239. vContext.pause()
  240. },
  241. // 停止视频
  242. handleStop(id) {
  243. if (!id) return
  244. const vContext = uni.createVideoContext(id, this)
  245. vContext.stop()
  246. },
  247. // 进入全屏
  248. handleFullScreen(id) {
  249. if (!id) return
  250. const vContext = uni.createVideoContext(id, this)
  251. vContext.requestFullScreen()
  252. },
  253. // 预览图片
  254. previewImage(index, previewImageList) {
  255. if (this.checkPermission()) return
  256. const that = this
  257. uni.previewImage({
  258. current: index,
  259. indicator: 'number',
  260. urls: previewImageList,
  261. loop: true,
  262. success() {
  263. that.$emit('previewImage', true)
  264. }
  265. })
  266. },
  267. //用户权限校验拦截
  268. checkPermission() {
  269. //permission:查看权限:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  270. const _self = this
  271. // 如果 TipStatus 返回false 就放行
  272. if (!_self.TipStatus) return 0
  273. this.modalButton[1].text = this.TipStatus.btn
  274. this.showModal = true
  275. return -1
  276. },
  277. // modal 按钮点击
  278. handleModalClick(e) {
  279. // 点击确认按钮
  280. if (e.index === 1) {
  281. this.showModal = false
  282. this.nextAction(this.TipStatus.redirect) //执行下一步
  283. } else {
  284. this.showModal = false
  285. }
  286. },
  287. //图片列表处理
  288. imageFormat(list) {
  289. const imageList = []
  290. if (list.length > 2) {
  291. list.forEach((item, index) => {
  292. imageList.push({ url: item, style: '' })
  293. })
  294. }
  295. if (list.length === 1) {
  296. try {
  297. const strArr = list[0]
  298. .split('?')[1]
  299. .replace(/\&|\=/g, '-')
  300. .split('-')
  301. const w = strArr[1] // 图片长
  302. const h = strArr[3] // 图片高
  303. let style = ''
  304. if (w > h) {
  305. style = `width:600rpx;height:${(600 / w) * h}rpx`
  306. } else {
  307. style = `height:600rpx;width:${(600 * w) / h}rpx`
  308. }
  309. imageList.push({ url: list[0], style: style })
  310. } catch (e) {
  311. console.error(
  312. '图片链接格式不正确,返回未处理图片,请设置正确的链接:http://image/text.png?width=xx&height=xx'
  313. )
  314. imageList.push({ url: list[0], style: '' })
  315. }
  316. }
  317. if (list.length === 2) {
  318. const style = 'width:300rpx;height:300rpx;'
  319. imageList.push({ url: list[0], style })
  320. imageList.push({ url: list[1], style })
  321. }
  322. return imageList
  323. },
  324. // 点击按钮后要做的事
  325. nextAction(redirect) {
  326. const _self = this
  327. if (typeof redirect == 'string') {
  328. // 跳转链接
  329. this.$api.navigateTo(redirect)
  330. }
  331. if (redirect === 10) {
  332. this.searchArchiveByBean()
  333. }
  334. },
  335. // 文件预览
  336. previewFile(file) {
  337. if (this.checkPermission()) return
  338. //先将链接缓存
  339. uni.setStorageSync('openLink', file.fileUrl)
  340. // 获取文件后缀
  341. const index = file.fileName.lastIndexOf('.')
  342. const suffix = file.fileName.substring(index)
  343. if (suffix === '.doc' || suffix === '.ppt') {
  344. this.$api.navigateTo('/pages/h5/article/path?key=openLink&type=1')
  345. } else if (suffix === '.pdf') {
  346. this.$api.navigateTo('/pages/h5/article/path?key=openLink&type=2')
  347. } else {
  348. // 不支持的文件
  349. return uni.showModal({
  350. content: `${suffix}类型文件暂不支持预览`,
  351. cancelColor: '#666',
  352. confirmColor: '#E15616'
  353. })
  354. }
  355. }
  356. }
  357. }
  358. </script>
  359. <style lang="scss" scoped>
  360. .product-doc {
  361. background: #f7f7f7;
  362. }
  363. .hasBottom {
  364. padding-bottom: 90rpx;
  365. }
  366. .cm-login {
  367. position: fixed;
  368. left: 24rpx;
  369. bottom: 115rpx; // 包含商品导航
  370. display: flex;
  371. justify-content: space-between;
  372. align-items: center;
  373. padding: 0 32rpx;
  374. width: 702rpx;
  375. height: 90rpx;
  376. background: #ffe6dc;
  377. border-radius: 16px;
  378. box-sizing: border-box;
  379. &.maxBottom {
  380. bottom: 175rpx;
  381. }
  382. text {
  383. font-size: 26rpx;
  384. color: #e15616;
  385. }
  386. .cm-btn {
  387. width: 136rpx;
  388. height: 48rpx;
  389. background: #e15616;
  390. border-radius: 28px;
  391. font-size: 26rpx;
  392. text-align: center;
  393. line-height: 48rpx;
  394. color: #ffffff;
  395. }
  396. }
  397. .category {
  398. padding: 0 24rpx;
  399. margin-bottom: 20rpx;
  400. background: #fff;
  401. .cm-video-section {
  402. position: relative;
  403. width: 702rpx;
  404. height: 402rpx;
  405. .cm-video-cover {
  406. width: 702rpx;
  407. height: 402rpx;
  408. }
  409. .cm-player-btn {
  410. position: absolute;
  411. left: 50%;
  412. top: 50%;
  413. transform: translate(-50%, -50%);
  414. z-index: 5;
  415. width: 56rpx;
  416. height: 56rpx;
  417. background: url(https://static.caimei365.com/app/img/icon2/H5-plalyer.png) center no-repeat;
  418. background-size: 56rpx 56rpx;
  419. }
  420. }
  421. .category-title {
  422. padding-top: 24rpx;
  423. padding-bottom: 8rpx;
  424. font-size: 28rpx;
  425. font-weight: 500;
  426. color: #333333;
  427. border-bottom: 1px solid #f0f0f0;
  428. }
  429. .cm-none {
  430. height: 37rpx;
  431. margin: 24rpx 0 0 0;
  432. padding-bottom: 48rpx;
  433. font-size: 26rpx;
  434. font-weight: 400;
  435. line-height: 37rpx;
  436. color: #333333;
  437. }
  438. &.cm-file {
  439. .section {
  440. display: flex;
  441. justify-content: space-between;
  442. align-items: center;
  443. image {
  444. width: 88rpx;
  445. height: 88rpx;
  446. }
  447. .cm-title {
  448. height: 74rpx;
  449. }
  450. .cm-desc {
  451. width: 582rpx;
  452. }
  453. .cm-bottom {
  454. display: flex;
  455. justify-content: space-between;
  456. align-items: center;
  457. padding: 16rpx 0 0;
  458. .cm-preview {
  459. font-size: 26rpx;
  460. font-weight: 400;
  461. color: #e15616;
  462. }
  463. .cm-time {
  464. padding: 0;
  465. }
  466. }
  467. }
  468. }
  469. .section {
  470. padding-bottom: 24rpx;
  471. border-bottom: 1px solid #f0f0f0;
  472. &:last-child {
  473. border-bottom: 0;
  474. }
  475. .cm-title {
  476. display: -webkit-box;
  477. max-height: 74rpx;
  478. margin-top: 24rpx;
  479. font-size: 26rpx;
  480. font-weight: 400;
  481. line-height: 1.5;
  482. color: #333333;
  483. -webkit-box-orient: vertical;
  484. -webkit-line-clamp: 2;
  485. overflow: hidden;
  486. word-break: break-all;
  487. text-align: justify;
  488. }
  489. .cm-time {
  490. padding: 8rpx 0;
  491. font-size: 22rpx;
  492. font-weight: 400;
  493. color: #b2b2b2;
  494. }
  495. .cm-img-list {
  496. display: flex;
  497. justify-content: flex-start;
  498. flex-wrap: wrap;
  499. &.cm-list {
  500. image {
  501. width: 162rpx;
  502. height: 162rpx;
  503. margin: 18rpx 18rpx 0 0;
  504. box-sizing: border-box;
  505. border-radius: 6rpx;
  506. border: 1px solid #e1e1e1;
  507. &:nth-child(4n) {
  508. margin-right: 0;
  509. }
  510. }
  511. }
  512. &.cm-one {
  513. max-width: 400rpx;
  514. max-height: 400rpx;
  515. image {
  516. box-sizing: border-box;
  517. border-radius: 6rpx;
  518. border: 1px solid #e1e1e1;
  519. }
  520. }
  521. }
  522. .cm-video-list {
  523. margin-top: 18rpx;
  524. width: 702rpx;
  525. height: 420rpx;
  526. video {
  527. width: 100% !important;
  528. max-width: 100%;
  529. min-width: 100%;
  530. display: flex;
  531. max-height: 420rpx;
  532. // width: 100%;
  533. // height: 100%;
  534. background: #000;
  535. }
  536. }
  537. }
  538. }
  539. </style>