custommanage.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // pages/order/custommanage/custommanage.js
  2. let util = require('../../../utils/util.js');
  3. let pyutil = require('../../../utils/pinyin.js');
  4. var that
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. customs: [],
  11. jumpNum: '',
  12. tel: '',
  13. total: 0,
  14. totalAmount: 0,
  15. totalDebt: 0,
  16. isfirst: true,
  17. ussindex: 0
  18. },
  19. ussChane(e) {
  20. this.setData({
  21. ussindex: e.detail.value
  22. })
  23. this.getAllCustom()
  24. },
  25. settel(e) {
  26. this.setData({
  27. tel: e.detail.value
  28. })
  29. this.getAllCustom()
  30. },
  31. todetail(e) {
  32. wx.navigateTo({
  33. url: '/pages/order/customdetail/customdetail?id=' + e.currentTarget.dataset.id + "&onlyID=" + e.currentTarget.dataset.onlyid,
  34. })
  35. },
  36. toedite(e) {
  37. wx.navigateTo({
  38. url: '/pages/order/addcustom/addcustom?id=' + e.currentTarget.dataset.id
  39. })
  40. },
  41. getDefaultBook() {
  42. util.query('accountbook/wxapi/getdefault', {}, function(res) {
  43. if (res.code === 10000) {
  44. res.data.userInfos.unshift({
  45. key: 0,
  46. wechatName: '全部'
  47. })
  48. that.setData({
  49. uss: res.data.userInfos
  50. })
  51. }
  52. })
  53. },
  54. toadd() {
  55. wx.navigateTo({
  56. url: '/pages/order/addcustom/addcustom',
  57. })
  58. },
  59. del(e) {
  60. wx.showModal({
  61. title: '确认',
  62. content: '是否确定删除客户',
  63. success(res) {
  64. if (res.confirm) {
  65. util.query("customer/wxapi/delete", {
  66. id: parseInt(e.currentTarget.dataset.id)
  67. }, function(res) {
  68. if (res.code == 10000) {
  69. util.showToast('删除成功')
  70. that.getAllCustom()
  71. } else {
  72. util.showToast(res.message)
  73. }
  74. }, "POST")
  75. } else if (res.cancel) {
  76. }
  77. }
  78. })
  79. },
  80. /**
  81. * 生命周期函数--监听页面加载
  82. */
  83. onLoad: function(options) {
  84. that = this
  85. //pyutil.getPinYinFirstCharacter('?吧#:&')
  86. this.getDefaultBook()
  87. this.getAllCustom()
  88. },
  89. getAllCustom() {
  90. var data = {
  91. pageNo: 1,
  92. pageSize: 9999,
  93. nameOrPhone: this.data.tel
  94. }
  95. if (this.data.ussindex != 0) {
  96. data.creatorUid = this.data.uss[this.data.ussindex].uid
  97. }
  98. util.query('customer/wxapi/listpage', data, function(res) {
  99. if (res.code === 10000) {
  100. var da = res.data.content
  101. var pys = []
  102. for (var i in da) {
  103. da[i].debt = da[i].debt.toFixed(2)
  104. var py = pyutil.getPinYinFirstCharacter(da[i].name).toUpperCase().substr(0, 1)
  105. py = util.checkABC(py) ? py : '其他'
  106. var isfind = false
  107. for (var j in pys) {
  108. if (pys[j].py === py) {
  109. isfind = true
  110. pys[j].data.push(da[i])
  111. }
  112. }
  113. if (!isfind) {
  114. pys.push({
  115. py: py,
  116. data: [da[i]]
  117. })
  118. }
  119. }
  120. // pys = Object.keys(pys).sort(function(a, b) {
  121. // return pys[b].py - pys[a].py;
  122. // });
  123. // var sorted_keys_array = Object.keys(pys).sort((a, b) => {
  124. // return datas[b].py - datas[a].py;
  125. // });
  126. pys = pys.sort(function(a, b) {
  127. return a.py.charCodeAt() - b.py.charCodeAt()
  128. })
  129. that.setData({
  130. customs: pys,
  131. total: res.total,
  132. totalAmount: res.totalAmount.toFixed(2),
  133. totalDebt: res.totalDebt.toFixed(2)
  134. })
  135. } else {
  136. that.setData({
  137. customs: [],
  138. total: 0,
  139. totalAmount: 0,
  140. totalDebt: 0
  141. })
  142. }
  143. })
  144. },
  145. setjumpNum(e) {
  146. this.setData({
  147. jumpNum: e.currentTarget.dataset.index
  148. })
  149. },
  150. /**
  151. * 生命周期函数--监听页面初次渲染完成
  152. */
  153. onReady: function() {
  154. },
  155. /**
  156. * 生命周期函数--监听页面显示
  157. */
  158. onShow: function() {
  159. if (!this.data.isfirst) {
  160. this.getAllCustom()
  161. this.getDefaultBook()
  162. }
  163. },
  164. /**
  165. * 生命周期函数--监听页面隐藏
  166. */
  167. onHide: function() {
  168. this.setData({
  169. isfirst: false
  170. })
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function() {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function() {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function() {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function() {
  191. }
  192. })