index.js 31 KB

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