C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

252 rindas
6.2 KiB

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