cm-product-doc.vue 22 KB

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