C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.0 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. fenxiang: imgurl.fenxiang.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. })
  160. // if (res.data && res.data.qrCode){
  161. // that.setData({
  162. // qrCode: res.data.qrCode,
  163. // })
  164. // }
  165. })
  166. .catch(err => {
  167. wx.showToast({
  168. title: err.errMsg,
  169. icon: 'none',
  170. duration: 2000,
  171. mask: false
  172. });
  173. })
  174. },
  175. /**
  176. * 获取多商铺列表
  177. */
  178. shopList: function(e) {
  179. wx.navigateTo({
  180. url: `/pages/index/merchantList/index?id=${e.currentTarget.dataset.id}`
  181. })
  182. },
  183. onShareAppMessage: function(res) {
  184. let that = this;
  185. let shareObj = {
  186. title: that.data.data.merchantName,
  187. path: `/pages/index/index?id=${that.data.id}&frommd=md`,
  188. success: function(res) {
  189. if (res.errMsg == 'shareAppMessage:ok') {}
  190. },
  191. fail: function(error) {
  192. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  193. }
  194. };
  195. // 来自页面内的按钮的转发
  196. if (res.from === 'button') {
  197. console.log(res)
  198. var eData = res.target.dataset.id;
  199. console.log(eData)
  200. shareObj.path = `/pages/index/index?id=${eData}&frommd=md`;
  201. }
  202. // 返回shareObj
  203. return shareObj;
  204. }
  205. })