index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const link = app.globalData.url
  5. Page({
  6. data: {
  7. grids1: [{
  8. image: 'order',
  9. text: '我的订单'
  10. }, {
  11. image: 'user',
  12. text: '好友列表'
  13. }, {
  14. image: 'help',
  15. text: '帮助中心'
  16. }, {
  17. image: 'add',
  18. text: '邀请好友'
  19. }, {
  20. image: 'to-top',
  21. text: '手动同步订单'
  22. }, {
  23. image: 'customer-service',
  24. text: '联系客服'
  25. }, {
  26. image: 'setting',
  27. text: '设置'
  28. },
  29. {
  30. image: 'success',
  31. text: '提现'
  32. },
  33. //{
  34. // image: 'eye',
  35. // text: '我的足迹'
  36. // }, {
  37. // image: 'scan',
  38. // text: '扫一扫'
  39. // },
  40. ],
  41. // grids2: [{
  42. // image: 'cart',
  43. // text: '我的购物车'
  44. // }, {
  45. // image: 'help',
  46. // text: '帮助中心'
  47. // }, {
  48. // image: 'address',
  49. // text: '地址管理'
  50. // }, {
  51. // image: 'order',
  52. // text: '我的订单'
  53. // }, {
  54. // image: 'customer-service',
  55. // text: '联系客服'
  56. // }, ],
  57. motto: 'Hello World',
  58. userInfo: {},
  59. hasUserInfo: false,
  60. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  61. canIUseGetUserProfile: false,
  62. canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  63. },
  64. // 事件处理函数
  65. bindViewTap() {
  66. wx.navigateTo({
  67. url: '../logs/logs'
  68. })
  69. },
  70. onLoad() {
  71. var that = this
  72. var opneId = wx.getStorageSync('openId')
  73. var nickName = wx.getStorageSync('nickName')
  74. if (wx.getUserProfile) {
  75. this.setData({
  76. canIUseGetUserProfile: true
  77. })
  78. }
  79. //获取金额
  80. wx.request( {
  81. url: link + "/v1/forward/lhf",
  82. header: {
  83. "Content-Type": "application/json",
  84. "function":"/v1/user/wallet/get"
  85. },
  86. method: "POST",
  87. data: { openId: opneId },
  88. success (res) {
  89. console.log(res)
  90. that.setData({
  91. wallet: res.data.data.wallet
  92. })
  93. }
  94. })
  95. console.log(nickName)
  96. if (nickName == ''){
  97. wx.request( {
  98. url: link + "/v1/forward/lhf",
  99. header: {
  100. "Content-Type": "application/json",
  101. "function":"/v1/user/open.id/get"
  102. },
  103. method: "POST",
  104. data: { openId: opneId },
  105. success (res) {
  106. console.log(res)
  107. wx.setStorageSync('nickName', res.data.data.user.nickName)
  108. wx.setStorageSync('userId', res.data.data.user.id)
  109. that.setData({
  110. userId: res.data.data.user.id
  111. })
  112. }
  113. })
  114. } else{
  115. var userId = wx.getStorageSync('userId')
  116. console.log(userId)
  117. that.setData({
  118. userId: userId
  119. })
  120. }
  121. },
  122. clickGrid(e) {
  123. var that = this
  124. console.log(e)
  125. if (e.detail.cell.text == "我的订单"){
  126. wx.navigateTo({
  127. url:"/pages/order/order"
  128. })
  129. } else if (e.detail.cell.text == "联系客服"){
  130. wx.showModal({
  131. title: '客服微信',
  132. content: '客服微信:tao1024_com,点击复制按钮,直接复制客服微信号,粘贴到微信中搜索添加客服.',
  133. showCancel: true,//是否显示取消按钮
  134. cancelText:"取消",//默认是“取消”
  135. //cancelColor:'skyblue',//取消文字的颜色
  136. confirmText:"复制",//默认是“确定”
  137. //confirmColor: 'skyblue',//确定文字的颜色
  138. success: function (res) {
  139. if (res.cancel) {
  140. //点击取消,默认隐藏弹框
  141. } else {
  142. wx.setClipboardData({
  143. data: 'tao1024_com',
  144. success (res) {
  145. //点击确定
  146. wx.showToast({
  147. title: '复制成功',//提示文字
  148. duration:2000,//显示时长
  149. mask:true,//是否显示透明蒙层,防止触摸穿透,默认:false
  150. icon:'success', //图标,支持"success"、"loading"
  151. success:function(){ },//接口调用成功
  152. fail: function () { }, //接口调用失败的回调函数
  153. complete: function () { } //接口调用结束的回调函数
  154. })
  155. }
  156. })
  157. }
  158. },
  159. fail: function (res) { },//接口调用失败的回调函数
  160. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  161. })
  162. }
  163. else if (e.detail.cell.text == "提现") {
  164. wx.showToast({
  165. title: "结算金额:0元",
  166. icon: 'none'
  167. });
  168. } else if (e.detail.cell.text == "邀请好友"){
  169. console.log('邀请好友')
  170. wx.navigateTo({
  171. url:"/pages/friends/friends"
  172. })
  173. } else if (e.detail.cell.text == "好友列表"){
  174. wx.navigateTo({
  175. url:"/pages/friends-list/friends-list"
  176. })
  177. }
  178. else {
  179. wx.showToast({
  180. title: "功能开发中...",
  181. icon: 'none'
  182. });
  183. }
  184. },
  185. getUserProfile(e) {
  186. var that = this
  187. var openId = wx.getStorageSync('openId')
  188. var nickName = wx.getStorageSync('nickName')
  189. console.log("'"+nickName+"'")
  190. console.log(openId)
  191. if (nickName == ''){
  192. wx.getUserProfile({
  193. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  194. success: (res) => {
  195. console.log(res)
  196. //更新user
  197. wx.request( {
  198. url: link + "/v1/forward/lhf",
  199. header: {
  200. "Content-Type": "application/json",
  201. "function":"/v1/user/update/name"
  202. },
  203. method: "POST",
  204. data: { openId: openId ,nickName:res.userInfo.nickName,avatarUrl:res.userInfo.avatarUrl},
  205. success (ress) {
  206. console.log(ress)
  207. wx.setStorageSync('nickName', res.userInfo.nickName)
  208. }
  209. })
  210. that.clickGrid(e)
  211. }
  212. })
  213. } else{
  214. that.clickGrid(e)
  215. }
  216. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  217. },
  218. getUserInfo(e) {
  219. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
  220. console.log(e)
  221. this.setData({
  222. userInfo: e.detail.userInfo,
  223. hasUserInfo: true
  224. })
  225. },
  226. /**
  227. * 用户点击右上角分享
  228. */
  229. // onShareAppMessage: function () {
  230. // var openId = wx.getStorageSync('openId')
  231. // return {
  232. // title: '优惠券小程序',
  233. // desc: '电商内部优惠券',
  234. // path: 'pages/boutique/outique?openId=' + openId // 路径,传递参数到指定页面。
  235. // }
  236. // }
  237. })