|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- // pages/member/member.js
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- userInfo: {
- avatarUrl: '',
- nickName: '',
- phone: '',
- memberNo: 1,
- integral: 0,
- level_name:'',
- level_cash:0,
- level_point:0,
- base_exchange:1
- },
- memberLe: ['一', '二', '三', '四', '五', '六','七','八','九','十'],
- type:1,
- couponList:[],
- showCoupon:true,
- integralType:1,//1核销积分 2赠送积分
- integralNums:0,
- writeOffAmount:0,//核销金额
- multipleList:[1,10,50,300,500],
- submiting:false
- },
- user_id:null,
- /**
- * 获取用户信息
- */
- getUserInfo() {
- var that = this;
- app.requestGet('admin/buy/userinfo', {
- user_id: this.user_id
- }, res => {
- if (res.code == 200) {
- var {
- headimgurl,
- nickname,
- user_phone,
- user_level,
- user_point_all,
- user_point_use,
- level_name,
- level_cash,
- level_point,
- base_exchange
- } = res.data;
- var userInfo = {
- avatarUrl: headimgurl,
- nickName: nickname,
- phone: that.handlePhone(user_phone),
- memberNo: user_level,
- integral: user_point_all - user_point_use,
- level_name,
- level_cash,
- level_point,
- base_exchange
- }
- this.setData({
- userInfo: userInfo
- })
- } else {
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 2000
- })
- }
- })
- },
- /**
- * 手机号隐藏处理
- */
- handlePhone(phone) {
- var str = phone + '';
- return str.slice(0, 3) + '****' + str.slice(-4)
- },
- /**
- * 切换券类型
- */
- changeType(e){
- var type = parseInt(e.currentTarget.dataset.type);
- if(type!=this.data.type){
- this.setData({
- type: type,
- couponList:[]
- })
- this.getCouponList();
- }
- },
- /**
- * 获取核销用户券列表
- */
- getCouponList(){
- app.requestGet('admin/buy/pendinglist', { user_id:this.user_id, item_type:this.data.type},res=>{
- if(res.code==200){
- this.setData({
- couponList: res.data
- })
- }else{
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 2000
- })
- }
- })
- },
- /**
- * 核销
- */
- writeOff(e){
- var index=e.currentTarget.dataset.index;
- var couponId=this.data.couponList[index].coupon_sell_id;
- wx.navigateTo({
- url: '../coupon/coupon?user_id=' + this.user_id+'&coupon_sell_id='+couponId
- })
- },
- /**
- * 核销或赠送积分
- */
- changeIntegral(e){
- var type = parseInt(e.currentTarget.dataset.code);
- this.setData({
- integralType:type,
- showCoupon:false,
- integralNums:0,
- writeOffAmount:0,
- submiting:false
- })
- },
- /**
- * 修改核销或赠送积分
- */
- changeIntergral(e){
- var value=e.detail.value;
- var str=value.replace(/[^\d]/g,'');
- var writeOffAmount=0;
- if(this.data.integralType==1){//核销积分
- writeOffAmount=Math.floor(str/this.data.userInfo.base_exchange)
- }
- this.setData({
- integralNums: str?parseInt(str):0,
- writeOffAmount
- })
- },
- /**
- * 关闭积分页
- */
- closeIntegral(){
- this.setData({
- showCoupon:true
- })
- },
- /**
- * 核销或赠送积分
- */
- confirmIntegral(){
- if(this.data.submiting){
- return
- }else{
- var that=this;
- wx.showModal({
- title: '提示',
- content: that.data.integralType==1?'确认核销积分':'确认赠送积分',
- success (res) {
- if (res.confirm) {
- that.integralRequest()
- }
- }
- })
- }
- },
- /**
- * 积分请求
- */
- integralRequest(){
- var that=this;
- this.setData({
- submiting:true
- })
- var integral=this.data.integralNums;
- var type=this.data.integralType==1;
- var data,url;
- if(type==1){//核销积分
- data={
- user_id:this.user_id,
- point_check:integral,
- cash_exchange:this.data.writeOffAmount
- }
- url='admin/point/check';
- }else{//赠送积分
- data={
- user_id:this.user_id,
- point_add:integral
- }
- url="admin/point/add";
- }
- app.requestPost(url,data,res=>{
- if(res.code==200){
- that.getUserInfo();
- wx.showToast({
- title: type==1?'积分核销成功':'积分赠送成功',
- icon: 'success',
- duration: 2000
- })
- }else{
- wx.showToast({
- title: res.message,
- icon: 'none',
- duration: 2000
- })
- }
- this.setData({
- submiting:false
- })
- })
- },
- /**
- * 快速选择积分
- */
- choiceIntegral(e){
- var value=e.currentTarget.dataset.value;
- this.setData({
- integralNums:value
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- this.user_id = options.id;
- this.getUserInfo();
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- this.getCouponList();
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
-
- }
- })
|