123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- // pages/customermanage/customermanage.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- pagesList: [],
- loading: true,
- dataLoadComplete: false,
- params: {
- pageNum: 1,
- pageSize: 15,
- },
- },
- addCustomer() {
- wx.navigateTo({
- url: '/pages/customermanage/addcustomer'
- })
- },
- getList(showSetTip) {
- const that = this;
- wx.showLoading({ mask: true });
- this.setData({
- title: '加载中',
- loading: true
- })
- const params = JSON.parse(JSON.stringify(that.data.params));
- app.$http.get('/user/getAccountInfoPage', params).then(({ status, data: { list = [], total = 0 }, msg }) => {
- if (0 === status) {
- let result = list,
- dataLoadComplete = false;
- // 判断数据是否全部加载完成
- if (15 != list.length) {
- dataLoadComplete = true;
- }
- // 不是第一页时,合并原有数据
- if (1 != params.pageNum) {
- result = this.data.pagesList.concat(result)
- }
- this.setData({
- pagesList: result,
- dataLoadComplete
- })
- }
- wx.hideLoading();
- this.setData({
- loading: false
- })
- if(showSetTip) {
- wx.showToast({
- title: '设置成功',
- icon: 'success'
- })
- }
- }).catch(() => {
- wx.hideLoading();
- this.setData({
- loading: false
- })
- })
- },
- // 滚动到处理
- scrollBottom() {
- if (this.data.dataLoadComplete) {
- return
- }
- this.setData({
- 'params.pageNum': this.data.params.pageNum + 1
- })
- this.getList();
- },
- setDefault(e) {
- const { id, isDefault } = e.currentTarget.dataset.item;
- if (!isDefault) {
- wx.showLoading();
- app.$http.postForm('/user/setDefault', {
- id
- }).then(({ status, msg }) => {
- if (status === 0) {
-
- app.globalData = {};
- app.getUserInfo(app.token);
- this.getList(true);
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- wx.hideLoading();
- }).catch(() => {
- wx.hideLoading();
- })
- }
- },
- unbindDevice(e) {
- const {id, username, userNumber} = e.currentTarget.dataset.item;
- this.popup.setData({
- extClass: 'customer-popup',
- showIcon: false,
- title: '您确认解绑当前户号?',
- content: `户名:${username || '-'}`,
- content1: `户号:${userNumber || '-'}`,
- params: {
- id
- }
- });
- this.popup.show();
- },
- call(e){
- let mobile= e.currentTarget.dataset['index'];
- if(mobile!==""){
- wx.makePhoneCall({
- phoneNumber: mobile
- })
- }
- },
- cancelEvent: function () {
- this.popup.close();
- },
- confirmEvent: function () {
- const self = this;
- if (this.popup.data.type == 'success' && this.popup.data.params) {
- const { id } = this.popup.data.params;
- app.$http.deleteForm('/user/cancelBind', {
- id
- }).then(({ status, msg }) => {
- if (status === 0) {
- wx.showToast({
- title: '解绑成功',
- })
- setTimeout(() => {
- self.getList();
- app.globalData = {};
- app.getUserInfo(app.token);
- self.popup.close();
- }, 1500)
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- //获得popup组件
- this.popup = this.selectComponent("#popup");
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getList();
- },
- })
|