index.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. // pages/product-con/index.js
  2. var app = getApp();
  3. var wxh = require('../../utils/wxh.js');
  4. var WxParse = require('../../wxParse/wxParse.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. storeImage: '',//海报产品图
  11. PromotionCode: '',//二维码图片
  12. canvasStatus: false,//海报绘图标签
  13. posterImage:'',//海报路径
  14. posterImageStatus:false,
  15. attrName:'',
  16. attr:'选择商品属性',
  17. attrValue:'',
  18. url: app.globalData.urlImages,
  19. storeInfo: [],
  20. storeKeyWord:[],
  21. similarity: [],
  22. productAttr: [],
  23. productValue: [],
  24. productSelect:[
  25. { image: "" },
  26. { store_name: "" },
  27. { price: 0 },
  28. { unique: "" },
  29. { stock: 0 },
  30. ],
  31. reply: [],
  32. replyCount:0,
  33. description:'',
  34. collect:false,//是否收藏
  35. indicatorDots: true,//是否显示面板指示点;
  36. autoplay: true,//是否自动播放;
  37. interval: 3000,//动画间隔的时间;
  38. duration: 500,//动画播放的时长;
  39. indicatorColor: "rgba(51, 51, 51, .3)",
  40. indicatorActivecolor: "#ffffff",
  41. id:0,
  42. num: 1,
  43. show: false,
  44. prostatus: false,
  45. CartCount:0,
  46. status:0,
  47. actionSheetHidden:true,
  48. },
  49. setTouchMove: function (e) {
  50. var that = this;
  51. wxh.home(that, e);
  52. },
  53. goPhone: function () {
  54. wx.request({
  55. url: app.globalData.url + '/routine/auth_api/get_site_phone?uid=' + app.globalData.uid,
  56. method: 'GET',
  57. success: function (res) {
  58. wx.makePhoneCall({
  59. phoneNumber: res.data.msg,
  60. })
  61. }
  62. })
  63. },
  64. setNumber:function(e){
  65. var that = this;
  66. var num = parseInt(e.detail.value);
  67. that.setData({
  68. num: num ? num : 1
  69. })
  70. },
  71. goCoupon:function(){
  72. wx.navigateTo({
  73. url: "/pages/coupon-status/coupon-status"
  74. })
  75. },
  76. getAttrInfo:function(){
  77. var that = this;
  78. wxh.footan(that);
  79. that.setData({
  80. status:1
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面加载
  85. */
  86. onLoad: function (options) {
  87. // console.log(options);
  88. // return ;
  89. app.globalData.openPages = '/pages/product-con/index?id=' + options.id;
  90. app.setBarColor();
  91. var that = this;
  92. app.setUserInfo();
  93. that.getCartCount();
  94. that.setData({
  95. id: options.id
  96. })
  97. var header = {
  98. 'content-type': 'application/x-www-form-urlencoded',
  99. };
  100. wx.request({
  101. url: app.globalData.url + '/routine/auth_api/details?uid=' + app.globalData.uid,
  102. method: 'POST',
  103. data:{
  104. id:that.data.id
  105. },
  106. header: header,
  107. success: function (res) {
  108. if(res.data.code == 200){
  109. var image = "productSelect.image";
  110. var store_name = "productSelect.store_name";
  111. var price = "productSelect.price";
  112. var unique = "productSelect.unique";
  113. var stock = "productSelect.stock";
  114. that.setData({
  115. storeInfo: res.data.data.storeInfo,
  116. storeKeyWord: res.data.data.storeInfo.keyword.split(","),
  117. similarity: res.data.data.similarity,
  118. productAttr: res.data.data.productAttr,
  119. productValue: res.data.data.productValue,
  120. reply: res.data.data.reply,
  121. replyCount: res.data.data.replyCount,
  122. description: res.data.data.storeInfo.description,
  123. collect:res.data.data.storeInfo.userCollect,
  124. [image]: res.data.data.storeInfo.image,
  125. [stock]: res.data.data.storeInfo.stock,
  126. [store_name]: res.data.data.storeInfo.store_name,
  127. [price]: res.data.data.storeInfo.price,
  128. [unique]: ''
  129. })
  130. that.downloadFilestoreImage();
  131. that.downloadFilePromotionCode();
  132. WxParse.wxParse('description', 'html', that.data.description, that, 0);
  133. }else{
  134. wx.showToast({
  135. title: res.data.msg,
  136. icon: 'none',
  137. duration: 1000
  138. })
  139. setTimeout(function(){
  140. wx.navigateBack({});
  141. },1200)
  142. }
  143. }
  144. })
  145. },
  146. listenerActionSheet: function () {
  147. this.setData({
  148. actionSheetHidden: !this.data.actionSheetHidden
  149. })
  150. },
  151. // 保存海报图片
  152. savePosterPath: function () {
  153. var that = this;
  154. wx.getSetting({
  155. success(res) {
  156. if (!res.authSetting['scope.writePhotosAlbum']) {
  157. wx.authorize({
  158. scope: 'scope.writePhotosAlbum',
  159. success() {
  160. wx.saveImageToPhotosAlbum({
  161. filePath: that.data.posterImage,
  162. success: function (res) {
  163. that.posterImageClose();
  164. wx.showToast({
  165. title: '保存成功',
  166. icon: 'success',
  167. duration: 1500,
  168. })
  169. },
  170. fail: function (res) {
  171. wx.showToast({
  172. title: '保存失败',
  173. icon: 'none',
  174. duration: 1500,
  175. })
  176. },
  177. complete: function (res) { },
  178. })
  179. }
  180. })
  181. } else {
  182. wx.saveImageToPhotosAlbum({
  183. filePath: that.data.posterImage,
  184. success: function (res) {
  185. that.posterImageClose();
  186. wx.showToast({
  187. title: '保存成功',
  188. icon: 'success',
  189. duration: 1500,
  190. })
  191. },
  192. fail: function (res) {
  193. wx.showToast({
  194. title: '保存失败',
  195. icon: 'none',
  196. duration: 1500,
  197. })
  198. },
  199. complete: function (res) { },
  200. })
  201. }
  202. }
  203. })
  204. },
  205. //生成海报获取文字
  206. textByteLength: function(text, num) { // text为传入的文本 num为单行显示的字节长度
  207. let strLength = 0;
  208. let rows = 1;
  209. let str = 0;
  210. let arr = [];
  211. for (let j = 0; j < text.length; j++) {
  212. if (text.charCodeAt(j) > 255) {
  213. strLength += 2;
  214. if (strLength > rows * num) {
  215. strLength++;
  216. arr.push(text.slice(str, j));
  217. str = j;
  218. rows++;
  219. }
  220. } else {
  221. strLength++;
  222. if (strLength > rows * num) {
  223. arr.push(text.slice(str, j));
  224. str = j;
  225. rows++;
  226. }
  227. }
  228. }
  229. arr.push(text.slice(str, text.length));
  230. return [strLength, arr, rows] // [处理文字的总字节长度,每行显示内容的数组,行数]
  231. },
  232. //隐藏海报
  233. posterImageClose: function () {
  234. this.setData({
  235. posterImageStatus: false,
  236. })
  237. },
  238. //替换安全域名
  239. setDomain:function(url){
  240. if(url.indexOf("https://") > -1) return url;
  241. else return url.replace('http://','https://');
  242. },
  243. //获取海报产品图
  244. downloadFilestoreImage:function(){
  245. var that = this;
  246. wx.downloadFile({
  247. url: that.setDomain(that.data.storeInfo.image),
  248. success: function (res) {
  249. that.setData({
  250. storeImage : res.tempFilePath
  251. })
  252. }
  253. });
  254. },
  255. //获取产品分销二维码
  256. downloadFilePromotionCode:function(){
  257. var that = this;
  258. wx.request({
  259. url: app.globalData.url + '/routine/auth_api/product_promotion_code?uid=' + app.globalData.uid,
  260. method: 'GET',
  261. data: { id: that.data.id, },
  262. success: function (res) {
  263. if (res.data.code == 200) {
  264. wx.downloadFile({
  265. url: that.setDomain(res.data.msg),
  266. success: function (res) {
  267. that.setData({
  268. PromotionCode: res.tempFilePath
  269. })
  270. }
  271. });
  272. }else{
  273. that.setData({
  274. PromotionCode: ''
  275. })
  276. }
  277. }
  278. });
  279. },
  280. //生成海报
  281. goPoster:function(){
  282. var that = this;
  283. wx.showLoading({
  284. title: '海报生成中',
  285. mask: true,
  286. })
  287. that.setData({ canvasStatus: true });
  288. const arr2 = ['/images/posterbackgd.png', that.data.storeImage, that.data.PromotionCode];
  289. console.log(arr2);
  290. if (arr2[2] == '') {
  291. wx.request({
  292. url: app.globalData.url + '/routine/auth_api/product_promotion_code?uid=' + app.globalData.uid,
  293. method: 'GET',
  294. data: { id: that.data.id, },
  295. success: function (res) {
  296. if (res.data.code == 200) {
  297. const msgPromotionCode = res.data.msg;
  298. const ctx = wx.createCanvasContext('myCanvas');
  299. ctx.clearRect(0, 0, 0, 0);
  300. wx.downloadFile({
  301. url: that.setDomain(msgPromotionCode),
  302. success: function (res) {
  303. arr2[2] = res.tempFilePath;
  304. wx.getImageInfo({
  305. src: arr2[0],
  306. success: function (res) {
  307. const WIDTH = res.width;
  308. const HEIGHT = res.height;
  309. ctx.drawImage(arr2[0], 0, 0, WIDTH, HEIGHT);
  310. ctx.drawImage(arr2[1], 0, 0, WIDTH, WIDTH);
  311. ctx.save();
  312. let r = 90;
  313. let d = r * 2;
  314. let cx = 40;
  315. let cy = 990;
  316. ctx.arc(cx + r, cy + r, r, 0, 2 * Math.PI);
  317. ctx.clip();
  318. ctx.drawImage(arr2[2], cx, cy, d, d);
  319. ctx.restore();
  320. const CONTENT_ROW_LENGTH = 40;
  321. let [contentLeng, contentArray, contentRows] = that.textByteLength(that.data.storeInfo.store_name, CONTENT_ROW_LENGTH);
  322. ctx.setTextAlign('center')
  323. ctx.setFontSize(32);
  324. let contentHh = 32 * 1.3;
  325. for (let m = 0; m < contentArray.length; m++) {
  326. ctx.fillText(contentArray[m], WIDTH / 2, 820 + contentHh * m);
  327. }
  328. ctx.setTextAlign('center')
  329. ctx.setFontSize(48);
  330. ctx.setFillStyle('red');
  331. ctx.fillText('¥' + that.data.storeInfo.price, WIDTH / 2, 860 + contentHh);
  332. ctx.draw(true, function () {
  333. wx.canvasToTempFilePath({
  334. canvasId: 'myCanvas',
  335. fileType: 'png',
  336. destWidth: WIDTH,
  337. destHeight: HEIGHT,
  338. success: function (res) {
  339. wx.hideLoading();
  340. that.setData({
  341. posterImage: res.tempFilePath,
  342. posterImageStatus: true,
  343. canvasStatus: false,
  344. actionSheetHidden: !that.data.actionSheetHidden
  345. })
  346. }
  347. })
  348. });
  349. },
  350. })
  351. }
  352. });
  353. } else {
  354. wx.showToast({
  355. title: res.data.msg,
  356. icon: 'none',
  357. duration: 1500,
  358. mask: true,
  359. })
  360. }
  361. }
  362. });
  363. }else{
  364. const ctx = wx.createCanvasContext('myCanvas');
  365. ctx.clearRect(0, 0, 0, 0);
  366. wx.getImageInfo({
  367. src: arr2[0],
  368. success: function (res) {
  369. const WIDTH = res.width;
  370. const HEIGHT = res.height;
  371. ctx.drawImage(arr2[0], 0, 0, WIDTH, HEIGHT);
  372. ctx.drawImage(arr2[1], 0, 0, WIDTH, WIDTH);
  373. ctx.save();
  374. let r = 90;
  375. let d = r * 2;
  376. let cx = 40;
  377. let cy = 990;
  378. ctx.arc(cx + r, cy + r, r, 0, 2 * Math.PI);
  379. ctx.clip();
  380. ctx.drawImage(arr2[2], cx, cy, d, d);
  381. ctx.restore();
  382. const CONTENT_ROW_LENGTH = 40;
  383. let [contentLeng, contentArray, contentRows] = that.textByteLength(that.data.storeInfo.store_name, CONTENT_ROW_LENGTH);
  384. ctx.setTextAlign('center')
  385. ctx.setFontSize(32);
  386. let contentHh = 32 * 1.3;
  387. for (let m = 0; m < contentArray.length; m++) {
  388. ctx.fillText(contentArray[m], WIDTH / 2, 820 + contentHh * m);
  389. }
  390. ctx.setTextAlign('center')
  391. ctx.setFontSize(48);
  392. ctx.setFillStyle('red');
  393. ctx.fillText('¥' + that.data.storeInfo.price, WIDTH / 2, 860 + contentHh);
  394. ctx.draw(true, function () {
  395. wx.canvasToTempFilePath({
  396. canvasId: 'myCanvas',
  397. fileType: 'png',
  398. destWidth: WIDTH,
  399. destHeight: HEIGHT,
  400. success: function (res) {
  401. wx.hideLoading();
  402. that.setData({
  403. posterImage: res.tempFilePath,
  404. posterImageStatus: true,
  405. canvasStatus: false,
  406. actionSheetHidden: !that.data.actionSheetHidden
  407. })
  408. }
  409. })
  410. });
  411. },
  412. })
  413. }
  414. },
  415. goPhoto:function(){
  416. var that = this;
  417. wx.showActionSheet({
  418. itemList: ['发送给朋友', '生成海报'],
  419. success: function (res) {
  420. if (res.tapIndex){
  421. wx.request({
  422. url: app.globalData.url + '/routine/auth_api/get_pages?uid=' + app.globalData.uid,
  423. method: 'GET',
  424. data: {
  425. path: app.globalData.openPages,
  426. productId: that.data.id
  427. },
  428. success: function (res) {
  429. console.log(res);
  430. }
  431. })
  432. }else{
  433. that.onShareAppMessage();
  434. }
  435. },
  436. fail: function (res) {
  437. console.log(res.errMsg)
  438. }
  439. })
  440. },
  441. parameterShow: function () {
  442. var that = this;
  443. if (that.data.productSelect.unique != ''){
  444. var header = {
  445. 'content-type': 'application/x-www-form-urlencoded',
  446. };
  447. wx.request({
  448. url: app.globalData.url + '/routine/auth_api/set_cart?uid=' + app.globalData.uid,
  449. method: 'GET',
  450. data: {
  451. productId: that.data.id,
  452. cartNum: that.data.num,
  453. uniqueId: that.data.productSelect.unique
  454. },
  455. header: header,
  456. success: function (res) {
  457. if (res.data.code == 200) {
  458. wx.showToast({
  459. title: '添加购物车成功',
  460. icon: 'success',
  461. duration: 2000
  462. })
  463. that.setData({
  464. prostatus: false
  465. })
  466. that.getCartCount();
  467. } else {
  468. wx.showToast({
  469. title: res.data.msg,
  470. icon: 'none',
  471. duration: 2000
  472. })
  473. }
  474. }
  475. })
  476. } else {
  477. wxh.footan(that);
  478. that.setData({
  479. status: 2
  480. })
  481. }
  482. },
  483. goOrder: function () {
  484. var that = this;
  485. if (that.data.productSelect.unique != '') {
  486. var header = {
  487. 'content-type': 'application/x-www-form-urlencoded',
  488. };
  489. wx.request({
  490. url: app.globalData.url + '/routine/auth_api/now_buy?uid=' + app.globalData.uid,
  491. method: 'GET',
  492. data: {
  493. productId: that.data.id,
  494. cartNum: that.data.num,
  495. uniqueId: that.data.productSelect.unique
  496. },
  497. header: header,
  498. success: function (res) {
  499. if (res.data.code == 200) {
  500. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  501. url: '/pages/order-confirm/order-confirm?id=' + res.data.data.cartId
  502. })
  503. } else {
  504. wx.showToast({
  505. title: res.data.msg,
  506. icon: 'none',
  507. duration: 2000
  508. })
  509. }
  510. }
  511. })
  512. } else {
  513. wxh.footan(that);
  514. that.setData({
  515. status: 3
  516. })
  517. }
  518. },
  519. modelbg: function (e) {
  520. this.setData({
  521. prostatus: false
  522. })
  523. },
  524. bindMinus: function () {
  525. var that = this;
  526. wxh.carmin(that)
  527. },
  528. bindPlus: function () {
  529. var that = this;
  530. wxh.carjia(that);
  531. },
  532. tapsize: function (e) {
  533. var that = this;
  534. var key = e.currentTarget.dataset.key;
  535. var attrValues = [];
  536. var attrName = that.data.attrName;
  537. var attrNameArr = attrName.split(",");
  538. var array = that.data.productAttr;
  539. for (var i in that.data.productAttr){
  540. for (var j in that.data.productAttr[i]['attr_values']){
  541. if (that.data.productAttr[i]['attr_values'][j] == key){
  542. attrValues = that.data.productAttr[i]['attr_values'];
  543. }
  544. }
  545. }
  546. for (var ii in attrNameArr) {
  547. if (that.in_array(attrNameArr[ii],attrValues)){
  548. attrNameArr.splice(ii, 1);
  549. }
  550. }
  551. attrName = attrNameArr.join(',');
  552. if (attrName) var eName = e.currentTarget.dataset.key + ',' + attrName;
  553. else var eName = e.currentTarget.dataset.key;
  554. attrNameArr = eName.split(",");
  555. var isBool = false;
  556. var isattrNameArrLength = 0;
  557. for (var an in attrNameArr) {
  558. if (attrNameArr[an]) isattrNameArrLength = isattrNameArrLength + 1;
  559. }
  560. for (var b in that.data.productValue) {
  561. var sukValue = that.data.productValue[b].suk.split(",");
  562. if (sukValue.length == isattrNameArrLength) {
  563. if (that.in_array_two(attrNameArr, sukValue)) {
  564. isBool = true;
  565. }
  566. } else {
  567. isBool = true;
  568. }
  569. }
  570. if (!isBool){
  571. wx.showToast({
  572. title: '属性不存在,请重新选择',
  573. icon: 'none',
  574. duration: 1500,
  575. })
  576. } else {
  577. that.setData({
  578. attrName: e.currentTarget.dataset.key + ',' + attrName
  579. })
  580. attrNameArr = that.data.attrName.split(",");
  581. var attrNameArrSort = '';
  582. for (var jj in that.data.productAttr) {
  583. for (var jjj in that.data.productAttr[jj]['attr_values']) {
  584. if (that.in_array(that.data.productAttr[jj]['attr_values'][jjj], attrNameArr)) {
  585. attrNameArrSort += that.data.productAttr[jj]['attr_values'][jjj] + ',';
  586. }
  587. }
  588. }
  589. for (var jj in array) {
  590. for (var jjj in array[jj]['attr_values']) {
  591. if (that.in_array(array[jj]['attr_values'][jjj], attrNameArr)) {
  592. array[jj]['attr_value'][jjj].check = true;
  593. } else {
  594. array[jj]['attr_value'][jjj].check = false;
  595. }
  596. }
  597. }
  598. that.setData({
  599. productAttr: array
  600. })
  601. var attrNameArrSortArr = attrNameArrSort.split(",");
  602. attrNameArrSortArr.pop();
  603. that.setData({
  604. attrName: attrNameArrSortArr.join(',')
  605. })
  606. var arrAttrName = that.data.attrName.split(",");
  607. for (var index in that.data.productValue) {
  608. var strValue = that.data.productValue[index]['suk'];
  609. var arrValue = strValue.split(",");
  610. if (that.in_array_two(arrValue, arrAttrName)) {
  611. var image = "productSelect.image";
  612. var store_name = "productSelect.store_name";
  613. var price = "productSelect.price";
  614. var unique = "productSelect.unique";
  615. var stock = "productSelect.stock";
  616. that.setData({
  617. [image]: that.data.productValue[index]['image'],
  618. [price]: that.data.productValue[index]['price'],
  619. [unique]: that.data.productValue[index]['unique'],
  620. [stock]: that.data.productValue[index]['stock'],
  621. })
  622. }
  623. }
  624. }
  625. },
  626. in_array_two:function(arr1,arr2){
  627. if (arr1.sort().toString() == arr2.sort().toString()) {
  628. return true;
  629. }
  630. else {
  631. return false;
  632. }
  633. },
  634. in_array: function (str, arr) {
  635. for (var f1 in arr) {
  636. if (arr[f1] == str) {
  637. return true;
  638. }
  639. }
  640. },
  641. tapcolor: function (e) {
  642. var that = this;
  643. wxh.tapcolor(that, e);
  644. },
  645. subBuy:function(e){
  646. wx.request({
  647. url: app.globalData.url + '/routine/auth_api/get_form_id?uid=' + app.globalData.uid,
  648. method: 'GET',
  649. data: {
  650. formId: e.detail.formId
  651. },
  652. success: function (res) {}
  653. })
  654. var that = this;
  655. if (that.data.num > that.data.productSelect.stock){
  656. wx.showToast({
  657. title: '库存不足' + that.data.num,
  658. icon: 'none',
  659. duration: 2000
  660. })
  661. that.setData({
  662. num: that.data.productSelect.stock,
  663. })
  664. } else if (that.data.productAttr.length > 0 && that.data.productSelect.unique == '') {
  665. wx.showToast({
  666. title: '请选择属性',
  667. icon: 'none',
  668. duration: 2000
  669. })
  670. }else{
  671. if (that.data.status == 1){
  672. var attrValueData = [];
  673. for (var i in that.data.productValue){
  674. if (that.data.productValue[i].unique == that.data.productSelect.unique) {
  675. for (var j in that.data.productAttr) {
  676. for (var k in that.data.productAttr[j].attr_values) {
  677. var sukArr = that.data.productValue[i].suk.split(',');
  678. if (that.in_array(that.data.productAttr[j].attr_values[k], sukArr)){
  679. attrValueData.push(that.data.productAttr[j].attr_name + ':' + that.data.productAttr[j].attr_values[k]) ;
  680. }
  681. }
  682. }
  683. }
  684. }
  685. that.setData({
  686. attr:'已选',
  687. attrValue: attrValueData.join(','),
  688. prostatus: false
  689. })
  690. }else if (that.data.status == 2) {
  691. var header = {
  692. 'content-type': 'application/x-www-form-urlencoded',
  693. };
  694. wx.request({
  695. url: app.globalData.url + '/routine/auth_api/set_cart?uid=' + app.globalData.uid,
  696. method: 'GET',
  697. data: {
  698. productId: that.data.id,
  699. cartNum: that.data.num,
  700. uniqueId: that.data.productSelect.unique
  701. },
  702. header: header,
  703. success: function (res) {
  704. if (res.data.code == 200) {
  705. wx.showToast({
  706. title: '添加购物车成功',
  707. icon: 'success',
  708. duration: 2000
  709. })
  710. that.setData({
  711. prostatus: false
  712. })
  713. that.getCartCount();
  714. } else {
  715. wx.showToast({
  716. title: res.data.msg,
  717. icon: 'none',
  718. duration: 2000
  719. })
  720. }
  721. }
  722. })
  723. } else if (that.data.status == 3){
  724. var header = {
  725. 'content-type': 'application/x-www-form-urlencoded',
  726. };
  727. wx.request({
  728. url: app.globalData.url + '/routine/auth_api/now_buy?uid=' + app.globalData.uid,
  729. method: 'GET',
  730. data: {
  731. productId: that.data.id,
  732. cartNum: that.data.num,
  733. uniqueId: that.data.productSelect.unique
  734. },
  735. header: header,
  736. success: function (res) {
  737. if (res.data.code == 200) {
  738. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  739. url: '/pages/order-confirm/order-confirm?id=' + res.data.data.cartId
  740. })
  741. } else {
  742. wx.showToast({
  743. title: res.data.msg,
  744. icon: 'none',
  745. duration: 2000
  746. })
  747. }
  748. }
  749. })
  750. }
  751. }
  752. },
  753. getCartCount:function(){
  754. var that = this;
  755. var header = {
  756. 'content-type': 'application/x-www-form-urlencoded',
  757. };
  758. wx.request({
  759. url: app.globalData.url + '/routine/auth_api/get_cart_num?uid=' + app.globalData.uid,
  760. method: 'POST',
  761. header: header,
  762. success: function (res) {
  763. that.setData({
  764. CartCount: res.data.data
  765. })
  766. }
  767. })
  768. },
  769. setCollect:function(){
  770. if (this.data.collect) this.unCollectProduct();
  771. else this.collectProduct();
  772. },
  773. unCollectProduct: function () {
  774. var that = this;
  775. var header = {
  776. 'content-type': 'application/x-www-form-urlencoded',
  777. };
  778. wx.request({
  779. url: app.globalData.url + '/routine/auth_api/uncollect_product?uid=' + app.globalData.uid,
  780. method: 'POST',
  781. header: header,
  782. data: {
  783. productId: that.data.id
  784. },
  785. success: function (res) {
  786. wx.showToast({
  787. title: '取消收藏成功',
  788. icon: 'success',
  789. duration: 1500,
  790. })
  791. that.setData({
  792. collect: false,
  793. })
  794. }
  795. })
  796. },
  797. collectProduct:function(){
  798. var that = this;
  799. var header = {
  800. 'content-type': 'application/x-www-form-urlencoded',
  801. };
  802. wx.request({
  803. url: app.globalData.url + '/routine/auth_api/collect_product?uid=' + app.globalData.uid,
  804. method: 'POST',
  805. header: header,
  806. data:{
  807. productId:that.data.id
  808. },
  809. success: function (res) {
  810. wx.showToast({
  811. title: '收藏成功',
  812. icon: 'success',
  813. duration: 1500,
  814. })
  815. that.setData({
  816. collect: true,
  817. })
  818. }
  819. })
  820. },
  821. getCar:function(){
  822. wx.switchTab({
  823. url: '/pages/buycar/buycar'
  824. });
  825. },
  826. /**
  827. * 生命周期函数--监听页面初次渲染完成
  828. */
  829. onReady: function () {
  830. },
  831. /**
  832. * 生命周期函数--监听页面显示
  833. */
  834. onShow: function () {
  835. },
  836. /**
  837. * 生命周期函数--监听页面隐藏
  838. */
  839. onHide: function () {
  840. },
  841. /**
  842. * 生命周期函数--监听页面卸载
  843. */
  844. onUnload: function () {
  845. },
  846. /**
  847. * 页面相关事件处理函数--监听用户下拉动作
  848. */
  849. onPullDownRefresh: function () {
  850. },
  851. /**
  852. * 页面上拉触底事件的处理函数
  853. */
  854. onReachBottom: function () {
  855. },
  856. /**
  857. * 用户点击右上角分享
  858. */
  859. onShareAppMessage: function () {
  860. var that = this;
  861. that.setData({
  862. actionSheetHidden: !that.data.actionSheetHidden
  863. })
  864. return {
  865. title: that.data.productSelect.store_name,
  866. path: app.globalData.openPages,
  867. // imageUrl: that.data.url + that.data.product.image,
  868. success: function () {
  869. wx.showToast({
  870. title: '分享成功',
  871. icon: 'success',
  872. duration: 2000
  873. })
  874. }
  875. }
  876. }
  877. })