articleInfor.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. // articleInfor.js
  2. var app = getApp();
  3. var WxParse = require('../../wxParse/wxParse.js');
  4. var articleInfor = {
  5. };
  6. var articleInfor1 = {
  7. };
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. id : '',//当前详情对应的id
  14. isSelect: false,
  15. articleInfor: articleInfor,
  16. articleInfor1: articleInfor1,
  17. find_content: '',
  18. find_content2: '',
  19. find_content3: '',
  20. find_content4: '',
  21. find_content5: '',
  22. goods1: '',
  23. goods2: '',
  24. goods3: '',
  25. goods4: '',
  26. goods5: '',
  27. find_name: '',
  28. find_sta: '',
  29. find_des: '',
  30. find_logo: '',
  31. find_yuedu: '',
  32. find_shoucang: '',
  33. find_sro: '',
  34. find_lev: '',
  35. img1: '',
  36. img2: '',
  37. img3: '',
  38. img4: '',
  39. img5: '',
  40. cmname1: '',
  41. cmname2: '',
  42. cmname3: '',
  43. cmname4: '',
  44. cmname5: '',
  45. title1: '',
  46. title2: '',
  47. title3: '',
  48. title4: '',
  49. title5: '',
  50. price1: '',
  51. price2: '',
  52. price3: '',
  53. price4: '',
  54. price5: '',
  55. id1: '',
  56. id2: '',
  57. id3: '',
  58. id4: '',
  59. id5: '',
  60. wxParseData:'',
  61. title: '',
  62. hiddenmodal: true, //弹窗
  63. modalCont: '',
  64. showBtn: false, //是否显示右侧返回首页按钮
  65. isSelectNew: 0, //默认
  66. from_flag: 0
  67. },
  68. selectZan:function(e){
  69. var that = this;
  70. var opera = e.currentTarget.dataset.opera;
  71. var id = e.currentTarget.dataset.id;
  72. var find_shoucangnew = that.data.find_shoucang
  73. var host = getApp().globalData.servsers;
  74. var un_id = getApp().globalData.un_id;
  75. if (un_id != undefined && un_id != '' && un_id != null){
  76. if (opera == false) {
  77. //后台增加收藏数量
  78. wx.request({
  79. url: host + "findapi/updateFindforshoucang",
  80. data: {
  81. id: id
  82. },
  83. method: 'GET',
  84. header: {
  85. 'Accept': 'application/json'
  86. },
  87. success: function (res) {
  88. var size = res.data.total;
  89. that.setData({
  90. navList: res.data.rows
  91. });
  92. if (res == null || res.data == null) {
  93. console.error('网络请求失败');
  94. return;
  95. }
  96. }
  97. })
  98. //后台增加收藏用户收藏数据
  99. wx.request({
  100. url: host + "collectionapi/insertcollection",
  101. data: {
  102. user_id: un_id,
  103. collection_clas: 1,
  104. collection_name: id,
  105. },
  106. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  107. header: {
  108. 'Accept': 'application/json'
  109. },
  110. success: function (res) {
  111. if (res == null || res.data == null) {
  112. console.error('网络请求失败');
  113. return;
  114. }
  115. }
  116. })
  117. that.setData({
  118. isSelect: true,
  119. find_shoucang: parseInt(find_shoucangnew) + 1
  120. })
  121. } else {
  122. //后台删除收藏用户收藏数量
  123. wx.request({
  124. url: host + "collectionapi/deleteforxcx",
  125. data: {
  126. user_id: un_id,
  127. collection_clas: 1,
  128. collection_name: id,
  129. },
  130. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  131. header: {
  132. 'Accept': 'application/json'
  133. },
  134. success: function (res) {
  135. if (res == null || res.data == null) {
  136. console.error('网络请求失败');
  137. return;
  138. }
  139. }
  140. })
  141. //后台删除收藏用户收藏数据
  142. wx.request({
  143. url: host + "findapi/updateFindforshoucangfu",
  144. data: {
  145. id: id
  146. },
  147. method: 'GET',
  148. header: {
  149. 'Accept': 'application/json'
  150. },
  151. success: function (res) {
  152. var size = res.data.total;
  153. that.setData({
  154. navList: res.data.rows
  155. });
  156. if (res == null || res.data == null) {
  157. console.error('网络请求失败');
  158. return;
  159. }
  160. }
  161. })
  162. this.setData({
  163. isSelect: false,
  164. find_shoucang: parseInt(find_shoucangnew) - 1
  165. })
  166. }
  167. }
  168. },
  169. onLoad: function (options) {
  170. var that = this;
  171. // WxParse.wxParse('content', 'html', content, that, 5);
  172. var host = getApp().globalData.servsers;
  173. var un_id = getApp().globalData.un_id;
  174. that.data.id = options.id;
  175. if (un_id != undefined){
  176. wx.request({
  177. url: host + "collectionapi/findAllforxcx",
  178. data: {
  179. user_id: un_id,
  180. collection_clas: 1,
  181. collection_name: options.id,
  182. },
  183. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  184. header: {
  185. 'Accept': 'application/json'
  186. },
  187. success: function (res) {
  188. //查看该用户是否收藏发现文章res.data.total =0 没有收藏
  189. if (res.data.total == 0) {
  190. that.setData({
  191. isSelect: false
  192. })
  193. } else {
  194. that.setData({
  195. isSelect: true
  196. })
  197. }
  198. if (res == null || res.data == null) {
  199. console.error('网络请求失败');
  200. return;
  201. }
  202. }
  203. })
  204. }
  205. //增加阅读量
  206. wx.request({
  207. url: host +"findapi/updateFindforread",
  208. data: {
  209. id: options.id
  210. },
  211. method: 'GET',
  212. header: {
  213. 'Accept': 'application/json'
  214. },
  215. success: function (res) {
  216. if (res == null || res.data == null) {
  217. console.error('网络请求失败');
  218. return;
  219. }
  220. }
  221. })
  222. that.setData({
  223. title: options.title,
  224. intro: options.intro,
  225. id: options.id,
  226. src: options.src,
  227. from_flag: options.from_flag,
  228. })
  229. if (options.from_flag == 1) {//从分享链接进入
  230. that.setData({
  231. showBtn: true
  232. })
  233. } else {
  234. that.setData({
  235. showBtn: false
  236. })
  237. }
  238. //首页banner
  239. wx.request({
  240. url: host+"findapi/findListview",
  241. data: {
  242. id: options.id
  243. },
  244. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  245. header: {
  246. 'Accept': 'application/json'
  247. },
  248. success: function (res) {
  249. // console.log(WxParse.wxParse('article', 'html', res.data.rows[0].find_content, that, 5));
  250. if(res.data.rows[0].goods1!=null){
  251. var article = res.data.rows[0].find_content;
  252. WxParse.wxParse('article', 'html', res.data.rows[0].find_content, that, 5)
  253. var article1 = res.data.rows[0].find_content2;
  254. WxParse.wxParse('article1', 'html', res.data.rows[0].find_content2, that, 5)
  255. var article2 = res.data.rows[0].find_content3;
  256. WxParse.wxParse('article2', 'html', res.data.rows[0].find_content3, that, 5)
  257. var article3 = res.data.rows[0].find_content4;
  258. WxParse.wxParse('article3', 'html', res.data.rows[0].find_content4, that, 5)
  259. var article4 = res.data.rows[0].find_content5;
  260. WxParse.wxParse('article4', 'html', res.data.rows[0].find_content5, that, 5)
  261. wx.request({
  262. url: host + "commodityapi/commoditview",
  263. data: {
  264. com_id: res.data.rows[0].goods1,
  265. },
  266. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  267. header: {
  268. 'Accept': 'application/json'
  269. },
  270. success: function (res) {
  271. if (res.data.commodity == undefined){
  272. console.log('商品已下架');
  273. return false;
  274. }else{
  275. that.setData({
  276. id1: res.data.commodity.id,
  277. img1: host + 'images/' + res.data.images[0],
  278. cmname1: res.data.commodity.commodity_name,
  279. title1: res.data.commodity.commodity_des,
  280. price1: res.data.commodity.commodity_sale,
  281. oldPrice1: res.data.commodity.commodity_cost
  282. });
  283. }
  284. if (res == null || res.data == null) {
  285. console.error('网络请求失败');
  286. return;
  287. }
  288. }
  289. });
  290. }
  291. if (res.data.rows[0].goods2 != '0') {
  292. wx.request({
  293. url: host + "commodityapi/commoditview",
  294. data: {
  295. com_id: res.data.rows[0].goods2
  296. },
  297. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  298. header: {
  299. 'Accept': 'application/json'
  300. },
  301. success: function (res) {
  302. if (res.data.commodity == undefined) {
  303. console.log('商品已下架');
  304. return false;
  305. } else {
  306. that.setData({
  307. id2: res.data.commodity.id,
  308. img2: host+'images/' + res.data.images[0],
  309. cmname2: res.data.commodity.commodity_name,
  310. title2: res.data.commodity.commodity_des,
  311. price2: res.data.commodity.commodity_sale,
  312. oldPrice2: res.data.commodity.commodity_cost
  313. });
  314. }
  315. if (res == null || res.data == null) {
  316. console.error('网络请求失败');
  317. return;
  318. }
  319. }
  320. })
  321. }
  322. if (res.data.rows[0].goods3 != '0') {
  323. wx.request({
  324. url: host + "commodityapi/commoditview",
  325. data: {
  326. com_id: res.data.rows[0].goods3
  327. },
  328. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  329. header: {
  330. 'Accept': 'application/json'
  331. },
  332. success: function (res) {
  333. if (res.data.commodity == undefined) {
  334. console.log('商品已下架');
  335. return false;
  336. } else {
  337. that.setData({
  338. id3: res.data.commodity.id,
  339. img3: host+'images/' + res.data.images[0],
  340. cmname3: res.data.commodity.commodity_name,
  341. title3: res.data.commodity.commodity_des,
  342. price3: res.data.commodity.commodity_sale,
  343. oldPrice3: res.data.commodity.commodity_cost
  344. });
  345. }
  346. if (res == null || res.data == null) {
  347. console.error('网络请求失败');
  348. return;
  349. }
  350. }
  351. })
  352. }
  353. if (res.data.rows[0].goods4 != '0') {
  354. wx.request({
  355. url: host + "commodityapi/commoditview",
  356. data: {
  357. com_id: res.data.rows[0].goods4
  358. },
  359. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  360. header: {
  361. 'Accept': 'application/json'
  362. },
  363. success: function (res) {
  364. if (res.data.commodity == undefined) {
  365. console.log('商品已下架');
  366. return false;
  367. } else {
  368. that.setData({
  369. id4: res.data.commodity.id,
  370. img4: host+'images/' + res.data.images[0],
  371. cmname4: res.data.commodity.commodity_name,
  372. title4: res.data.commodity.commodity_des,
  373. price4: res.data.commodity.commodity_sale,
  374. oldPrice4: res.data.commodity.commodity_cost
  375. });
  376. }
  377. if (res == null || res.data == null) {
  378. console.error('网络请求失败');
  379. return;
  380. }
  381. }
  382. })
  383. }
  384. if (res.data.rows[0].goods5 != '0') {
  385. wx.request({
  386. url: host + "commodityapi/commoditview",
  387. data: {
  388. com_id: res.data.rows[0].goods5
  389. },
  390. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  391. header: {
  392. 'Accept': 'application/json'
  393. },
  394. success: function (res) {
  395. if (res.data.commodity == undefined) {
  396. console.log('商品已下架');
  397. return false;
  398. } else {
  399. that.setData({
  400. id5: res.data.commodity.id,
  401. img5: host+'images/' + res.data.images[0],
  402. cmname5: res.data.commodity.commodity_name,
  403. title5: res.data.commodity.commodity_des,
  404. price5: res.data.commodity.commodity_sale,
  405. oldPrice5: res.data.commodity.commodity_cost
  406. });
  407. }
  408. if (res == null || res.data == null) {
  409. console.error('网络请求失败');
  410. return;
  411. }
  412. }
  413. })
  414. }
  415. that.setData({
  416. find_content: res.data.rows[0].find_content,
  417. find_content2: res.data.rows[0].find_content2,
  418. find_content3: res.data.rows[0].find_content3,
  419. find_content4: res.data.rows[0].find_content4,
  420. find_content5: res.data.rows[0].find_content5,
  421. find_name: res.data.rows[0].find_name,
  422. find_sta: res.data.rows[0].find_sta,
  423. find_des: res.data.rows[0].find_des,
  424. find_logo: res.data.rows[0].find_logo,
  425. find_yuedu: res.data.rows[0].find_yuedu,
  426. find_shoucang: res.data.rows[0].find_shoucang,
  427. find_sro: res.data.rows[0].find_sro,
  428. find_lev: res.data.rows[0].find_lev,
  429. goods1: res.data.rows[0].goods1,
  430. goods2: res.data.rows[0].goods2,
  431. goods3: res.data.rows[0].goods3,
  432. goods4: res.data.rows[0].goods4,
  433. goods5: res.data.rows[0].goods5,
  434. title: res.data.rows[0].find_name
  435. });
  436. wx.setNavigationBarTitle({
  437. title: res.data.rows[0].find_name
  438. })
  439. if (res == null || res.data == null) {
  440. console.error('网络请求失败');
  441. return;
  442. }
  443. }
  444. });
  445. },
  446. onShareAppMessage: function (res) {//页面分享
  447. var that = this;
  448. var host = getApp().globalData.servsers;
  449. if (res.from === 'button') {
  450. // 来自页面内转发按钮
  451. console.log(res.target)
  452. }
  453. return {
  454. title: that.data.title,
  455. path: '/pages/articleInfor/articleInfor?id=' + that.data.id + '&from_flag=' + 1,
  456. imageUrl: that.data.find_logo,
  457. success: function (res) {
  458. // 转发成功
  459. that.setData({
  460. hiddenmodal: false,
  461. modalCont: '转发成功'
  462. })
  463. setTimeout(function () {
  464. that.setData({
  465. hiddenmodal: true
  466. })
  467. }, 1000)
  468. },
  469. fail: function (res) {
  470. // 转发失败
  471. }
  472. }
  473. },
  474. //返回首页
  475. backIndex: function (e) {
  476. wx.switchTab({
  477. url: '/pages/index/index',
  478. })
  479. }
  480. })
  481. var that;
  482. var Util = require('../../utils/util.js');