articleshare.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. bType: "",
  12. pType: "",
  13. title: '志远装饰数字化平台',
  14. customerFlag: false,
  15. articleObj: {},
  16. imgUrl: app.globalData.imgUrl,
  17. type: 1, //3是我的创作进入视频编辑列表进来的,1是我的创作的列表进入,2是裂变列表进入
  18. nowflag: false,
  19. footflag: true,
  20. wshareshow: false,
  21. priceflag: false,
  22. showTask: true,
  23. datashow: false,
  24. showCutImage: false,
  25. loading: false,
  26. showApproval: false,
  27. remark: "",
  28. trackimgarr: [],
  29. nowimagearr: [],
  30. shareApprovallist: []
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. if (!!options.type) {
  37. this.setData({
  38. footflag: false
  39. })
  40. }
  41. if (!!options.ty) {
  42. this.setData({
  43. bType: options.ty,
  44. showTask: false
  45. })
  46. }
  47. if (!!options.tp) {
  48. this.setData({
  49. pType: options.tp
  50. })
  51. }
  52. this.setData({
  53. aid: options.aid,
  54. type: options.type,
  55. })
  56. wx.showLoading({
  57. title: '加载中...',
  58. })
  59. this.artileMsg();
  60. },
  61. handShowUpload: function () {
  62. this.setData({
  63. trackimgarr: [],
  64. nowimagearr: [],
  65. remark: "",
  66. showCutImage: true
  67. })
  68. },
  69. handleShowApproval() {
  70. this.setData({
  71. showApproval: true
  72. })
  73. wx.showLoading({
  74. title: '加载中...',
  75. })
  76. this.getBrokerApprovallist();
  77. },
  78. //获取审核列表
  79. getBrokerApprovallist() {
  80. const that = this;
  81. utils.$post({
  82. url: app.globalData.webUrl + 'api/agentEmp/share_list',
  83. header: {
  84. 'Authorization': 'bearer ' + app.globalData.token
  85. },
  86. data: {
  87. id: that.data.aid,
  88. type: "Article"
  89. },
  90. success: function (res) {
  91. wx.hideLoading();
  92. if (res.data.code == 0) {
  93. that.setData({
  94. shareApprovallist: res.data.data,
  95. datashow: true
  96. })
  97. }
  98. }
  99. })
  100. },
  101. previewImageEvent(e) {
  102. let index = parseInt(e.currentTarget.dataset.index);
  103. let idx = parseInt(e.currentTarget.dataset.idx);
  104. wx.previewImage({
  105. urls: this.data.shareApprovallist[index].img,
  106. current: this.data.shareApprovallist[index].img[idx]
  107. })
  108. },
  109. closeDialog: function () {
  110. this.setData({
  111. showCutImage: false,
  112. showApproval: false
  113. })
  114. },
  115. getTextarea(e) {
  116. this.setData({
  117. remark: e.detail.value
  118. })
  119. },
  120. //审核通过
  121. confirmApproval(e) {
  122. let id = e.currentTarget.dataset.id;
  123. const that = this;
  124. wx.showModal({
  125. title: '审核提醒',
  126. content: '您确认通过审核吗?',
  127. complete: (res) => {
  128. if (res.confirm) {
  129. utils.$post({
  130. url: app.globalData.webUrl + 'api/agentEmp/validate_share',
  131. header: {
  132. 'Authorization': 'bearer ' + app.globalData.token
  133. },
  134. data: {
  135. share_id: id,
  136. status: 1
  137. },
  138. success: function (res) {
  139. if (res.data.code == 0) {
  140. wx.showToast({
  141. title: '已通过审核',
  142. icon: "none",
  143. duration: 1500,
  144. success: function() {
  145. setTimeout(() => {
  146. that.getBrokerApprovallist();
  147. },1000)
  148. }
  149. })
  150. }
  151. }
  152. })
  153. }
  154. }
  155. })
  156. },
  157. //审核拒绝
  158. rejectApproval(e) {
  159. let id = e.currentTarget.dataset.id;
  160. const that = this;
  161. wx.showModal({
  162. title: '审核提醒',
  163. content: '您确认驳回审核吗?',
  164. complete: (res) => {
  165. if (res.confirm) {
  166. utils.$post({
  167. url: app.globalData.webUrl + 'api/agentEmp/validate_share',
  168. header: {
  169. 'Authorization': 'bearer ' + app.globalData.token
  170. },
  171. data: {
  172. share_id: id,
  173. status: 2
  174. },
  175. success: function (res) {
  176. if (res.data.code == 0) {
  177. wx.showToast({
  178. title: '已驳回审核',
  179. icon: "none",
  180. duration: 1500,
  181. success: function() {
  182. setTimeout(() => {
  183. that.getBrokerApprovallist();
  184. },1000)
  185. }
  186. })
  187. }
  188. }
  189. })
  190. }
  191. }
  192. })
  193. },
  194. //上传分享截图
  195. submitData() {
  196. if (!this.data.trackimgarr.length) {
  197. wx.showToast({
  198. title: '请上传分享截图!',
  199. icon: "none",
  200. duration: 1500,
  201. })
  202. return false;
  203. }
  204. this.setData({
  205. loading: true
  206. })
  207. this.ossuploadimg();
  208. },
  209. uploadImage() {
  210. let _this = this;
  211. wx.chooseMedia({
  212. count: 9,
  213. mediaType: ["image"],
  214. sourceType: ["album", "camera"],
  215. sizeType: ['original', 'compressed'],
  216. success: function (res) {
  217. if (res.errMsg == "chooseMedia:ok") {
  218. _this.createImagePayment(res.tempFiles);
  219. }
  220. }
  221. })
  222. },
  223. imageDel(e) {
  224. let index = e.currentTarget.dataset.index;
  225. this.data.trackimgarr.splice(index, 1);
  226. this.setData({
  227. trackimgarr: this.data.trackimgarr
  228. })
  229. },
  230. createImagePayment: function (imgUrl) {
  231. var that = this;
  232. if (imgUrl.length == 0) return;
  233. var lent = that.data.trackimgarr.length + imgUrl.length;
  234. if (lent > 9) {
  235. lent = 9
  236. } else {
  237. lent = lent;
  238. }
  239. let trackimgarr = that.data.trackimgarr;
  240. let len = imgUrl.length;
  241. if ((trackimgarr.length + len) > 9) {
  242. for (let j = 0; j < len; j++) {
  243. if (trackimgarr.length < 9) {
  244. trackimgarr.push(imgUrl[j]);
  245. }
  246. }
  247. } else {
  248. trackimgarr = trackimgarr.concat(imgUrl);
  249. }
  250. that.setData({
  251. trackimgarr: trackimgarr
  252. })
  253. },
  254. ossuploadimg: function (e) {
  255. let that = this;
  256. let trackimgarr = that.data.trackimgarr;
  257. var arr = [];
  258. for (let i = 0; i < trackimgarr.length; i++) {
  259. //获取文件后缀
  260. // 随机生成文件名称
  261. let rstr = trackimgarr[i].tempFilePath.split('.');
  262. var fileRandName = Date.now() + "" + parseInt(Math.random() * 10000) + i;
  263. var imgName = fileRandName + '.' + 'png';
  264. // var fileName = that.data.;
  265. var date = new Date();
  266. var time = date.getFullYear() + '' + (date.getMonth() * 1 + 1) + '' + date.getDate();
  267. var imgstr = 'broker/' + time + '/' + imgName;
  268. var nowimagearr = that.data.nowimagearr;
  269. nowimagearr.push(imgstr);
  270. that.setData({
  271. nowimagearr: nowimagearr
  272. })
  273. wx.uploadFile({
  274. url: 'https://wzh-zqxg.oss-cn-hangzhou.aliyuncs.com',
  275. filePath: trackimgarr[i].tempFilePath,
  276. name: 'file',
  277. formData: {
  278. // name: that.data.imgSrc[0],
  279. key: 'broker/' + time + '/' + imgName,
  280. policy: "eyJleHBpcmF0aW9uIjoiMjA0MC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==",
  281. OSSAccessKeyId: "LTAI5tHjWupJSCAycy2yVbQZ",
  282. success_action_status: "200",
  283. signature: "GPu5wBYVzdhICS/hdJH6rKG0kos=",
  284. },
  285. header: {
  286. "Content-Type": "multipart/form-data",
  287. 'accept': 'application/json',
  288. },
  289. success: function (rs) {
  290. if (rs.errMsg == 'uploadFile:ok') {
  291. arr.push('0');
  292. if (arr.length == trackimgarr.length) {
  293. that.requestUploadImageApi();
  294. }
  295. }
  296. },
  297. fail(res) {
  298. wx.hideLoading()
  299. }
  300. })
  301. }
  302. },
  303. requestUploadImageApi() {
  304. let that = this;
  305. let imgs = that.data.nowimagearr.map(v => {
  306. return { serverId: "", img: v, };
  307. })
  308. utils.$post({
  309. url: app.globalData.webUrl + 'api/agentsWork/upload_share_log',
  310. header: {
  311. 'Authorization': 'bearer ' + app.globalData.token
  312. },
  313. data: {
  314. type: "Article",
  315. article_id: that.data.aid,
  316. file_media_id: imgs,
  317. remarks: that.data.remark
  318. },
  319. success: function (res) {
  320. that.setData({
  321. loading: false
  322. })
  323. if (res.data.code == '0') {
  324. wx.showToast({
  325. title: '上传成功',
  326. icon: "success",
  327. duration: 1500
  328. })
  329. that.setData({
  330. showCutImage: false
  331. })
  332. }
  333. }
  334. })
  335. },
  336. setpostertap: function () {
  337. if (this.data.bType == 'b') {
  338. wx.navigateTo({
  339. url: '/index/pages/setposter/setposter?type=article&aid=' + this.data.aid + "&ty=b&listshare=",
  340. })
  341. } else {
  342. wx.navigateTo({
  343. url: '/index/pages/setposter/setposter?type=article&aid=' + this.data.aid + "&listshare=",
  344. })
  345. }
  346. },
  347. priceshowtap() {
  348. this.setData({
  349. priceflag: true
  350. })
  351. },
  352. closepricetap() {
  353. this.setData({
  354. priceflag: false
  355. })
  356. },
  357. /**
  358. * 生命周期函数--监听页面初次渲染完成
  359. */
  360. onReady: function () {
  361. },
  362. articlesharetap: function () {
  363. this.setData({
  364. wshareshow: true
  365. })
  366. },
  367. artileMsg: function () {
  368. var that = this;
  369. utils.$post({
  370. url: app.globalData.webUrl + 'api/article/info',
  371. header: {
  372. 'Authorization': 'bearer ' + app.globalData.token
  373. },
  374. data: {
  375. article_id: that.data.aid
  376. },
  377. success: function (res) {
  378. if (res.data.code == '0') {
  379. that.setData({
  380. articleObj: res.data.data,
  381. title: res.data.data.title
  382. })
  383. wx.setNavigationBarTitle({
  384. title: res.data.data.title
  385. })
  386. }
  387. setTimeout(function () {
  388. wx.hideLoading();
  389. }, 1000)
  390. }
  391. })
  392. },
  393. /**
  394. * 生命周期函数--监听页面显示
  395. */
  396. onShow: function () {
  397. var that = this;
  398. if (app.globalData.sharearticle) {
  399. // wx.showToast({
  400. // title: '即将跳转原页面',
  401. // icon: 'success',
  402. // })
  403. setTimeout(function () {
  404. // wx.redirectTo({
  405. // url: "/mycustomer/pages/mycreation/mycreation?type=3",
  406. // });
  407. if (that.data.type == '2') {
  408. wx.redirectTo({
  409. url: "/mycustomer/pages/mycreation/mycreation?type=2",
  410. });
  411. } else if (that.data.type == '1') {
  412. wx.navigateBack({
  413. delta: 3
  414. });
  415. } else {
  416. wx.navigateBack({
  417. delta: 2
  418. });
  419. }
  420. }, 1000)
  421. }
  422. stoptime = 0;
  423. setTimeout(function () {
  424. stoptime = stoptime * 1 + 1;
  425. }, 1000)
  426. },
  427. shareurltap: function () {
  428. let that = this;
  429. wx.showLoading({
  430. title: '加载中...',
  431. })
  432. if (this.data.bType == 'b') {
  433. util.schemefun('/share/pages/articleshare/articleshare', 'aid=' + that.data.aid + '&userid=' + app.globalData.agentEmployeEid + '&ctp=' + app.globalData.clientype + '&agid=' + app.globalData.brokeruserId, that.data.aid, 'article', '');
  434. } else {
  435. util.schemefun('/share/pages/articleshare/articleshare', 'aid=' + that.data.aid + '&userid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, that.data.aid, 'article', '');
  436. }
  437. this.sharelogtap();
  438. },
  439. sharealerttap: function (e) {
  440. var that = this;
  441. that.setData({
  442. nowflag: true,
  443. })
  444. },
  445. sendfriendtap() {
  446. this.sharelogtap();
  447. },
  448. sharelogtap: function () {
  449. var that = this;
  450. this.setData({
  451. nowflag: false,
  452. })
  453. utils.$post({
  454. url: app.globalData.webUrl + 'api/share/addlog',
  455. header: {
  456. 'Authorization': 'bearer ' + app.globalData.token
  457. },
  458. data: {
  459. id: that.data.aid,
  460. type: 'article'
  461. },
  462. success: function (r) {}
  463. })
  464. },
  465. collectTap: function () {
  466. var that = this;
  467. utils.$post({
  468. url: app.globalData.webUrl + 'api/article/collect',
  469. header: {
  470. 'Authorization': 'bearer ' + app.globalData.token
  471. },
  472. data: {
  473. id: that.data.aid,
  474. },
  475. success: function (res) {
  476. var articleObj = that.data.articleObj;
  477. if (res.data.code == '0') {
  478. articleObj.collect = 1;
  479. that.setData({
  480. articleObj: articleObj
  481. })
  482. wx.showToast({
  483. title: '收藏成功!',
  484. icon: 'none',
  485. duration: 1000
  486. })
  487. that.setData({
  488. articleObj: articleObj
  489. })
  490. }
  491. }
  492. })
  493. },
  494. cancleTap: function () {
  495. var that = this;
  496. utils.$post({
  497. url: app.globalData.webUrl + 'api/article/collectCancel',
  498. header: {
  499. 'Authorization': 'bearer ' + app.globalData.token
  500. },
  501. data: {
  502. id: that.data.aid,
  503. },
  504. success: function (res) {
  505. var articleObj = that.data.articleObj;
  506. if (res.data.code == '0') {
  507. articleObj.collect = 0;
  508. that.setData({
  509. articleObj: articleObj
  510. })
  511. wx.showToast({
  512. title: '取消收藏成功!',
  513. icon: 'none',
  514. duration: 1000
  515. })
  516. that.setData({
  517. articleObj: articleObj
  518. })
  519. }
  520. }
  521. })
  522. },
  523. zantap: function () {
  524. var that = this;
  525. utils.$post({
  526. url: app.globalData.webUrl + 'api/article/star',
  527. header: {
  528. 'Authorization': 'bearer ' + app.globalData.token
  529. },
  530. data: {
  531. id: that.data.aid,
  532. },
  533. success: function (res) {
  534. var articleObj = that.data.articleObj;
  535. if (res.data.code == '0') {
  536. if (articleObj.stared == 1) {
  537. wx.showToast({
  538. title: '您已点赞!',
  539. icon: 'none',
  540. duration: 1000
  541. })
  542. } else {
  543. articleObj.stared = 1;
  544. wx.showToast({
  545. title: '点赞成功!',
  546. icon: 'none',
  547. duration: 1000
  548. })
  549. articleObj.star_num = articleObj.star_num * 1 + 1;
  550. }
  551. that.setData({
  552. articleObj: articleObj
  553. })
  554. }
  555. }
  556. })
  557. },
  558. /**
  559. * 生命周期函数--监听页面隐藏
  560. */
  561. onHide: function () {
  562. var timearr = app.globalData.timearr,
  563. flag = false;
  564. for (var i = 0; i < timearr.length; i++) {
  565. if (timearr[i].type == 'articleprelook') {
  566. timearr[i].time = timearr[i].time * 1 + stoptime * 1;
  567. flag = true;
  568. }
  569. }
  570. if (!flag) {
  571. var obj = {
  572. type: 'articleprelook',
  573. time: stoptime
  574. };
  575. app.globalData.timearr.push(obj);
  576. } else {
  577. app.globalData.timearr = timearr;
  578. }
  579. },
  580. /**
  581. * 生命周期函数--监听页面卸载
  582. */
  583. onUnload: function () {
  584. },
  585. /**
  586. * 页面相关事件处理函数--监听用户下拉动作
  587. */
  588. onPullDownRefresh: function () {
  589. },
  590. /**
  591. * 页面上拉触底事件的处理函数
  592. */
  593. onReachBottom: function () {
  594. },
  595. /**
  596. * 用户点击右上角分享
  597. */
  598. onShareAppMessage: function () {
  599. var img = this.data.articleObj.cover_share_img?this.data.articleObj.cover_share_img:this.data.articleObj.cover_img;
  600. if (this.data.bType == 'b') {
  601. this.sharelogtap();
  602. return {
  603. title: this.data.articleObj.title,
  604. imageUrl: img,
  605. path: '/share/pages/articleshare/articleshare?aid=' + this.data.aid + '&userid=' + app.globalData.agentEmployeEid + '&ctp=' + app.globalData.clientype + '&agid=' + app.globalData.brokeruserId
  606. }
  607. } else {
  608. this.sharelogtap();
  609. return {
  610. title: this.data.articleObj.title,
  611. imageUrl: img,
  612. path: '/share/pages/articleshare/articleshare?aid=' + this.data.aid + '&userid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
  613. }
  614. }
  615. }
  616. })