AttachmentDownload.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <section class="attachment-download-container" v-if="renderAttachList.length">
  3. <div class="others-header flex flex-(items-center)">
  4. <div class="content-file-attachment-left flex flex-items-center">
  5. <span class="left-icon flex flex-items-center">
  6. <span class="file-attachment-text text-nowrap">附件下载</span>
  7. </span>
  8. <div class="right-content flex flex-items-center" v-if="canShowTip">
  9. <!-- 免费用户,无体验次数(没体验过) -->
  10. <template v-if="isFree && freeFileNum === 0">
  11. <span class="attachment-tag text-nowrap">
  12. <span class="attachment-tag-text">
  13. 免费用户享有{{ freeFileNum || 1 }}次附件下载权益
  14. </span>
  15. </span>
  16. </template>
  17. <!-- 免费用户,无体验次数(体验过) -->
  18. <template v-else-if="isFree && freeFileNum < 0">
  19. <span class="attachment-tag text-nowrap">
  20. <span class="attachment-tag-text">下载更多附件</span>
  21. <button class="open-vip-btn" @click="toBuySvip">
  22. 开通超级订阅
  23. </button>
  24. </span>
  25. </template>
  26. <!-- 新超级订阅,并且不是大会员(或者是大会员没有附件下载权限) -->
  27. <template v-else-if="isNewSuper && !memberHasAttachPower">
  28. <span class="attachment-tag text-nowrap">
  29. <span class="attachment-tag-text">本月剩余:{{ fileNum }}个</span>
  30. </span>
  31. <i class="iconfont icon-help" @click="fileDownloadHelp"></i>
  32. </template>
  33. </div>
  34. </div>
  35. <div class="content-file-attachment-actions" v-if="canShowTip">
  36. <span
  37. class="action-button"
  38. @click="chargeFilePack"
  39. v-if="isNewSuper && !memberHasAttachPower"
  40. >
  41. 立即充值
  42. </span>
  43. </div>
  44. </div>
  45. <div class="file-attachment-list">
  46. <div
  47. class="file-attachment-item highlight-text underline clickable"
  48. v-for="(attach, index) in renderAttachList"
  49. @click="startDownloadFile(attach)"
  50. :key="index"
  51. >
  52. {{ attach.name }}
  53. </div>
  54. </div>
  55. </section>
  56. </template>
  57. <script>
  58. import { mapState, mapGetters } from 'vuex'
  59. import { useGetContentAttachment } from '@/composables/attachment-download/'
  60. import { IsCustomTopNet, IsSunPublishContent } from '@/views/article-content/composables/useContentStore'
  61. export default {
  62. name: 'AttachmentDownload',
  63. props: {
  64. id: {
  65. type: String,
  66. required: true,
  67. default: ''
  68. },
  69. type: {
  70. type: String,
  71. default: ''
  72. },
  73. title: {
  74. type: String,
  75. required: true,
  76. default: ''
  77. },
  78. attachmentList: {
  79. type: Array,
  80. default() {
  81. return [
  82. // {
  83. // fileName: '附件1.pdf',
  84. // fileSize: '1.9 M',
  85. // fileType: 'pdf'
  86. // },
  87. // {
  88. // fileName: '附件2.pdf',
  89. // fileSize: '129 KB',
  90. // fileType: 'pdf'
  91. // }
  92. ]
  93. }
  94. }
  95. },
  96. data() {
  97. return {
  98. loading: false,
  99. attachment: {
  100. fileUrl: '', // 当前附件真实url
  101. file: {}, // 当前需要下载的附件信息
  102. downloaded: false
  103. },
  104. resourcePack: {
  105. exchangeNum: 0,
  106. freeNum: 0,
  107. grantNum: 0,
  108. name: '附件下载包',
  109. number: 0,
  110. purchaseNum: 0,
  111. resourceType: '附件下载包',
  112. thirtyNum: 0
  113. }
  114. }
  115. },
  116. computed: {
  117. ...mapGetters('user', [
  118. 'isFree',
  119. 'isSuper',
  120. 'isMember',
  121. 'bigMemberPower',
  122. 'isBusiness'
  123. ]),
  124. ...mapState({
  125. power: (state) => state.user.info
  126. }),
  127. // 免费用户免费体验次数
  128. freeFileNum() {
  129. if (this.resourcePack.number > 0) {
  130. return this.resourcePack.number
  131. } else {
  132. if (this.attachment.downloaded) {
  133. return -1
  134. } else {
  135. return this.power?.freeFile
  136. }
  137. }
  138. },
  139. fileNum() {
  140. return this.resourcePack.number
  141. },
  142. isNewSuper() {
  143. return this.power.viper && this.isSuper
  144. },
  145. memberHasAttachPower() {
  146. return this.isMember && this.bigMemberPower.indexOf(3) !== -1
  147. },
  148. renderAttachList() {
  149. return this.attachmentList.map((a) => {
  150. let size = a.fileSize
  151. return {
  152. name: a.fileName,
  153. size: size,
  154. type: a.fileType
  155. }
  156. })
  157. },
  158. canShowTip() {
  159. // 定制化用户不展示提示和留资
  160. if (IsCustomTopNet.value) {
  161. return false
  162. }
  163. if (IsSunPublishContent.value) {
  164. return false
  165. }
  166. return true
  167. }
  168. },
  169. created() {
  170. this.getInfo()
  171. },
  172. methods: {
  173. replaceSpace(n) {
  174. return n.trim().replace(/\s+/g, '')
  175. },
  176. async getInfo() {
  177. const { attachment } = useGetContentAttachment({ id: this.id })
  178. this.attachmentInstance = attachment
  179. await this.attachmentInstance.getResourcePackAccount()
  180. this.resourcePack = this.attachmentInstance.resourcePack
  181. },
  182. async refreshResourcePackCount() {
  183. if (!this.attachmentInstance) {
  184. return this.getInfo()
  185. }
  186. await this.attachmentInstance.getResourcePackAccount()
  187. this.resourcePack = this.attachmentInstance.resourcePack
  188. },
  189. showDialog(conf = {}) {
  190. const defaultConf = {
  191. title: '',
  192. message: '',
  193. customClass: 'custom-message-box',
  194. confirmButtonText: '我知道了',
  195. confirmButtonClass: 'custom-confirm-btn',
  196. cancelButtonClass: 'custom-cancel-btn',
  197. showClose: false,
  198. showCancelButton: false,
  199. closeOnClickModal: false,
  200. center: true
  201. }
  202. Object.assign(defaultConf, conf)
  203. return this.$confirm(defaultConf.message, defaultConf.title, defaultConf)
  204. },
  205. fileDownloadHelp() {
  206. this.$alert(
  207. '点击附件即为下载,系统会扣除当月附件下载个数;每月1号上月余额清零重新计算,请合理使用。',
  208. '',
  209. {
  210. confirmButtonText: '我知道了',
  211. confirmButtonColor: '#2ABDD1',
  212. showClose: false,
  213. center: true
  214. }
  215. )
  216. },
  217. async startDownloadFile(file) {
  218. // 定制化用户直接下载
  219. if (IsCustomTopNet.value) {
  220. return this.downloadFile(file)
  221. }
  222. if (IsSunPublishContent.value) {
  223. return this.downloadFile(file)
  224. }
  225. // 大客户直接下载
  226. if (location.pathname.indexOf('entservice') !== -1) {
  227. return this.downloadFile(file)
  228. }
  229. if (this.isFree) {
  230. // 免费用户
  231. // 判断有无体验过 0:未体验过
  232. if (this.freeFileNum === 0) {
  233. // TODO 判断有无留过资 且未体验过 - 去留资 source: 'article_attach_freeuser'
  234. this.$emit('doOpenCollect', {
  235. source: 'article_attach_freeuser',
  236. reload: true
  237. })
  238. } else if (this.freeFileNum < 0 && this.resourcePack.number <= 0) {
  239. // 免费用户 体验过 下载次数为-1 弹框提醒跳至超级订阅购买页
  240. // 并且剑鱼币兑换的附件下载权益没有余额
  241. return this.showDialog({
  242. title: '开通超级订阅',
  243. message:
  244. '您的免费【附件下载】次数已使用完,暂无免费查看权限。如需查看更多,请开通超级订阅获取更多权限。',
  245. showCancelButton: true,
  246. confirmButtonText: '去开通'
  247. })
  248. .then(() => {
  249. this.toBuySvip()
  250. })
  251. .catch(() => {})
  252. } else {
  253. // P317版本改为免费用户只要有下载次数,均可正常下载
  254. this.downloadFile(file)
  255. this.attachment.downloaded = true
  256. }
  257. } else {
  258. // 付费用户
  259. // 大会员用户 有下载个数
  260. if (this.memberHasAttachPower) {
  261. return this.downloadFile(file)
  262. }
  263. // 超级订阅用户
  264. if (this.isSuper) {
  265. // 新超级订阅用户
  266. if (this.isNewSuper) {
  267. // 是否用完弹窗放到请求之后,根据请求返回值进行判断
  268. return this.downloadFile(file)
  269. // if (this.fileNum > 0) {
  270. // this.downloadFile(file)
  271. // } else {
  272. // // 次数用完
  273. // return this.showDialog({
  274. // message:
  275. // '您本月附件下载机会已消耗完毕,如需下载更多附件,请前往充值。',
  276. // showCancelButton: true,
  277. // confirmButtonText: '立即充值'
  278. // })
  279. // .then(() => {
  280. // // this.concatKf()
  281. // this.chargeFilePack()
  282. // })
  283. // .catch(() => {})
  284. // }
  285. } else {
  286. // 老超级订阅用户 提醒升级
  287. return this.showDialog({
  288. title: '升级超级订阅',
  289. message: '对不起,暂无权限,您可升级超级订阅解锁附件下载',
  290. showCancelButton: true,
  291. confirmButtonText: '前往升级'
  292. })
  293. .then(() => {
  294. this.toUpgradeSvip()
  295. })
  296. .catch(() => {})
  297. }
  298. }
  299. // 商机管理只要有个数就能下载
  300. if (this.isBusiness && this.resourcePack.number > 0) {
  301. return this.downloadFile(file)
  302. }
  303. // 大会员自定义版本没有下载权限 或 非超级订阅的商机管理用户 (弹框提醒联系客服)
  304. const isMemberButNoPower = this.isMember && !this.memberHasAttachPower
  305. const noAttachmentDownloadPower = isMemberButNoPower && !this.isNewSuper
  306. if (noAttachmentDownloadPower || (!this.isSuper && this.isBusiness)) {
  307. // 老超级订阅用户 提醒升级
  308. return this.showDialog({
  309. message:
  310. '您未购买此服务,如需使用请联系您的客户经理或客服升级套餐,谢谢!',
  311. confirmButtonText: '我知道了'
  312. })
  313. .then(() => {})
  314. .catch(() => {})
  315. }
  316. }
  317. },
  318. async downloadFile(file) {
  319. this.attachment.file = file
  320. // downUrl: 原始url
  321. // fileUrl: 下载地址
  322. const result = await this.getAttachmentInfo(file)
  323. if (result) {
  324. const { downUrl, fileUrl } = result
  325. let skipRefresh = false
  326. // 定制化用户不展示提示和留资
  327. if (IsCustomTopNet.value) {
  328. skipRefresh = true
  329. }
  330. if (IsSunPublishContent.value) {
  331. skipRefresh = true
  332. }
  333. if (!skipRefresh) {
  334. this.refreshResourcePackCount()
  335. }
  336. if (downUrl && fileUrl) {
  337. location.href = fileUrl
  338. } else {
  339. console.log('获取附件fid失败')
  340. }
  341. }
  342. },
  343. async getAttachmentInfo(file) {
  344. this.loading = true
  345. if (!this.loading) return
  346. const params = {
  347. id: this.id, // 附件详情页id
  348. fileName: file.name, // 附件名称
  349. infoType: this.type === 'issued' ? 'S' : '', // 信息类型:默认为空; 供应信息:S
  350. productName: '附件下载包',
  351. platform: 'PC', // 平台:PC;APP;WX
  352. title: this.title // 附件详情页标题附件详情页标题
  353. }
  354. try {
  355. const { r: data, m: msg } =
  356. await this.attachmentInstance.useResourcePack(params)
  357. // 各种余额不足提示
  358. if (data) {
  359. if (data.code && data.code < 0) {
  360. if (this.isFree) {
  361. this.showDialog({
  362. title: '开通超级订阅',
  363. message:
  364. '您的免费【附件下载】次数已使用完,暂无免费查看权限。如需查看更多,请开通超级订阅获取更多权限。',
  365. showCancelButton: true,
  366. confirmButtonText: '去开通'
  367. })
  368. .then(() => {
  369. this.toBuySvip()
  370. })
  371. .catch(() => {})
  372. } else if (this.isSuper) {
  373. this.showDialog({
  374. title: '开通超级订阅',
  375. message:
  376. '您本月附件下载机会已消耗完毕,如需下载更多附件,请前往充值。',
  377. showCancelButton: true,
  378. confirmButtonText: '立即充值'
  379. })
  380. .then(() => {
  381. this.chargeFilePack()
  382. })
  383. .catch(() => {})
  384. } else {
  385. this.$toast(msg || '获取附件地址失败')
  386. }
  387. } else if (!msg && data.downUrl) {
  388. const downUrl = data.downUrl
  389. const fileUrl = downUrl
  390. ? `${downUrl}?response-content-type=application/octet-stream`
  391. : ''
  392. return {
  393. ...data,
  394. fileUrl // 真实下载地址
  395. }
  396. } else {
  397. this.$toast(msg || '获取附件地址失败')
  398. }
  399. } else {
  400. this.$toast(msg || '获取附件地址失败')
  401. }
  402. } catch (error) {
  403. console.log(error)
  404. } finally {
  405. this.loading = false
  406. }
  407. },
  408. toBuySvip() {
  409. window.open('/swordfish/page_big_pc/free/svip/buy', '_blank')
  410. },
  411. chargeFilePack() {
  412. window.open('/swordfish/page_big_pc/free/filePack/buy', '_blank')
  413. }
  414. }
  415. }
  416. </script>
  417. <style lang="scss" scoped>
  418. .attachment-download-container {
  419. margin-top: 40px;
  420. margin-bottom: 70px;
  421. }
  422. .file-attachment-text {
  423. margin-right: 12px;
  424. font-size: 16px;
  425. line-height: 24px;
  426. }
  427. .attachment-tag {
  428. margin: 0 8px;
  429. padding: 2px 0;
  430. font-size: 12px;
  431. line-height: 18px;
  432. color: $color-main;
  433. background: $color_main_background;
  434. border-radius: 10px;
  435. &-text {
  436. padding: 0 8px;
  437. color: $color-main;
  438. }
  439. }
  440. .action-button {
  441. flex-shrink: 0;
  442. display: inline-block;
  443. margin-left: 24px;
  444. text-align: center;
  445. cursor: pointer;
  446. padding: 0 16px;
  447. min-width: 64px;
  448. font-size: 12px;
  449. line-height: 30px;
  450. border-radius: 4px;
  451. color: #fff;
  452. background-color: $color-main;
  453. }
  454. .file-attachment-list {
  455. margin-top: 16px;
  456. font-size: 15px;
  457. line-height: 22px;
  458. .file-attachment-item {
  459. display: block;
  460. cursor: pointer;
  461. margin-bottom: 16px;
  462. }
  463. }
  464. .right-content {
  465. .iconfont {
  466. cursor: pointer;
  467. color: $color-main;
  468. }
  469. }
  470. .open-vip-btn {
  471. color: #fff;
  472. padding: 0 8px;
  473. border-radius: inherit;
  474. background-color: $color-main;
  475. }
  476. </style>