index.js 7.1 KB

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