123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- // pages/order/custommanage/custommanage.js
- let util = require('../../../utils/util.js');
- let pyutil = require('../../../utils/pinyin.js');
- var that
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- customs: [],
- jumpNum: '',
- tel: '',
- total: 0,
- totalAmount: 0,
- totalDebt: 0,
- isfirst: true,
- ussindex: 0
- },
- ussChane(e) {
- this.setData({
- ussindex: e.detail.value
- })
- this.getAllCustom()
- },
- settel(e) {
- this.setData({
- tel: e.detail.value
- })
- this.getAllCustom()
- },
- todetail(e) {
- wx.navigateTo({
- url: '/pages/order/customdetail/customdetail?id=' + e.currentTarget.dataset.id + "&onlyID=" + e.currentTarget.dataset.onlyid,
- })
- },
- toedite(e) {
- wx.navigateTo({
- url: '/pages/order/addcustom/addcustom?id=' + e.currentTarget.dataset.id
- })
- },
- getDefaultBook() {
- util.query('accountbook/wxapi/getdefault', {}, function(res) {
- if (res.code === 10000) {
- res.data.userInfos.unshift({
- key: 0,
- wechatName: '全部'
- })
- that.setData({
- uss: res.data.userInfos
- })
- }
- })
- },
- toadd() {
- wx.navigateTo({
- url: '/pages/order/addcustom/addcustom',
- })
- },
- del(e) {
- wx.showModal({
- title: '确认',
- content: '是否确定删除客户',
- success(res) {
- if (res.confirm) {
- util.query("customer/wxapi/delete", {
- id: parseInt(e.currentTarget.dataset.id)
- }, function(res) {
- if (res.code == 10000) {
- util.showToast('删除成功')
- that.getAllCustom()
- } else {
- util.showToast(res.message)
- }
- }, "POST")
- } else if (res.cancel) {
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- that = this
- //pyutil.getPinYinFirstCharacter('?吧#:&')
- this.getDefaultBook()
- this.getAllCustom()
- },
- getAllCustom() {
- var data = {
- pageNo: 1,
- pageSize: 9999,
- nameOrPhone: this.data.tel
- }
- if (this.data.ussindex != 0) {
- data.creatorUid = this.data.uss[this.data.ussindex].uid
- }
- util.query('customer/wxapi/listpage', data, function(res) {
- if (res.code === 10000) {
- var da = res.data.content
- var pys = []
- for (var i in da) {
- da[i].debt = da[i].debt.toFixed(2)
- var py = pyutil.getPinYinFirstCharacter(da[i].name).toUpperCase().substr(0, 1)
- py = util.checkABC(py) ? py : '其他'
- var isfind = false
- for (var j in pys) {
- if (pys[j].py === py) {
- isfind = true
- pys[j].data.push(da[i])
- }
- }
- if (!isfind) {
- pys.push({
- py: py,
- data: [da[i]]
- })
- }
- }
- // pys = Object.keys(pys).sort(function(a, b) {
- // return pys[b].py - pys[a].py;
- // });
- // var sorted_keys_array = Object.keys(pys).sort((a, b) => {
- // return datas[b].py - datas[a].py;
- // });
- pys = pys.sort(function(a, b) {
- return a.py.charCodeAt() - b.py.charCodeAt()
- })
- that.setData({
- customs: pys,
- total: res.total,
- totalAmount: res.totalAmount.toFixed(2),
- totalDebt: res.totalDebt.toFixed(2)
- })
- } else {
- that.setData({
- customs: [],
- total: 0,
- totalAmount: 0,
- totalDebt: 0
- })
- }
- })
- },
- setjumpNum(e) {
- this.setData({
- jumpNum: e.currentTarget.dataset.index
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- if (!this.data.isfirst) {
- this.getAllCustom()
- this.getDefaultBook()
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- this.setData({
- isfirst: false
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|