myhomepage.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. // pages/helpsell/helpsell.js
  2. const app = getApp();
  3. const api = require('../../api/api');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navbarData: {
  10. showCapsule: 1,
  11. capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
  12. },
  13. head_id: 0, //团长id
  14. height: 0, //状态栏高度
  15. user_info: {}, //团长个人信息
  16. classify: [], //商品分类
  17. info: {}, //详细信息
  18. pintuan: [], //拼团列表
  19. showphone: false, //显示打电话
  20. phone: [], //电话
  21. showfen: false, //显示分享
  22. fenxiang: [{
  23. name: '分享给朋友',
  24. openType: 'share'
  25. }, {
  26. name: '分享到朋友圈'
  27. }],
  28. enterType: 0, //进入类型(0:显示订阅按钮,不显示编辑按钮;1:不显示订阅按钮,显示编辑按钮)
  29. isSubscription: false, //是否已订阅团长
  30. /* 组件参数 */
  31. showPopup: false
  32. },
  33. _navback() {
  34. wx.navigateBack()
  35. },
  36. showfens() {
  37. this.setData({
  38. showfen: true
  39. })
  40. },
  41. showphones() {
  42. this.setData({
  43. showphone: true
  44. })
  45. },
  46. offzhe() {
  47. this.setData({
  48. showfen: false,
  49. showphone: false
  50. })
  51. },
  52. phoneok(e) {
  53. wx.makePhoneCall({
  54. phoneNumber: e.detail.name,
  55. })
  56. },
  57. gobianji() {
  58. wx.navigateTo({
  59. url: '/pages/userinfo/userinfo',
  60. })
  61. },
  62. fenok(e) {
  63. if (e.detail.name === '分享给朋友') {
  64. console.log('分享朋友');
  65. } else {
  66. wx.navigateTo({
  67. url: '/pages/sharetofirend/sharetofirend?type=0&id=' + this.data.head_id,
  68. })
  69. }
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options) {
  75. let that = this;
  76. that.setData({
  77. height: app.globalData.height,
  78. enterType: Number(options.type),
  79. head_id: Number(options.id)
  80. })
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. let that = this;
  92. // 获取团长详情
  93. wx.showLoading({
  94. title: '加载中',
  95. mask: true
  96. })
  97. wx.request({
  98. url: api.Head_info,
  99. header: {
  100. 'Authorization': wx.getStorageSync('token')
  101. },
  102. data: {
  103. id: that.data.head_id,
  104. },
  105. success(res) {
  106. console.log(res);
  107. if (res.data.code === 1) {
  108. that.setData({
  109. user_info: res.data.data.user_info,
  110. classify: res.data.data.classification_info,
  111. info: res.data.data.info,
  112. pintuan: res.data.data.gang_list,
  113. isSubscription: res.data.data.subscribe === 1 ? true : false,
  114. phone: [{
  115. name: res.data.data.user_info.phone
  116. }]
  117. })
  118. } else {
  119. wx.showToast({
  120. title: res.data.msg,
  121. mask: true,
  122. icon: 'none'
  123. })
  124. }
  125. },
  126. fail(err) {
  127. wx.showToast({
  128. title: '发起网络请求失败',
  129. icon: 'none',
  130. mask: true
  131. })
  132. },
  133. complete() {
  134. wx.hideLoading()
  135. }
  136. })
  137. },
  138. /**
  139. * 生命周期函数--监听页面隐藏
  140. */
  141. onHide: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面卸载
  145. */
  146. onUnload: function () {
  147. },
  148. /**
  149. * 页面相关事件处理函数--监听用户下拉动作
  150. */
  151. onPullDownRefresh: function () {
  152. },
  153. /**
  154. * 页面上拉触底事件的处理函数
  155. */
  156. onReachBottom: function () {
  157. },
  158. /**
  159. * 用户点击右上角分享
  160. */
  161. onShareAppMessage: function () {
  162. let head_id = this.data.user_info.id; //团长
  163. return {
  164. title: '团长分享',
  165. path: '/pages/myhomepage/myhomepage?type=0&id=' + head_id,
  166. imageUrl: this.data.user_info.headimg
  167. }
  168. },
  169. // 跳转团长微信二维码
  170. navToWXQrcode() {
  171. let headimg = this.data.user_info.headimg;
  172. let name = this.data.user_info.name;
  173. let wechat_code = this.data.user_info.wechat_code;
  174. wx.navigateTo({
  175. url: '/pages/wxqrcode/wxqrcode?headimg=' + headimg + '&name=' + name + '&wechat_code=' + wechat_code
  176. })
  177. },
  178. // 页面跳转
  179. navgo(e) {
  180. let url = e.currentTarget.dataset.url;
  181. wx.navigateTo({
  182. url: url
  183. })
  184. },
  185. // 订阅
  186. subscription() {
  187. let that = this;
  188. if (that.data.isSubscription) {
  189. that.setData({
  190. showPopup: true
  191. })
  192. } else {
  193. wx.showLoading({
  194. title: '加载中',
  195. mask: true
  196. })
  197. wx.request({
  198. url: api.subscribe,
  199. header: {
  200. 'Authorization': wx.getStorageSync('token')
  201. },
  202. method: 'POST',
  203. data: {
  204. id: that.data.head_id
  205. },
  206. success(res) {
  207. console.log(res);
  208. if (res.data.code === 1) {
  209. that.setData({
  210. isSubscription: true,
  211. showPopup: false
  212. })
  213. wx.showToast({
  214. title: res.data.msg,
  215. icon: 'success',
  216. mask: true
  217. })
  218. } else {
  219. wx.showToast({
  220. title: res.data.msg,
  221. mask: true,
  222. icon: 'none'
  223. })
  224. }
  225. },
  226. fail(err) {
  227. wx.showToast({
  228. title: '发起网络请求失败',
  229. icon: 'none',
  230. mask: true
  231. })
  232. },
  233. complete() {
  234. wx.hideLoading()
  235. }
  236. })
  237. }
  238. },
  239. // 关闭弹出层
  240. closePopup() {
  241. this.setData({
  242. showPopup: false
  243. })
  244. },
  245. // 确认弹出层
  246. confirmPopup() {
  247. let that = this;
  248. wx.showLoading({
  249. title: '加载中',
  250. mask: true
  251. })
  252. wx.request({
  253. url: api.unsubscribe,
  254. header: {
  255. 'Authorization': wx.getStorageSync('token')
  256. },
  257. method: 'POST',
  258. data: {
  259. id: that.data.head_id
  260. },
  261. success(res) {
  262. console.log(res);
  263. if (res.data.code === 1) {
  264. that.setData({
  265. isSubscription: false,
  266. showPopup: false
  267. })
  268. wx.showToast({
  269. title: res.data.msg,
  270. icon: 'success',
  271. mask: true
  272. })
  273. } else {
  274. wx.showToast({
  275. title: res.data.msg,
  276. mask: true,
  277. icon: 'none'
  278. })
  279. }
  280. },
  281. fail(err) {
  282. wx.showToast({
  283. title: '发起网络请求失败',
  284. icon: 'none',
  285. mask: true
  286. })
  287. },
  288. complete() {
  289. wx.hideLoading()
  290. }
  291. })
  292. },
  293. // 拼团跳转
  294. navToPinTuanDetail(e) {
  295. let id = e.currentTarget.dataset.id;
  296. wx.navigateTo({
  297. url: '/pages/pintuandetail/pintuandetail?type=dingyue&id=' + id,
  298. })
  299. },
  300. })