index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. import { getProductDetail, getProductCode, collectAdd, collectDel, postCartAdd,getShare } from '../../api/store.js';
  2. import { getUserInfo, userShare } from '../../api/user.js';
  3. import { getCoupons,setFormId} from '../../api/api.js';
  4. import { getCartCounts } from '../../api/order.js';
  5. import WxParse from '../../wxParse/wxParse.js';
  6. import util from '../../utils/util.js';
  7. import wxh from '../../utils/wxh.js';
  8. import { CACHE_LONGITUDE, CACHE_LATITUDE } from '../../config.js';
  9. const app = getApp();
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. parameter: {
  16. 'navbar': '1',
  17. 'return': '1',
  18. 'title': '商品详情'
  19. },
  20. attribute: { 'cartAttr': false },//属性是否打开
  21. coupon: {
  22. 'coupon': false,
  23. list: [],
  24. },
  25. attr: '请选择',//属性页面提示
  26. attrValue: '',//已选属性
  27. animated: false,//购物车动画
  28. id: 0,//商品id
  29. replyCount: 0,//总评论数量
  30. reply: [],//评论列表
  31. storeInfo: {},//商品详情
  32. productAttr: [],//组件展示属性
  33. productValue: [],//系统属性
  34. couponList: [], //优惠券
  35. productSelect: {}, //属性选中规格
  36. cart_num: 1,//购买数量
  37. isAuto: false,//没有授权的不会自动授权
  38. iShidden: true,//是否隐藏授权
  39. isOpen: false,//是否打开属性组件
  40. isLog: app.globalData.isLog,//是否登录
  41. actionSheetHidden: true,
  42. posterImageStatus: false,
  43. storeImage: '',//海报产品图
  44. PromotionCode: '',//二维码图片
  45. canvasStatus: false,//海报绘图标签
  46. posterImage: '',//海报路径
  47. posterbackgd: '/images/posterbackgd.png',
  48. sharePacket: {
  49. isState: true,//默认不显示
  50. priceName: 0,
  51. },//分销商详细
  52. uid: 0,//用户uid
  53. circular: false,
  54. autoplay: false,
  55. interval: 3000,
  56. duration: 500,
  57. clientHeight: "",
  58. systemStore: {},//门店信息
  59. good_list: [],
  60. isDown: true,
  61. storeSelfMention: true,
  62. storeItems: {},
  63. storeList: [],
  64. activity:[],
  65. iSplus:true,
  66. navH: "",
  67. navList: [],
  68. opacity: 0,
  69. scrollY:0,
  70. topArr:[],
  71. toView: '',
  72. height: 0,
  73. heightArr: [],
  74. lock: false,
  75. scrollTop:0
  76. },
  77. returns: function () {
  78. wx.navigateBack();
  79. },
  80. tap: function (e) {
  81. var id = e.currentTarget.dataset.id;
  82. var index = e.currentTarget.dataset.index;
  83. var that = this;
  84. if (!this.data.good_list.length && id == "past2") {
  85. id = "past3"
  86. }
  87. this.setData({
  88. toView: id,
  89. navActive: index,
  90. lock: true,
  91. scrollTop:index>0?that.data.topArr[index]-(app.globalData.navHeight/2):that.data.topArr[index]
  92. });
  93. },
  94. scroll: function (e) {
  95. var that = this, scrollY = e.detail.scrollTop;
  96. var opacity = scrollY / 200;
  97. opacity = opacity > 1 ? 1 : opacity;
  98. that.setData({
  99. opacity: opacity,
  100. scrollY: scrollY
  101. })
  102. if (that.data.lock) {
  103. that.setData({
  104. lock: false
  105. })
  106. return;
  107. }
  108. for (var i = 0; i < that.data.topArr.length; i++) {
  109. if (scrollY < that.data.topArr[i]-(app.globalData.navHeight/2) + that.data.heightArr[i]) {
  110. that.setData({
  111. navActive: i
  112. });
  113. break
  114. }
  115. }
  116. },
  117. /**
  118. * 登录后加载
  119. *
  120. */
  121. onLoadFun: function (e) {
  122. this.setData({ isLog: true });
  123. // this.getCouponList();
  124. this.getCartCount();
  125. this.downloadFilePromotionCode();
  126. this.getUserInfo();
  127. // this.get_product_collect();
  128. },
  129. ChangCouponsClone: function () {
  130. this.setData({ 'coupon.coupon': false });
  131. },
  132. goActivity: function (e) {
  133. let item = e.currentTarget.dataset.items;
  134. if (item.type === "1") {
  135. wx.navigateTo({
  136. url: `/pages/activity/goods_seckill_details/index?id=${item.id}&time=${item.time}&status=1`
  137. });
  138. } else if (item.type === "2") {
  139. wx.navigateTo({ url: `/pages/activity/goods_bargain_details/index?id=${item.id}`});
  140. } else {
  141. wx.navigateTo({ url: `/pages/activity/goods_combination_details/index?id=${item.id}`});
  142. }
  143. },
  144. /**
  145. * 商品详情跳转
  146. */
  147. goDetail: function (e) {
  148. let item = e.currentTarget.dataset.items;
  149. if (item.activity && item.activity.type === "1") {
  150. wx.navigateTo({
  151. url: `/pages/activity/goods_seckill_details/index?id=${item.activity.id}&time=${item.activity.time}&status=1`
  152. });
  153. } else if (item.activity && item.activity.type === "2") {
  154. wx.navigateTo({ url: `/pages/activity/goods_bargain_details/index?id=${item.activity.id}`});
  155. } else if (item.activity && item.activity.type === "3") {
  156. wx.navigateTo({
  157. url: `/pages/activity/goods_combination_details/index?id=${item.activity.id}`
  158. });
  159. } else {
  160. wx.navigateTo({ url: `/pages/goods_details/index?id=${item.id}` });
  161. }
  162. },
  163. // /*
  164. // * 跳转门店列表
  165. // */
  166. // showStoreList: function () {
  167. // wx.navigateTo({
  168. // url: '/pages/goods_details_store/index?go=details'
  169. // })
  170. // },
  171. // /**
  172. // * 获取门店列表数据
  173. // */
  174. // getList: function () {
  175. // let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  176. // let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  177. // let data = {
  178. // latitude: latitude, //纬度
  179. // longitude: longitude, //经度
  180. // page: 1,
  181. // limit: 10
  182. // }
  183. // storeListApi(data).then(res => {
  184. // let list = res.data.list || [];
  185. // this.setData({
  186. // storeList: list,
  187. // storeItems: list[0]
  188. // });
  189. // }).catch(err => {
  190. // })
  191. // },
  192. /*
  193. * 获取用户信息
  194. */
  195. getUserInfo: function () {
  196. var that = this;
  197. getUserInfo().then(res => {
  198. let isState = true;
  199. if ((res.data.is_promoter || res.data.statu == 2) && this.data.sharePacket.priceName != 0) {
  200. isState = false;
  201. }
  202. that.setData({
  203. 'sharePacket.isState': isState,
  204. uid: res.data.uid
  205. });
  206. });
  207. },
  208. /**
  209. * 购物车手动填写
  210. *
  211. */
  212. iptCartNum: function (e) {
  213. this.setData({
  214. ['productSelect.cart_num']: e.detail,
  215. cart_num: e.detail
  216. });
  217. },
  218. /**
  219. * 购物车数量加和数量减
  220. *
  221. */
  222. ChangeCartNum:function(e){
  223. //是否 加|减
  224. var changeValue = e.detail;
  225. //获取当前变动属性
  226. var productSelect = this.data.productValue[this.data.attrValue];
  227. //如果没有属性,赋值给商品默认库存
  228. if (productSelect === undefined && !this.data.productAttr.length) productSelect = this.data.productSelect;
  229. //不存在不加数量
  230. if (productSelect===undefined) return;
  231. //提取库存
  232. var stock = productSelect.stock || 0;
  233. //设置默认数据
  234. if (productSelect.cart_num == undefined) productSelect.cart_num = 1;
  235. //数量+
  236. if (changeValue){
  237. productSelect.cart_num++;
  238. //大于库存时,等于库存
  239. if (productSelect.cart_num > stock) productSelect.cart_num = stock;
  240. this.setData({
  241. ['productSelect.cart_num']: productSelect.cart_num,
  242. cart_num: productSelect.cart_num
  243. });
  244. }else{
  245. //数量减
  246. productSelect.cart_num--;
  247. //小于1时,等于1
  248. if (productSelect.cart_num < 1) productSelect.cart_num=1;
  249. this.setData({
  250. ['productSelect.cart_num']: productSelect.cart_num,
  251. cart_num: productSelect.cart_num
  252. });
  253. }
  254. },
  255. /**
  256. * 属性变动赋值
  257. *
  258. */
  259. ChangeAttr: function (e) {
  260. var values = e.detail;
  261. var productSelect = this.data.productValue[values];
  262. var storeInfo = this.data.storeInfo;
  263. if (productSelect) {
  264. this.setData({
  265. ["productSelect.image"]: productSelect.image,
  266. ["productSelect.price"]: productSelect.now_price,
  267. ["productSelect.stock"]: productSelect.stock,
  268. ['productSelect.unique']: productSelect.unique,
  269. ['productSelect.cart_num']: 1,
  270. attrValue: values,
  271. attr: '已选择'
  272. });
  273. } else {
  274. this.setData({
  275. ["productSelect.image"]: storeInfo.image,
  276. ["productSelect.price"]: storeInfo.now_price,
  277. ["productSelect.stock"]: 0,
  278. ['productSelect.unique']: '',
  279. ['productSelect.cart_num']: 0,
  280. attrValue: '',
  281. attr: '请选择'
  282. });
  283. }
  284. },
  285. /**
  286. * 领取完毕移除当前页面领取过的优惠券展示
  287. */
  288. ChangCoupons: function (e) {
  289. var coupon = e.detail;
  290. var couponList = util.ArrayRemove(this.data.couponList, 'id', coupon.id);
  291. this.setData({ couponList: couponList });
  292. },
  293. /**
  294. * 生命周期函数--监听页面加载
  295. */
  296. onLoad: function (options) {
  297. var that = this;
  298. this.setData({
  299. navH: app.globalData.navHeight
  300. });
  301. //设置商品列表高度
  302. wx.getSystemInfo({
  303. success: function (res) {
  304. that.setData({
  305. height: res.windowHeight
  306. //res.windowHeight:获取整个窗口高度为px,*2为rpx;98为头部占据的高度;
  307. })
  308. },
  309. });
  310. //扫码携带参数处理
  311. if (options.scene) {
  312. var value = util.getUrlParams(decodeURIComponent(options.scene));
  313. if (value.id) options.id = value.id;
  314. //记录推广人uid
  315. if (value.pid) app.globalData.spid = value.pid;
  316. }
  317. if (!options.id) return app.Tips({ title: '缺少参数无法查看商品' }, { tab: 3, url: 1 });
  318. this.setData({ id: options.id });
  319. //记录推广人uid
  320. if (options.spid) app.globalData.spid = options.spid;
  321. this.getGoodsDetails();
  322. // this.getList();
  323. },
  324. //
  325. // infoScroll: function () {
  326. // var that = this, topArr = [], heightArr = [];
  327. // for (var i = 0; i < that.data.navList.length; i++) { //productList
  328. // //获取元素所在位置
  329. // var query = wx.createSelectorQuery().in(this);
  330. // var idView = "#past" + i;
  331. // if (!that.data.good_list.length && i == 2) {
  332. // var idView = "#past" + 3;
  333. // }
  334. // query.select(idView).boundingClientRect();
  335. // query.exec(function (res) {
  336. // var top = res[0].top;
  337. // var height = res[0].height;
  338. // topArr.push(top);
  339. // heightArr.push(height);
  340. // that.setData({
  341. // topArr: topArr,
  342. // heightArr: heightArr
  343. // });
  344. // });
  345. // };
  346. // },
  347. /**
  348. * 获取产品详情
  349. *
  350. */
  351. getGoodsDetails: function () {
  352. var that = this;
  353. getProductDetail(that.data.id).then(res => {
  354. var storeInfo = res.data.storeInfo;
  355. var good_list = res.data.good_list || [];
  356. var count = Math.ceil(good_list.length / 6);
  357. var goodArray = new Array();
  358. for (var i = 0; i < count; i++) {
  359. var list = good_list.slice(i * 6, i * 6 + 6);
  360. if (list.length) goodArray.push({ list: list });
  361. }
  362. that.setData({
  363. storeInfo: storeInfo,
  364. reply: res.data.reply ? [res.data.reply] : [],
  365. replyCount: res.data.replyCount,
  366. description: storeInfo.description,
  367. replyChance: res.data.replyChance,
  368. productAttr: res.data.productAttr,
  369. productValue: res.data.productValue,
  370. ["sharePacket.priceName"]: res.data.priceName,
  371. // ['parameter.title']: storeInfo.store_name,
  372. systemStore: res.data.system_store,
  373. storeSelfMention: res.data.store_self_mention,
  374. good_list: goodArray,
  375. activity:res.data.activity ? res.data.activity : []
  376. });
  377. var navList = ['商品', '评价', '详情'];
  378. if (goodArray.length) {
  379. navList.splice(2, 0, '推荐')
  380. }
  381. that.setData({
  382. navList: navList
  383. });
  384. if (app.globalData.isLog) {
  385. that.getUserInfo();
  386. }
  387. that.downloadFilestoreImage();
  388. that.DefaultSelect();
  389. setTimeout(function () {
  390. // that.setClientHeight();
  391. }, 500);
  392. setTimeout(function () {
  393. // that.infoScroll();
  394. }, 500);
  395. //html转wxml
  396. WxParse.wxParse('description', 'html', that.data.description, that, 0);
  397. }).catch(err => {
  398. //状态异常返回上级页面
  399. return app.Tips({ title: err.toString() }, { tab: 3, url: 1 });
  400. })
  401. },
  402. goPages: function (e) {
  403. wx.navigateTo({ url: 'pages/goods_details/index?id=' + e.currentTarget.dataset.id });
  404. },
  405. /**
  406. * 拨打电话
  407. */
  408. makePhone: function () {
  409. wx.makePhoneCall({
  410. phoneNumber: this.data.systemStore.phone
  411. })
  412. },
  413. /**
  414. * 打开地图
  415. *
  416. */
  417. // showMaoLocation: function () {
  418. // if (!this.data.systemStore.latitude || !this.data.systemStore.longitude) return app.Tips({ title: '缺少经纬度信息无法查看地图!' });
  419. // wx.openLocation({
  420. // latitude: parseFloat(this.data.systemStore.latitude),
  421. // longitude: parseFloat(this.data.systemStore.longitude),
  422. // scale: 8,
  423. // name: this.data.systemStore.name,
  424. // address: this.data.systemStore.address + this.data.systemStore.detailed_address,
  425. // success: function () {
  426. // },
  427. // });
  428. // },
  429. /**
  430. * 默认选中属性
  431. *
  432. */
  433. DefaultSelect: function () {
  434. var productAttr = this.data.productAttr, storeInfo = this.data.storeInfo , productValue = this.data.productValue,
  435. value = [];
  436. for (var key in productValue) {
  437. if (productValue[key].stock > 0) {
  438. value = this.data.productAttr.length ? key.split(",") : [];
  439. break;
  440. }
  441. }
  442. for (var i = 0, len = productAttr.length; i < len; i++) {
  443. if (productAttr[i].attr_value[0]) productAttr[i].checked = value[i];
  444. };
  445. var productSelect = this.data.productValue[value.sort().join(',')];
  446. if (productSelect) {
  447. this.setData({
  448. ["productSelect.store_name"]: storeInfo.store_name,
  449. ["productSelect.image"]: productSelect.image,
  450. ["productSelect.price"]: productSelect.price,
  451. ["productSelect.stock"]: productSelect.stock,
  452. ['productSelect.unique']: productSelect.unique,
  453. ['productSelect.cart_num']: 1,
  454. attrValue: value,
  455. attr: '已选择'
  456. });
  457. } else {
  458. this.setData({
  459. ["productSelect.store_name"]: storeInfo.store_name,
  460. ["productSelect.image"]: storeInfo.image,
  461. ["productSelect.price"]: storeInfo.price,
  462. ["productSelect.stock"]: this.data.productAttr.length ? 0 : storeInfo.stock,
  463. ['productSelect.unique']: '',
  464. ['productSelect.cart_num']: this.data.productAttr.length ? 0 : 1,
  465. attrValue: '',
  466. attr: '请选择'
  467. });
  468. }
  469. this.setData({ productAttr: productAttr });
  470. },
  471. // /**
  472. // * 获取是否收藏
  473. // */
  474. // get_product_collect: function () {
  475. // var that = this;
  476. // getProductDetail(that.data.id).then(res => {
  477. // that.setData({ 'storeInfo.userCollect': res.data.storeInfo.userCollect });
  478. // });
  479. // },
  480. /**
  481. * 获取优惠券
  482. *
  483. */
  484. // getCouponList() {
  485. // var that = this;
  486. // getCoupons({ page: 1, limit: 10, type: 1, product_id: that.data.id}).then(res => {
  487. // var couponList = [];
  488. // for (var i = 0; i < res.data.length; i++) {
  489. // if (!res.data[i].is_use && couponList.length < 2) couponList.push(res.data[i]);
  490. // }
  491. // that.setData({
  492. // ['coupon.list']: res.data,
  493. // couponList: couponList
  494. // });
  495. // });
  496. // },
  497. /**
  498. *
  499. *
  500. * 收藏商品
  501. */
  502. // setCollect: function () {
  503. // if (app.globalData.isLog === false) {
  504. // this.setData({
  505. // isAuto: true,
  506. // iShidden: false,
  507. // });
  508. // } else {
  509. // var that = this;
  510. // if (this.data.storeInfo.userCollect) {
  511. // collectDel(this.data.storeInfo.id).then(res => {
  512. // that.setData({
  513. // ['storeInfo.userCollect']: !that.data.storeInfo.userCollect
  514. // })
  515. // })
  516. // } else {
  517. // collectAdd(this.data.storeInfo.id).then(res => {
  518. // that.setData({
  519. // ['storeInfo.userCollect']: !that.data.storeInfo.userCollect
  520. // })
  521. // })
  522. // }
  523. // }
  524. // },
  525. /**
  526. * 打开属性插件
  527. */
  528. selecAttr: function () {
  529. if (app.globalData.isLog === false)
  530. this.setData({ isAuto: true, iShidden: false })
  531. else
  532. this.setData({ 'attribute.cartAttr': true, isOpen: true })
  533. },
  534. /**
  535. * 打开优惠券插件
  536. */
  537. // coupon: function () {
  538. // if (app.globalData.isLog === false)
  539. // this.setData({ isAuto: true, iShidden: false })
  540. // else {
  541. // this.getCouponList();
  542. // this.setData({ 'coupon.coupon': true })
  543. // }
  544. // },
  545. onMyEvent: function (e) {
  546. this.setData({ 'attribute.cartAttr': e.detail.window, isOpen: false });
  547. },
  548. /**
  549. * 打开属性加入购物车
  550. *
  551. */
  552. joinCart: function (e) {
  553. //是否登录
  554. if (app.globalData.isLog === false)
  555. this.setData({ isAuto: true, iShidden: false, });
  556. else {
  557. this.goCat();
  558. }
  559. },
  560. /*
  561. * 加入购物车
  562. */
  563. goCat: function (isPay) {
  564. var that = this;
  565. var productSelect = this.data.productValue[this.data.attrValue];
  566. //打开属性
  567. if (this.data.attrValue) {
  568. //默认选中了属性,但是没有打开过属性弹窗还是自动打开让用户查看默认选中的属性
  569. this.setData({ 'attribute.cartAttr': !this.data.isOpen ? true : false })
  570. } else {
  571. if (this.data.isOpen)
  572. this.setData({ 'attribute.cartAttr': true })
  573. else
  574. this.setData({ 'attribute.cartAttr': !this.data.attribute.cartAttr });
  575. }
  576. //只有关闭属性弹窗时进行加入购物车
  577. if (this.data.attribute.cartAttr === true && this.data.isOpen == false) return this.setData({ isOpen: true });
  578. //如果有属性,没有选择,提示用户选择
  579. if (this.data.productAttr.length && productSelect === undefined && this.data.isOpen == true) return app.Tips({ title: '请选择属性' });
  580. if (!that.data.cart_num || parseInt(that.data.cart_num) <= 0) return app.Tips({ title: '请输入购买数量' });
  581. postCartAdd({
  582. productId: that.data.id,
  583. cartNum: that.data.cart_num,
  584. uniqueId: productSelect !== undefined ? productSelect.unique : '',
  585. 'new': isPay === undefined ? 0 : 1,
  586. }).then(res => {
  587. that.setData({ isOpen: false, 'attribute.cartAttr': false });
  588. if (isPay)
  589. wx.navigateTo({ url: '/pages/order_confirm/index?cartId=' + res.data.cartId });
  590. else
  591. app.Tips({ title: '添加购物车成功', icon: 'success' }, function () {
  592. that.getCartCount(true);
  593. });
  594. }).catch(err => {
  595. return app.Tips({ title: err });
  596. });
  597. },
  598. /**
  599. * 获取购物车数量
  600. * @param boolean 是否展示购物车动画和重置属性
  601. */
  602. getCartCount: function (isAnima) {
  603. var that = this;
  604. getCartCounts().then(res => {
  605. that.setData({ CartCount: res.data.count });
  606. //加入购物车后重置属性
  607. if (isAnima) {
  608. that.setData({
  609. animated: true,
  610. attrValue: '',
  611. attr: '请选择',
  612. ["productSelect.image"]: that.data.storeInfo.image,
  613. ["productSelect.price"]: that.data.storeInfo.price,
  614. ["productSelect.stock"]: that.data.storeInfo.stock,
  615. ['productSelect.unique']: '',
  616. ['productSelect.cart_num']: 1,
  617. });
  618. that.selectComponent('#product-window').ResetAttr();
  619. setTimeout(function () {
  620. that.setData({
  621. animated: false
  622. });
  623. }, 500);
  624. }
  625. });
  626. },
  627. /**
  628. * 立即购买
  629. */
  630. goBuy: function (e) {
  631. if (app.globalData.isLog === false)
  632. this.setData({ isAuto: true, iShidden: false });
  633. else
  634. this.goCat(true);
  635. },
  636. /**
  637. * 分享打开和关闭
  638. *
  639. */
  640. listenerActionSheet: function () {
  641. if (app.globalData.isLog === false)
  642. this.setData({ isAuto: true, iShidden: false });
  643. else
  644. this.setData({ actionSheetHidden: !this.data.actionSheetHidden })
  645. },
  646. //隐藏海报
  647. posterImageClose: function () {
  648. this.setData({ posterImageStatus: false, })
  649. },
  650. //替换安全域名
  651. setDomain: function (url) {
  652. url = url ? url.toString() : '';
  653. //本地调试打开,生产请注销
  654. // return url;
  655. if (url.indexOf("https://") > -1) return url;
  656. else return url.replace('http://', 'https://');
  657. },
  658. //获取海报产品图
  659. downloadFilestoreImage: function () {
  660. var that = this;
  661. wx.downloadFile({
  662. url: that.setDomain(that.data.storeInfo.image),
  663. success: function (res) {
  664. that.setData({
  665. storeImage: res.tempFilePath
  666. })
  667. },
  668. fail: function () {
  669. return app.Tips({ title: '' });
  670. that.setData({
  671. storeImage: '',
  672. })
  673. },
  674. });
  675. },
  676. /**
  677. * 获取产品分销二维码
  678. * @param function successFn 下载完成回调
  679. *
  680. */
  681. downloadFilePromotionCode: function (successFn) {
  682. var that = this;
  683. getProductCode(this.data.id).then(res => {
  684. wx.downloadFile({
  685. url: that.setDomain(res.data.code),
  686. success: function (res) {
  687. that.setData({ isDown: false });
  688. if (typeof successFn == 'function')
  689. successFn && successFn(res.tempFilePath);
  690. else
  691. that.setData({ PromotionCode: res.tempFilePath });
  692. },
  693. fail: function () {
  694. that.setData({ isDown: false });
  695. that.setData({ PromotionCode: '' });
  696. },
  697. });
  698. }).catch(err => {
  699. that.setData({ isDown: false });
  700. that.setData({ PromotionCode: '' });
  701. });
  702. },
  703. /**
  704. * 生成海报
  705. */
  706. goPoster: function () {
  707. var that = this;
  708. that.setData({ canvasStatus: true });
  709. var arr2 = [that.data.posterbackgd, that.data.storeImage, that.data.PromotionCode];
  710. if (that.data.isDown) return app.Tips({ title: '正在下载海报,请稍后再试!' });
  711. wx.getImageInfo({
  712. src: that.data.PromotionCode,
  713. fail: function (res) {
  714. return app.Tips({ 'title': '小程序二维码需要发布正式版后才能获取到' });
  715. },
  716. success() {
  717. if (arr2[2] == '') {
  718. //海报二维码不存在则从新下载
  719. that.downloadFilePromotionCode(function (msgPromotionCode) {
  720. arr2[2] = msgPromotionCode;
  721. if (arr2[2] == '') return app.Tips({ title: '海报二维码生成失败!' });
  722. util.PosterCanvas(arr2, that.data.storeInfo.store_name, that.data.storeInfo.price, function (tempFilePath) {
  723. that.setData({
  724. posterImage: tempFilePath,
  725. posterImageStatus: true,
  726. canvasStatus: false,
  727. actionSheetHidden: !that.data.actionSheetHidden
  728. })
  729. });
  730. });
  731. } else {
  732. //生成推广海报
  733. util.PosterCanvas(arr2, that.data.storeInfo.store_name, that.data.storeInfo.price, function (tempFilePath) {
  734. that.setData({
  735. posterImage: tempFilePath,
  736. posterImageStatus: true,
  737. canvasStatus: false,
  738. actionSheetHidden: !that.data.actionSheetHidden
  739. })
  740. });
  741. }
  742. },
  743. });
  744. },
  745. /*
  746. * 保存到手机相册
  747. */
  748. savePosterPath: function () {
  749. var that = this;
  750. wx.getSetting({
  751. success(res) {
  752. if (!res.authSetting['scope.writePhotosAlbum']) {
  753. wx.authorize({
  754. scope: 'scope.writePhotosAlbum',
  755. success() {
  756. wx.saveImageToPhotosAlbum({
  757. filePath: that.data.posterImage,
  758. success: function (res) {
  759. that.posterImageClose();
  760. app.Tips({ title: '保存成功', icon: 'success' });
  761. },
  762. fail: function (res) {
  763. app.Tips({ title: '保存失败' });
  764. }
  765. })
  766. }
  767. })
  768. } else {
  769. wx.saveImageToPhotosAlbum({
  770. filePath: that.data.posterImage,
  771. success: function (res) {
  772. that.posterImageClose();
  773. app.Tips({ title: '保存成功', icon: 'success' });
  774. },
  775. fail: function (res) {
  776. app.Tips({ title: '保存失败' });
  777. },
  778. })
  779. }
  780. }
  781. })
  782. },
  783. /**
  784. * 用户点击右上角分享
  785. */
  786. onShareAppMessage: function () {
  787. var that = this;
  788. that.setData({ actionSheetHidden: !that.data.actionSheetHidden });
  789. userShare();
  790. return {
  791. title: that.data.storeInfo.store_name || '',
  792. imageUrl: that.data.storeInfo.image || '',
  793. path: '/pages/goods_details/index?id=' + that.data.id + '&spid=' + that.data.uid,
  794. }
  795. }
  796. })