C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
4.9 KiB

  1. const Http = require("../../../../utils/HttpBasics");
  2. const imgurl = require("../../../../utils/imgurl");
  3. const config = require("../../../../config/config");
  4. const util = require("../../../../utils/util");
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. poterbg: imgurl.poterbg.url,
  12. teljpgUrl: imgurl.teljpg.url,
  13. share01: imgurl.share01.url,
  14. actUrl: imgurl.act.url,
  15. wmhome: imgurl.wmhome.url,
  16. page: 1,
  17. imglist: null,
  18. shopVoList: [],
  19. couponList: [], //活动劵列表
  20. qrCodeL: '', //小程序码
  21. currentTab: 0,
  22. isshare: false,
  23. showpost: false,
  24. imgHeight: 0,
  25. id: null,
  26. windowWidth: wx.getSystemInfoSync().windowWidth,
  27. windowHeight: wx.getSystemInfoSync().screenHeight,
  28. totalHeight: 0,
  29. canvasScale: 1.0, // 画布放大的倍数,因为如果保存的是一倍的分享图片的话,分享图会有点虚。所以保存的时候,canvasScale设置为2.0,wxss 里面的left: 500%;打开注释。就可保存两倍的分享图
  30. },
  31. //关闭海报
  32. closePoste: function() {
  33. this.setData({
  34. showpost: false
  35. })
  36. },
  37. goback: function () {
  38. wx.switchTab({
  39. url: '/pages/main/index',
  40. })
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function(options) {
  46. let that = this;
  47. if (options && options.id) {
  48. this.setData({
  49. id: options.id
  50. });
  51. that.getList(options.id);
  52. that.getCouponList(options.id);
  53. this.setData({
  54. currentTab: 0
  55. })
  56. }
  57. },
  58. /**
  59. * 拨打电话
  60. */
  61. phone: function(e) {
  62. let that = this;
  63. wx.makePhoneCall({
  64. phoneNumber: e.target.dataset.merchantlinkphone
  65. });
  66. },
  67. /**
  68. * 显示分享弹框
  69. */
  70. showshare: function() {
  71. this.setData({
  72. isshare: true,
  73. })
  74. },
  75. /**
  76. * 隐藏分享弹框
  77. */
  78. hidemodal: function() {
  79. this.setData({
  80. isshare: false,
  81. })
  82. },
  83. //滑动切换
  84. swiperTabView: function(e) {
  85. this.setData({
  86. currentTab: e.detail.current
  87. });
  88. },
  89. /**
  90. * 显示分享海报
  91. */
  92. showPoster: function() {
  93. //跳转到海报生成页
  94. wx.navigateTo({
  95. url: `/pages/canvas/index?merchantId=${this.data.id}`
  96. })
  97. },
  98. //点击切换
  99. clickTab: function(e) {
  100. if (this.data.currentTab === e.target.dataset.current) {
  101. return false;
  102. } else {
  103. this.setData({
  104. currentTab: e.target.dataset.current
  105. })
  106. }
  107. },
  108. /**
  109. * 获取商户详情
  110. */
  111. getList: function(id) {
  112. let that = this;
  113. let data;
  114. data = {
  115. pageNum: that.data.page,
  116. pageSize: 15,
  117. id: id
  118. }
  119. Http.get({
  120. url: config.api.merchantList,
  121. data: data
  122. }).then(res => {
  123. let imgList = [];
  124. imgList.push(res.data.list[0].merchantImgUrl)
  125. that.setData({
  126. data: res.data.list[0],
  127. shopVoList: res.data.list[0].shopVoList,
  128. imglist: res.data.list[0].coverPicture == '[]' ? imgList : JSON.parse(res.data.list[0].coverPicture),
  129. })
  130. })
  131. .catch(err => {
  132. wx.showToast({
  133. title: err.errMsg,
  134. icon: 'none',
  135. duration: 2000,
  136. mask: false
  137. });
  138. })
  139. },
  140. /**
  141. * 获取商户活动信息 券类型(1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券,6.多商户券,8.砍价券,9.团购券,50.积分券,51.积分停车券 100.消费卡)
  142. * 投放频道:(1.列表, 2.限时抢购, 3. banner图 4. 游戏 5.卡频道 6.砍价频道 7.拼团频道 8专题)
  143. */
  144. getCouponList: function(id) {
  145. let that = this;
  146. let data;
  147. data = {
  148. status: 0,
  149. merchantId: id,
  150. pageNum: that.data.page,
  151. pageSize: 15,
  152. }
  153. Http.get({
  154. url: config.api.listByMerchant,
  155. data: data
  156. }).then(res => {
  157. that.setData({
  158. couponList: res.data.page.list,
  159. qrCode: res.data.qrCode,
  160. })
  161. })
  162. .catch(err => {
  163. wx.showToast({
  164. title: err.errMsg,
  165. icon: 'none',
  166. duration: 2000,
  167. mask: false
  168. });
  169. })
  170. },
  171. /**
  172. * 获取多商铺列表
  173. */
  174. shopList: function(e) {
  175. wx.navigateTo({
  176. url: `/pages/index/merchantList/index?id=${e.currentTarget.dataset.id}`
  177. })
  178. },
  179. onShareAppMessage: function(res) {
  180. let that = this;
  181. let shareObj = {
  182. title: that.data.data.merchantName,
  183. path: `/pages/index/index?id=${that.data.id}&frommd=md`,
  184. success: function(res) {
  185. if (res.errMsg == 'shareAppMessage:ok') {}
  186. },
  187. fail: function(error) {
  188. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  189. }
  190. };
  191. // 来自页面内的按钮的转发
  192. if (res.from === 'button') {
  193. console.log(res)
  194. var eData = res.target.dataset.id;
  195. console.log(eData)
  196. shareObj.path = `/pages/index/index?id=${eData}&frommd=md`;
  197. }
  198. // 返回shareObj
  199. return shareObj;
  200. }
  201. })