memberCenter.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // pages/memberCenter/memberCenter.js
  2. const api = require('../../api/index')
  3. const pay = require('../../utils/pay')
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. localImagePath:app.globalData.localImagePath,
  11. imgHttp:app.globalData.imghttp,
  12. userinfo:{},
  13. equity:[
  14. {
  15. icon:'/static/svg/down.png',
  16. label:'权益一'
  17. },
  18. {
  19. icon:'/static/svg/会员权益 (1).png',
  20. label:'权益二'
  21. },
  22. {
  23. icon:'/static/svg/会员权益.png',
  24. label:'权益三'
  25. },
  26. {
  27. icon:'/static/svg/会员级别处理.png',
  28. label:'权益四'
  29. },
  30. ],
  31. grades:[
  32. {
  33. background_icon:'/static/svg/B级会员背景图标.svg',
  34. background_color:'#3f395c',
  35. grade:'B级会员',
  36. money:'365'
  37. },
  38. {
  39. background_icon:'/static/svg/A级会员背景图标.svg',
  40. background_color:'#ff0101',
  41. grade:'A级会员',
  42. money:'520'
  43. },
  44. {
  45. background_icon:'/static/svg/S级会员背景图标.svg',
  46. background_color:'#000000',
  47. grade:'S级会员',
  48. money:'888'
  49. },
  50. ],
  51. choseVip:null,
  52. tableData:[],//会员权益
  53. tableHead:[]
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad(options) {
  59. this.getUserinfo()
  60. // var thead= [
  61. // { key: 'orderNum', name: '订单编号' },
  62. // { key: 'machNum', name: '机器编号' },
  63. // { key: 'planeNum', name: '计划生产数量' },
  64. // { key: 'planeEndTime', name: '计划结束时间' },
  65. // { key: 'productName', name: '产品名称' }
  66. // ]
  67. // var data= [
  68. // { orderNum: '01234dsnfbujhcdsvfkudshcvjbsdkcbsdjkchbsdjkhb', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  69. // { orderNum: '31234', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  70. // { orderNum: '13455', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  71. // { orderNum: '47867', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  72. // { orderNum: '34565', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  73. // { orderNum: '76809', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  74. // { orderNum: '01034', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' }
  75. // ]
  76. // this.setData(
  77. // {
  78. // tableHead:thead,
  79. // tableData:data
  80. // }
  81. // )
  82. this.queryAllVip()
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady() {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow() {
  93. },
  94. /**
  95. * 页面功能
  96. */
  97. //获取所有会员
  98. queryAllVip(){
  99. var that = this
  100. api.queryAllVip().then(res=>{
  101. if(res.code == 200){
  102. console.log(res)
  103. var data = res.data.data
  104. var grades = []
  105. var tableHead = [
  106. {
  107. key:"functionName",
  108. name:''
  109. }
  110. ]
  111. data.forEach(item => {
  112. var config = JSON.parse(item.configParameter)
  113. var obj = {
  114. background_icon:config.background_icon,
  115. background_color:config.background_color,
  116. grade:item.name,
  117. money:item.price,
  118. vipUuid:item.vipUuid
  119. }
  120. tableHead.push(
  121. {
  122. key:item.vipUuid,
  123. name:item.name
  124. }
  125. )
  126. grades.push(obj)
  127. })
  128. that.setData(
  129. {
  130. grades:grades,
  131. tableHead:tableHead,
  132. choseVip:null
  133. }
  134. )
  135. that.getVipRights()
  136. console.log(that.data.grades)
  137. }
  138. })
  139. },
  140. //获取会员权益
  141. getVipRights(){
  142. var that = this
  143. api.getVipRights().then(res=>{
  144. if(res.code == 200){
  145. var data = res.data.data
  146. var tableData = []
  147. for(var i = 0;i<data.length;i++){
  148. var obj = {
  149. functionName:data[i].functionName
  150. }
  151. var right = data[i].vipRightsVOList
  152. for(var j = 0;j<that.data.tableHead.length;j++){
  153. var head = that.data.tableHead[j]
  154. if(head.key == 'functionName'){
  155. continue
  156. }
  157. var obj2 = right.find(item=>{
  158. return item.vipUuid == head.key
  159. })
  160. if(obj2){
  161. obj[head.key] = obj2.description
  162. }else{
  163. obj[head.key] = ''
  164. }
  165. }
  166. tableData.push(obj)
  167. }
  168. that.setData(
  169. {
  170. tableData:tableData
  171. }
  172. )
  173. console.log(that.data.tableHead,that.data.tableData)
  174. }
  175. })
  176. },
  177. //获取用户信息
  178. getUserinfo(){
  179. api.selectPerson().then(res=>{
  180. if(res.code == 200){
  181. this.setData(
  182. {
  183. userinfo:res.data
  184. }
  185. )
  186. }
  187. })
  188. },
  189. //选择开通会员类型
  190. chooseVip(e){
  191. var {item} = e.currentTarget.dataset
  192. this.setData(
  193. {
  194. choseVip:item
  195. }
  196. )
  197. },
  198. //开通会员
  199. openVip(){
  200. if(!this.data.choseVip){
  201. api.notify(
  202. {
  203. type:'warning',
  204. message:'请先选择需要开通会员的类型',
  205. top:wx.getStorageSync('height')
  206. }
  207. )
  208. return
  209. }
  210. var params = {
  211. goodType:1,
  212. goodUuid:this.data.choseVip.vipUuid
  213. }
  214. wx.showLoading({
  215. title: '加载中',
  216. })
  217. pay.payMoney(params).then(res=>{
  218. console.log(res)
  219. if(res.errMsg == 'requestPayment:ok'){
  220. api.notify(
  221. {
  222. type:'success',
  223. message:'开通会员成功',
  224. top:wx.getStorageSync('height')
  225. }
  226. )
  227. this.getUserinfo()
  228. var pages = getCurrentPages()
  229. var currentPage = pages[pages.length - 2]
  230. currentPage.getUserinfo()
  231. }
  232. }).catch(error=>{
  233. })
  234. },
  235. /**
  236. * 生命周期函数--监听页面隐藏
  237. */
  238. onHide() {
  239. },
  240. /**
  241. * 生命周期函数--监听页面卸载
  242. */
  243. onUnload() {
  244. },
  245. /**
  246. * 页面相关事件处理函数--监听用户下拉动作
  247. */
  248. onPullDownRefresh() {
  249. },
  250. /**
  251. * 页面上拉触底事件的处理函数
  252. */
  253. onReachBottom() {
  254. },
  255. /**
  256. * 用户点击右上角分享
  257. */
  258. onShareAppMessage() {
  259. }
  260. })