index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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/user/wallet/get",
  82. header: {
  83. "Content-Type": "application/json"
  84. },
  85. method: "POST",
  86. data: { openId: opneId },
  87. success (res) {
  88. console.log(res)
  89. that.setData({
  90. wallet: res.data.data.wallet
  91. })
  92. }
  93. })
  94. console.log(nickName)
  95. if (nickName == ''){
  96. wx.request( {
  97. url: link + "/v1/user/open.id/get",
  98. header: {
  99. "Content-Type": "application/json"
  100. },
  101. method: "POST",
  102. data: { openId: opneId },
  103. success (res) {
  104. console.log(res)
  105. wx.setStorageSync('nickName', res.data.data.user.nickName)
  106. wx.setStorageSync('userId', res.data.data.user.id)
  107. that.setData({
  108. userId: res.data.data.user.id
  109. })
  110. }
  111. })
  112. } else{
  113. var userId = wx.getStorageSync('userId')
  114. console.log(userId)
  115. that.setData({
  116. userId: userId
  117. })
  118. }
  119. },
  120. clickGrid(e) {
  121. var that = this
  122. console.log(e)
  123. if (e.detail.cell.text == "我的订单"){
  124. wx.navigateTo({
  125. url:"/pages/order/order"
  126. })
  127. } else if (e.detail.cell.text == "联系客服"){
  128. wx.showModal({
  129. title: '客服微信',
  130. content: '客服微信:tao1024_com,点击复制按钮,直接复制客服微信号,粘贴到微信中搜索添加客服.',
  131. showCancel: true,//是否显示取消按钮
  132. cancelText:"取消",//默认是“取消”
  133. //cancelColor:'skyblue',//取消文字的颜色
  134. confirmText:"复制",//默认是“确定”
  135. //confirmColor: 'skyblue',//确定文字的颜色
  136. success: function (res) {
  137. if (res.cancel) {
  138. //点击取消,默认隐藏弹框
  139. } else {
  140. wx.setClipboardData({
  141. data: 'tao1024_com',
  142. success (res) {
  143. //点击确定
  144. wx.showToast({
  145. title: '复制成功',//提示文字
  146. duration:2000,//显示时长
  147. mask:true,//是否显示透明蒙层,防止触摸穿透,默认:false
  148. icon:'success', //图标,支持"success"、"loading"
  149. success:function(){ },//接口调用成功
  150. fail: function () { }, //接口调用失败的回调函数
  151. complete: function () { } //接口调用结束的回调函数
  152. })
  153. }
  154. })
  155. }
  156. },
  157. fail: function (res) { },//接口调用失败的回调函数
  158. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  159. })
  160. }
  161. else if (e.detail.cell.text == "提现") {
  162. wx.showToast({
  163. title: "结算金额:0元",
  164. icon: 'none'
  165. });
  166. } else if (e.detail.cell.text == "邀请好友"){
  167. console.log('邀请好友')
  168. wx.navigateTo({
  169. url:"/pages/friends/friends"
  170. })
  171. } else if (e.detail.cell.text == "好友列表"){
  172. wx.navigateTo({
  173. url:"/pages/friends-list/friends-list"
  174. })
  175. }
  176. else {
  177. wx.showToast({
  178. title: "功能开发中...",
  179. icon: 'none'
  180. });
  181. }
  182. },
  183. getUserProfile(e) {
  184. var that = this
  185. var openId = wx.getStorageSync('openId')
  186. var nickName = wx.getStorageSync('nickName')
  187. console.log("'"+nickName+"'")
  188. console.log(openId)
  189. if (nickName == ''){
  190. wx.getUserProfile({
  191. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  192. success: (res) => {
  193. console.log(res)
  194. //更新user
  195. wx.request( {
  196. url: link + "/v1/user/update/name",
  197. header: {
  198. "Content-Type": "application/json"
  199. },
  200. method: "POST",
  201. data: { openId: openId ,nickName:res.userInfo.nickName,avatarUrl:res.userInfo.avatarUrl},
  202. success (ress) {
  203. console.log(ress)
  204. wx.setStorageSync('nickName', res.userInfo.nickName)
  205. }
  206. })
  207. that.clickGrid(e)
  208. }
  209. })
  210. } else{
  211. that.clickGrid(e)
  212. }
  213. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  214. },
  215. getUserInfo(e) {
  216. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
  217. console.log(e)
  218. this.setData({
  219. userInfo: e.detail.userInfo,
  220. hasUserInfo: true
  221. })
  222. },
  223. /**
  224. * 用户点击右上角分享
  225. */
  226. // onShareAppMessage: function () {
  227. // var openId = wx.getStorageSync('openId')
  228. // return {
  229. // title: '优惠券小程序',
  230. // desc: '电商内部优惠券',
  231. // path: 'pages/boutique/outique?openId=' + openId // 路径,传递参数到指定页面。
  232. // }
  233. // }
  234. })