articleshare.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. var app = getApp();
  2. var utils = require("../../../utils/http");
  3. const util = require("../../../utils/util")
  4. var stoptime = 0;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. aid: '',
  11. title: '志远装饰数字化平台',
  12. customerFlag: false,
  13. articleObj: {},
  14. imgUrl: app.globalData.imgUrl,
  15. type: 1, //3是我的创作进入视频编辑列表进来的,1是我的创作的列表进入,2是裂变列表进入
  16. nowflag: false,
  17. footflag: true,
  18. wshareshow: false,
  19. priceflag: false
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. if (!!options.type) {
  26. this.setData({
  27. footflag: false
  28. })
  29. }
  30. this.setData({
  31. aid: options.aid,
  32. type: options.type,
  33. })
  34. wx.showLoading({
  35. title: '加载中...',
  36. })
  37. this.artileMsg();
  38. },
  39. setpostertap: function () {
  40. wx.navigateTo({
  41. url: '/index/pages/setposter/setposter?type=article&aid=' + this.data.aid + "&listshare=",
  42. })
  43. },
  44. priceshowtap() {
  45. this.setData({
  46. priceflag: true
  47. })
  48. },
  49. closepricetap() {
  50. this.setData({
  51. priceflag: false
  52. })
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. articlesharetap: function () {
  60. this.setData({
  61. wshareshow: true
  62. })
  63. },
  64. artileMsg: function () {
  65. var that = this;
  66. utils.$post({
  67. url: app.globalData.webUrl + 'api/article/info',
  68. header: {
  69. 'Authorization': 'bearer ' + app.globalData.token
  70. },
  71. data: {
  72. article_id: that.data.aid
  73. },
  74. success: function (res) {
  75. if (res.data.code == '0') {
  76. that.setData({
  77. articleObj: res.data.data,
  78. title: res.data.data.title
  79. })
  80. wx.setNavigationBarTitle({
  81. title: res.data.data.title
  82. })
  83. }
  84. setTimeout(function () {
  85. wx.hideLoading();
  86. }, 1000)
  87. }
  88. })
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. var that = this;
  95. if (app.globalData.sharearticle) {
  96. // wx.showToast({
  97. // title: '即将跳转原页面',
  98. // icon: 'success',
  99. // })
  100. setTimeout(function () {
  101. // wx.redirectTo({
  102. // url: "/mycustomer/pages/mycreation/mycreation?type=3",
  103. // });
  104. if (that.data.type == '2') {
  105. wx.redirectTo({
  106. url: "/mycustomer/pages/mycreation/mycreation?type=2",
  107. });
  108. } else if (that.data.type == '1') {
  109. wx.navigateBack({
  110. delta: 3
  111. });
  112. } else {
  113. wx.navigateBack({
  114. delta: 2
  115. });
  116. }
  117. }, 1000)
  118. }
  119. stoptime = 0;
  120. setTimeout(function () {
  121. stoptime = stoptime * 1 + 1;
  122. }, 1000)
  123. },
  124. shareurltap: function () {
  125. let that = this;
  126. wx.showLoading({
  127. title: '加载中...',
  128. })
  129. util.schemefun('/share/pages/articleshare/articleshare', 'aid=' + that.data.aid + '&userid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, that.data.aid, 'article', '');
  130. this.sharelogtap();
  131. },
  132. sharealerttap: function (e) {
  133. var that = this;
  134. that.setData({
  135. nowflag: true,
  136. })
  137. },
  138. sendfriendtap() {
  139. this.sharelogtap();
  140. },
  141. sharelogtap: function () {
  142. var that = this;
  143. this.setData({
  144. nowflag: false,
  145. })
  146. utils.$post({
  147. url: app.globalData.webUrl + 'api/share/addlog',
  148. header: {
  149. 'Authorization': 'bearer ' + app.globalData.token
  150. },
  151. data: {
  152. id: that.data.aid,
  153. type: 'article'
  154. },
  155. success: function (r) {}
  156. })
  157. },
  158. collectTap: function () {
  159. var that = this;
  160. utils.$post({
  161. url: app.globalData.webUrl + 'api/article/collect',
  162. header: {
  163. 'Authorization': 'bearer ' + app.globalData.token
  164. },
  165. data: {
  166. id: that.data.aid,
  167. },
  168. success: function (res) {
  169. var articleObj = that.data.articleObj;
  170. if (res.data.code == '0') {
  171. articleObj.collect = 1;
  172. that.setData({
  173. articleObj: articleObj
  174. })
  175. wx.showToast({
  176. title: '收藏成功!',
  177. icon: 'none',
  178. duration: 1000
  179. })
  180. that.setData({
  181. articleObj: articleObj
  182. })
  183. }
  184. }
  185. })
  186. },
  187. cancleTap: function () {
  188. var that = this;
  189. utils.$post({
  190. url: app.globalData.webUrl + 'api/article/collectCancel',
  191. header: {
  192. 'Authorization': 'bearer ' + app.globalData.token
  193. },
  194. data: {
  195. id: that.data.aid,
  196. },
  197. success: function (res) {
  198. var articleObj = that.data.articleObj;
  199. if (res.data.code == '0') {
  200. articleObj.collect = 0;
  201. that.setData({
  202. articleObj: articleObj
  203. })
  204. wx.showToast({
  205. title: '取消收藏成功!',
  206. icon: 'none',
  207. duration: 1000
  208. })
  209. that.setData({
  210. articleObj: articleObj
  211. })
  212. }
  213. }
  214. })
  215. },
  216. zantap: function () {
  217. var that = this;
  218. utils.$post({
  219. url: app.globalData.webUrl + 'api/article/star',
  220. header: {
  221. 'Authorization': 'bearer ' + app.globalData.token
  222. },
  223. data: {
  224. id: that.data.aid,
  225. },
  226. success: function (res) {
  227. var articleObj = that.data.articleObj;
  228. if (res.data.code == '0') {
  229. if (articleObj.stared == 1) {
  230. wx.showToast({
  231. title: '您已点赞!',
  232. icon: 'none',
  233. duration: 1000
  234. })
  235. } else {
  236. articleObj.stared = 1;
  237. wx.showToast({
  238. title: '点赞成功!',
  239. icon: 'none',
  240. duration: 1000
  241. })
  242. articleObj.star_num = articleObj.star_num * 1 + 1;
  243. }
  244. that.setData({
  245. articleObj: articleObj
  246. })
  247. }
  248. }
  249. })
  250. },
  251. /**
  252. * 生命周期函数--监听页面隐藏
  253. */
  254. onHide: function () {
  255. var timearr = app.globalData.timearr,
  256. flag = false;
  257. for (var i = 0; i < timearr.length; i++) {
  258. if (timearr[i].type == 'articleprelook') {
  259. timearr[i].time = timearr[i].time * 1 + stoptime * 1;
  260. flag = true;
  261. }
  262. }
  263. if (!flag) {
  264. var obj = {
  265. type: 'articleprelook',
  266. time: stoptime
  267. };
  268. app.globalData.timearr.push(obj);
  269. } else {
  270. app.globalData.timearr = timearr;
  271. }
  272. },
  273. /**
  274. * 生命周期函数--监听页面卸载
  275. */
  276. onUnload: function () {
  277. },
  278. /**
  279. * 页面相关事件处理函数--监听用户下拉动作
  280. */
  281. onPullDownRefresh: function () {
  282. },
  283. /**
  284. * 页面上拉触底事件的处理函数
  285. */
  286. onReachBottom: function () {
  287. },
  288. /**
  289. * 用户点击右上角分享
  290. */
  291. onShareAppMessage: function () {
  292. this.sharelogtap();
  293. var img = this.data.articleObj.cover_img;
  294. return {
  295. title: this.data.articleObj.title,
  296. imageUrl: img,
  297. path: '/share/pages/articleshare/articleshare?aid=' + this.data.aid + '&userid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
  298. }
  299. }
  300. })