details.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. const app = getApp()
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. Page({
  5. mixins: [require('../../mixin/compoentCartMixin.js')],
  6. data: {
  7. info: {},
  8. fmShow: true,
  9. canvasWidth: 375,
  10. canvasHeight: 300
  11. },
  12. gid: 0,
  13. goodsImg: '',
  14. imageUrl: '',
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. app.setShareConfig();
  20. let gid = options.id || '';
  21. this.gid = gid;
  22. this.getData(gid);
  23. let showBackBtn = false;
  24. let pages_all = getCurrentPages();
  25. if (pages_all.length > 1) {
  26. showBackBtn = true;
  27. }
  28. this.setData({ showBackBtn })
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow: function () {
  34. const that = this;
  35. util.check_login_new().then((res) => {
  36. let needAuth = !res;
  37. that.setData({ needAuth })
  38. if (res) {
  39. (0, status.cartNum)('', true).then((res) => {
  40. res.code == 0 && that.setData({
  41. cartNum: res.data
  42. })
  43. });
  44. }
  45. })
  46. },
  47. onReady: function (res) {
  48. this.videoContext = wx.createVideoContext('myVideo');
  49. },
  50. /**
  51. * 授权成功回调
  52. */
  53. authSuccess: function () {
  54. const that = this;
  55. let gid = this.gid;
  56. this.setData({
  57. needAuth: false,
  58. showAuthModal: false
  59. }, () => {
  60. that.getData(gid);
  61. })
  62. },
  63. vipModal: function(t) {
  64. this.setData(t.detail)
  65. },
  66. imageLoad: function (e) {
  67. var imageSize = util.imageUtil(e)
  68. this.setData({
  69. imageSize
  70. })
  71. },
  72. /**
  73. * 播放视频隐藏封面图
  74. */
  75. btnPlay: function () {
  76. this.setData({
  77. fmShow: false
  78. })
  79. this.videoContext.play();
  80. },
  81. videEnd: function () {
  82. this.setData({
  83. fmShow: true
  84. })
  85. },
  86. endPlay: function () {
  87. this.videoContext.pause();
  88. this.setData({
  89. fmShow: true
  90. })
  91. },
  92. /**
  93. * 获取信息
  94. */
  95. getData: function (id) {
  96. let that = this;
  97. let token = wx.getStorageSync('token');
  98. let community = wx.getStorageSync('community');
  99. let head_id = community.communityId || '';
  100. wx.showLoading();
  101. app.util.request({
  102. 'url': 'entry/wxapp/index',
  103. 'data': {
  104. controller: 'recipe.get_recipe_detail',
  105. token,
  106. id,
  107. head_id
  108. },
  109. dataType: 'json',
  110. success: function (res) {
  111. if (res.data.code==0) {
  112. let info = res.data.data || {};
  113. let is_open_recipe_full_video = res.data.is_open_recipe_full_video;
  114. let showCoverVideo = (is_open_recipe_full_video==1) && info.video;
  115. that.setData({ info, showCoverVideo }, ()=>{
  116. let shareImg = info.images;
  117. info.video && shareImg && status.download(shareImg + "?imageView2/1/w/500/h/400").then(function (a) {
  118. that.goodsImg = a.tempFilePath, that.drawImg();
  119. });
  120. })
  121. }
  122. wx.hideLoading();
  123. }
  124. })
  125. },
  126. /**
  127. * 点赞
  128. */
  129. agree: function () {
  130. if (!this.authModal()) return;
  131. let that = this;
  132. let item = this.data.info;
  133. let token = wx.getStorageSync('token');
  134. app.util.request({
  135. 'url': 'entry/wxapp/index',
  136. 'data': {
  137. controller: 'recipe.fav_recipe_do',
  138. token: token,
  139. id: item.id
  140. },
  141. dataType: 'json',
  142. success: function (res) {
  143. if (res.data.code == 0) {
  144. //成功
  145. wx.showToast({
  146. title: '已喜欢~',
  147. icon: 'none'
  148. })
  149. item.fav_count = res.data.fav_count;
  150. item.has_fav = 1;
  151. that.setData({ info: item })
  152. } else if (res.data.code == 1) {
  153. //未登录
  154. that.setData({ needAuth: true });
  155. } else if (res.data.code == 2) {
  156. //取消收藏
  157. item.fav_count = res.data.fav_count;
  158. item.has_fav = 0;
  159. that.setData({ info: item })
  160. wx.showToast({
  161. title: '取消喜欢~',
  162. icon: 'none'
  163. })
  164. }
  165. }
  166. })
  167. },
  168. goLink: function(e){
  169. let link = e.currentTarget.dataset.link;
  170. app.util.navTo(link);
  171. },
  172. drawImg: function () {
  173. var t = this;
  174. wx.createSelectorQuery().select(".canvas-img").boundingClientRect(function () {
  175. const context = wx.createCanvasContext("myCanvas");
  176. context.drawImage(t.goodsImg, 0, 0, status.getPx(375), status.getPx(300));
  177. context.drawImage("../../images/play.png", status.getPx(127.5), status.getPx(70), status.getPx(120), status.getPx(120));
  178. context.save();
  179. context.draw(false, t.checkCanvas());
  180. }).exec();
  181. },
  182. checkCanvas: function () {
  183. var that = this;
  184. setTimeout(() => {
  185. wx.canvasToTempFilePath({
  186. canvasId: "myCanvas",
  187. success: function (res) {
  188. res.tempFilePath ? that.imageUrl = res.tempFilePath : that.drawImg();
  189. console.log('我画完了')
  190. },
  191. fail: function (a) {
  192. that.drawImg();
  193. }
  194. })
  195. }, 500)
  196. },
  197. clickStore: function() {
  198. this.setData({ showStore: !this.data.showStore })
  199. },
  200. coverVideoEnd: function(){
  201. this.setData({
  202. showCoverVideo: false
  203. })
  204. },
  205. _backhome: function() {
  206. wx.switchTab({
  207. url: '/lionfish_comshop/pages/index/index',
  208. })
  209. },
  210. /**
  211. * 用户点击右上角分享
  212. */
  213. onShareAppMessage: function () {
  214. let info = this.data.info;
  215. var community = wx.getStorageSync('community');
  216. var gid = info.id;
  217. var community_id = community.communityId;
  218. var share_title = info.recipe_name;
  219. var share_id = wx.getStorageSync('member_id');
  220. var share_path = `lionfish_comshop/moduleA/menu/details?id=${gid}&share_id=${share_id}&community_id=${community_id}`;
  221. console.log('分享地址:', share_path);
  222. return {
  223. title: share_title,
  224. path: share_path,
  225. imageUrl: this.imageUrl,
  226. success: function (res) {
  227. // 转发成功
  228. },
  229. fail: function (res) {
  230. // 转发失败
  231. }
  232. }
  233. },
  234. onShareTimeline: function () {
  235. let info = this.data.info;
  236. var community = wx.getStorageSync('community');
  237. var gid = info.id;
  238. var community_id = community.communityId;
  239. var share_title = info.recipe_name;
  240. var share_id = wx.getStorageSync('member_id');
  241. var query= `id=${gid}&share_id=${share_id}&community_id=${community_id}`;
  242. return {
  243. title: share_title,
  244. query,
  245. imageUrl: this.imageUrl,
  246. success: function (res) {
  247. // 转发成功
  248. },
  249. fail: function (res) {
  250. // 转发失败
  251. }
  252. }
  253. }
  254. })