You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

member.js 5.6KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // pages/member/member.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userInfo: {
  9. avatarUrl: '',
  10. nickName: '',
  11. phone: '',
  12. memberNo: 1,
  13. integral: 0,
  14. level_name:'',
  15. level_cash:0,
  16. level_point:0,
  17. base_exchange:1
  18. },
  19. memberLe: ['一', '二', '三', '四', '五', '六','七','八','九','十'],
  20. type:1,
  21. couponList:[],
  22. showCoupon:true,
  23. integralType:1,//1核销积分 2赠送积分
  24. integralNums:0,
  25. writeOffAmount:0,//核销金额
  26. multipleList:[1,10,50,300,500],
  27. submiting:false
  28. },
  29. user_id:null,
  30. /**
  31. * 获取用户信息
  32. */
  33. getUserInfo() {
  34. var that = this;
  35. app.requestGet('admin/buy/userinfo', {
  36. user_id: this.user_id
  37. }, res => {
  38. if (res.code == 200) {
  39. var {
  40. headimgurl,
  41. nickname,
  42. user_phone,
  43. user_level,
  44. user_point_all,
  45. user_point_use,
  46. level_name,
  47. level_cash,
  48. level_point,
  49. base_exchange
  50. } = res.data;
  51. var userInfo = {
  52. avatarUrl: headimgurl,
  53. nickName: nickname,
  54. phone: that.handlePhone(user_phone),
  55. memberNo: user_level,
  56. integral: user_point_all - user_point_use,
  57. level_name,
  58. level_cash,
  59. level_point,
  60. base_exchange
  61. }
  62. this.setData({
  63. userInfo: userInfo
  64. })
  65. } else {
  66. wx.showToast({
  67. title: res.message,
  68. icon: 'none',
  69. duration: 2000
  70. })
  71. }
  72. })
  73. },
  74. /**
  75. * 手机号隐藏处理
  76. */
  77. handlePhone(phone) {
  78. var str = phone + '';
  79. return str.slice(0, 3) + '****' + str.slice(-4)
  80. },
  81. /**
  82. * 切换券类型
  83. */
  84. changeType(e){
  85. var type = parseInt(e.currentTarget.dataset.type);
  86. if(type!=this.data.type){
  87. this.setData({
  88. type: type,
  89. couponList:[]
  90. })
  91. this.getCouponList();
  92. }
  93. },
  94. /**
  95. * 获取核销用户券列表
  96. */
  97. getCouponList(){
  98. app.requestGet('admin/buy/pendinglist', { user_id:this.user_id, item_type:this.data.type},res=>{
  99. if(res.code==200){
  100. this.setData({
  101. couponList: res.data
  102. })
  103. }else{
  104. wx.showToast({
  105. title: res.message,
  106. icon: 'none',
  107. duration: 2000
  108. })
  109. }
  110. })
  111. },
  112. /**
  113. * 核销
  114. */
  115. writeOff(e){
  116. var index=e.currentTarget.dataset.index;
  117. var couponId=this.data.couponList[index].coupon_sell_id;
  118. wx.navigateTo({
  119. url: '../coupon/coupon?user_id=' + this.user_id+'&coupon_sell_id='+couponId
  120. })
  121. },
  122. /**
  123. * 核销或赠送积分
  124. */
  125. changeIntegral(e){
  126. var type = parseInt(e.currentTarget.dataset.code);
  127. this.setData({
  128. integralType:type,
  129. showCoupon:false,
  130. integralNums:0,
  131. writeOffAmount:0,
  132. submiting:false
  133. })
  134. },
  135. /**
  136. * 修改核销或赠送积分
  137. */
  138. changeIntergral(e){
  139. var value=e.detail.value;
  140. var str=value.replace(/[^\d]/g,'');
  141. var writeOffAmount=0;
  142. if(this.data.integralType==1){//核销积分
  143. writeOffAmount=Math.floor(str/this.data.userInfo.base_exchange)
  144. }
  145. this.setData({
  146. integralNums: str?parseInt(str):0,
  147. writeOffAmount
  148. })
  149. },
  150. /**
  151. * 关闭积分页
  152. */
  153. closeIntegral(){
  154. this.setData({
  155. showCoupon:true
  156. })
  157. },
  158. /**
  159. * 核销或赠送积分
  160. */
  161. confirmIntegral(){
  162. if(this.data.submiting){
  163. return
  164. }else{
  165. var that=this;
  166. wx.showModal({
  167. title: '提示',
  168. content: that.data.integralType==1?'确认核销积分':'确认赠送积分',
  169. success (res) {
  170. if (res.confirm) {
  171. that.integralRequest()
  172. }
  173. }
  174. })
  175. }
  176. },
  177. /**
  178. * 积分请求
  179. */
  180. integralRequest(){
  181. var that=this;
  182. this.setData({
  183. submiting:true
  184. })
  185. var integral=this.data.integralNums;
  186. var type=this.data.integralType==1;
  187. var data,url;
  188. if(type==1){//核销积分
  189. data={
  190. user_id:this.user_id,
  191. point_check:integral,
  192. cash_exchange:this.data.writeOffAmount
  193. }
  194. url='admin/point/check';
  195. }else{//赠送积分
  196. data={
  197. user_id:this.user_id,
  198. point_add:integral
  199. }
  200. url="admin/point/add";
  201. }
  202. app.requestPost(url,data,res=>{
  203. if(res.code==200){
  204. that.getUserInfo();
  205. wx.showToast({
  206. title: type==1?'积分核销成功':'积分赠送成功',
  207. icon: 'success',
  208. duration: 2000
  209. })
  210. }else{
  211. wx.showToast({
  212. title: res.message,
  213. icon: 'none',
  214. duration: 2000
  215. })
  216. }
  217. this.setData({
  218. submiting:false
  219. })
  220. })
  221. },
  222. /**
  223. * 快速选择积分
  224. */
  225. choiceIntegral(e){
  226. var value=e.currentTarget.dataset.value;
  227. this.setData({
  228. integralNums:value
  229. })
  230. },
  231. /**
  232. * 生命周期函数--监听页面加载
  233. */
  234. onLoad: function(options) {
  235. this.user_id = options.id;
  236. this.getUserInfo();
  237. },
  238. /**
  239. * 生命周期函数--监听页面初次渲染完成
  240. */
  241. onReady: function() {
  242. },
  243. /**
  244. * 生命周期函数--监听页面显示
  245. */
  246. onShow: function() {
  247. this.getCouponList();
  248. },
  249. /**
  250. * 生命周期函数--监听页面隐藏
  251. */
  252. onHide: function() {
  253. },
  254. /**
  255. * 生命周期函数--监听页面卸载
  256. */
  257. onUnload: function() {
  258. },
  259. /**
  260. * 页面相关事件处理函数--监听用户下拉动作
  261. */
  262. onPullDownRefresh: function() {
  263. },
  264. /**
  265. * 页面上拉触底事件的处理函数
  266. */
  267. onReachBottom: function() {
  268. },
  269. /**
  270. * 用户点击右上角分享
  271. */
  272. onShareAppMessage: function() {
  273. }
  274. })