beautyArchiveDetailMixin.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //商品资料库vue混入对象
  2. var beautyArchiveDetailMixin = {
  3. data: {
  4. isRequest: false,
  5. //用户信息相关
  6. permission: 5, //用户权限 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  7. //页面配置
  8. archiveId: '', //资料列表id
  9. currentVideoUrl: '', //正在播放的视频链接(上一个播放的的视频)
  10. showVideoDialog: false,
  11. isPlayer: false, //是否正在播放
  12. imageGroup: {},
  13. keyword: '',
  14. imageArchiveList: [], // 图片资料列表
  15. videoArchiveList: [], // 视频资料列表
  16. fileArchiveList: [], // 文件资料列表
  17. defaultImage: 'https://static.caimei365.com/app/img/icon2/PC-default.png', // 默认图片
  18. videoCover: 'https://static.caimei365.com/app/img/icon2/video-cover.png', //默认视频封面
  19. archiveProductInfo: {}
  20. },
  21. filters: {
  22. // 时间格式化
  23. formatTime: function (val) {
  24. return moment(new Date(val)).format('YYYY-MM-DD hh:mm:ss');
  25. }
  26. },
  27. computed: {
  28. //资料查看状态提示
  29. TipStatus: function () {
  30. // 资料权限
  31. var statusText = [
  32. false,
  33. {text: '请登录后查看!', btn: '去登录', redirect: '/login.html'},
  34. {text: '请升级成为会员机构后方可查看!', btn: '去升级', redirect: '/user/setting/upgrade.html'},
  35. {text: '请升级成为医美会员机构后方可查看!', btn: '去升级', redirect: '/user/setting/upgrade.html'},
  36. {text: '需抵扣100采美豆方可查看!', btn: '去查看', redirect: 10},
  37. {text: '无权限查看!', btn: ''}
  38. ];
  39. // 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  40. return statusText[this.permission];
  41. }
  42. },
  43. methods: {
  44. // 图片点击事件
  45. handleShowImage: function () {
  46. if (this.checkPermission() !== 0) return;
  47. },
  48. //初始化预览图片配置
  49. initPreviewImage: function () {
  50. var imageGroup = {};
  51. var imageEls = document.querySelectorAll('.cm-images');
  52. imageEls.forEach(function (imageEl, index) {
  53. imageGroup['cm-images-' + index] = new Viewer(imageEl);
  54. });
  55. this.imageGroup = imageGroup;
  56. },
  57. //显示视频播放窗口
  58. handleShowPlayer: function (url) {
  59. if (this.checkPermission() !== 0) return;
  60. //暂停上一个正在播放的播放器
  61. this.currentVideoUrl = url;
  62. this.showVideoDialog = true;
  63. },
  64. //隐藏视频播放窗口
  65. handleClosePlayer: function () {
  66. this.$refs.videoRef.pause();
  67. this.currentVideoUrl = '';
  68. this.showVideoDialog = false;
  69. },
  70. //播放视频
  71. handlePlayer: function () {
  72. var _self = this;
  73. var video = this.$refs.videoRef;
  74. video.addEventListener('pause', function () {
  75. _self.isPlayer = false
  76. });
  77. video.addEventListener('ended', function () {
  78. _self.isPlayer = false
  79. });
  80. video.addEventListener('error', function () {
  81. _self.isPlayer = false
  82. });
  83. video.addEventListener('play', function () {
  84. _self.isPlayer = true
  85. });
  86. if (!_self.isPlayer) video.play();
  87. },
  88. //预览office文件 word ppt pdf
  89. handlePreviewOffice: function (file) {
  90. if (this.checkPermission() !== 0) return;
  91. var index = file.fileName.lastIndexOf('.');
  92. var suffix = file.fileName.substring(index);
  93. if (suffix === '.doc' || suffix === '.ppt') {
  94. // 如果是 doc 或 ppt 直接打开链接预览
  95. window.open(file.fileUrl, '_blank');
  96. } else if (suffix === '.pdf') {
  97. // 如果是 pdf 需要跳转到预览页面并设置type为1,src为pdf预览链接
  98. if (isPC) {
  99. window.open(file.fileUrl, '_blank');
  100. } else {
  101. var url = '/document/pdfdetails.html?type=1&src=' + file.fileUrl;
  102. window.open(url, '_blank');
  103. }
  104. } else {
  105. CAIMEI.Popup({
  106. content: suffix + '类型文件暂时无法预览',
  107. confitmBtnText: '确定',
  108. cancelBtnText: '取消'
  109. }, function () {
  110. }, function () {
  111. });
  112. }
  113. },
  114. /*
  115. * 下一步操作 链接跳转 支付支付采美豆
  116. * redirect:
  117. * 链接: 链接跳转
  118. * 10: 支付采美豆
  119. * */
  120. handleClickToPage: function (redirect) {
  121. var _self = this;
  122. if (typeof redirect == "string") {
  123. // 跳转链接
  124. return window.open(redirect, '_blank');
  125. }
  126. if (redirect === 10) {
  127. // 调用接口
  128. CAIMEI.Popup({
  129. content: '确认使用采美豆',
  130. confitmBtnText: '确定',
  131. cancelBtnText: '取消'
  132. }, function () {
  133. _self.SearchArchiveByBeans()
  134. }, function () {
  135. });
  136. }
  137. },
  138. //用户权限配置 操作前拦截:预览图片,播放视频,预览文件的拦截
  139. checkPermission: function () {
  140. //permission:查看权限:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  141. var _self = this;
  142. // 如果 TipStatus 返回false 就放行
  143. if (!_self.TipStatus) return 0;
  144. CAIMEI.Popup({
  145. content: _self.TipStatus.text,
  146. confitmBtnText: _self.TipStatus.btn,
  147. cancelBtnText: '取消'
  148. }, function () {
  149. // 确认 执行 下一步 链接跳转 支付支付采美豆
  150. _self.handleClickToPage(_self.TipStatus.redirect);
  151. }, function () {
  152. });
  153. return -1;
  154. },
  155. //采美豆抵扣查看资料
  156. SearchArchiveByBeans: function () {
  157. BeautyArchiveApi.SearchArchiveByBeans({
  158. userId: GLOBAL_USER_ID,
  159. archiveId: this.archiveId
  160. }, function (res) {
  161. if (res.code) return CAIMEI.dialog(res.msg);
  162. // 支付采美豆成功,刷新页面
  163. CAIMEI.dialog(res.msg, true, function () {
  164. window.location.reload();
  165. }
  166. );
  167. });
  168. },
  169. // 对图片列表格式化处理
  170. formatImage: function (list) {
  171. var resultList = [];
  172. for (var i = 0; i < list.length; i++) {
  173. var imageUrl = list[i];
  174. var index = imageUrl.indexOf('?');
  175. var size = imageUrl.substring(index + 1).replace(/\&|\=/g, '-').split('-');
  176. var width = parseInt(size[1]);
  177. var height = parseInt(size[3]);
  178. var style = '';
  179. if (list.length > 1) {
  180. if (width >= height) {
  181. style = 'height:100%;width:auto;max-width:unset;';
  182. } else {
  183. style = 'width:100%;height: auto;max-width:unset;';
  184. }
  185. }
  186. if (list.length === 1) {
  187. if (width >= height) {
  188. style = 'max-width:800px;height:auto';
  189. } else {
  190. style = 'max-height:800px;width:auto';
  191. }
  192. }
  193. resultList.push({
  194. imageUrl: imageUrl,
  195. style: style
  196. })
  197. }
  198. return resultList;
  199. },
  200. //获取资料列表
  201. getProdcutArchiveDetails: function () {
  202. const _self = this;
  203. _self.isRequest = true;
  204. if (this.archiveId === 0) return;
  205. BeautyArchiveApi.GetProdcutArchiveDetails({
  206. userId: GLOBAL_USER_ID,
  207. archiveId: this.archiveId
  208. }, function (res) {
  209. if (res.code !== 0) return false;
  210. _self.imageArchiveList = res.data.imageArchiveList;
  211. _self.videoArchiveList = res.data.videoArchiveList;
  212. _self.fileArchiveList = res.data.fileArchiveList;
  213. _self.permission = res.data.permission;
  214. _self.archiveProductInfo.productImage = res.data.productImage;
  215. _self.archiveProductInfo.productName = res.data.productName;
  216. _self.archiveProductInfo.productType = res.data.productType;
  217. _self.archiveProductInfo.shopName = res.data.shopName;
  218. _self.isRequest = false;
  219. // 只有当前用户权限为0时初始化图片预览
  220. if (_self.permission === 0) {
  221. setTimeout(function () {
  222. _self.initPreviewImage()
  223. })
  224. }
  225. })
  226. }
  227. }
  228. };