customdetail.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // pages/order/customdetail/customdetail.js
  2. let util = require('../../../utils/util.js');
  3. var that
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. index: 1,
  10. imageurl: '',
  11. id: 0,
  12. custom: {},
  13. levelname: '',
  14. addresslist: [],
  15. showpay: false,
  16. payWayarray: [],
  17. payWayindex: 0,
  18. payWay: 1,
  19. payAmount: 0,
  20. paytime: '',
  21. isfirst: true,
  22. totalAmount: 0,
  23. totalDebt: 0,
  24. totalFreight: 0,
  25. totalPayed: 0,
  26. userName: ''
  27. },
  28. hidepay() {
  29. this.setData({
  30. showpay: false,
  31. })
  32. },
  33. setpayDate(e) {
  34. this.setData({
  35. paytime: e.detail.value
  36. })
  37. },
  38. payback() {
  39. this.setData({
  40. showpay: true,
  41. paytime: util.formatShortTime(new Date()),
  42. payWayindex: 0,
  43. payWay: 1,
  44. payAmount: 0
  45. })
  46. },
  47. savepay() {
  48. util.query('customerpayback/wxapi/create', {
  49. customer: {
  50. id: this.data.id,
  51. onlyID: this.data.onlyID
  52. },
  53. payAmount: this.data.payAmount,
  54. payWay: this.data.payWay,
  55. createTime: this.data.paytime + ' 00:00:00'
  56. }, function(res) {
  57. if (res.code === 10000) {
  58. util.showToast('保存成功')
  59. that.getDetail()
  60. that.hidepay()
  61. } else {
  62. util.showToast('保存失败')
  63. }
  64. }, 'POST')
  65. },
  66. setprice(e) {
  67. this.setData({
  68. payAmount: util.PointNum(e.detail.value)
  69. })
  70. },
  71. payWayChange(e) {
  72. this.setData({
  73. payWayindex: e.detail.value,
  74. payWay: this.data.payWayarray[e.detail.value].key,
  75. payWayname: this.data.payWayarray[e.detail.value].name
  76. })
  77. },
  78. setindex(e) {
  79. this.setData({
  80. index: e.currentTarget.dataset.index
  81. })
  82. },
  83. toaddress() {
  84. wx.navigateTo({
  85. url: '/pages/order/addAddress/addAddress?customerOnlyId=' + this.data.custom.onlyID
  86. })
  87. },
  88. toediteaddress(e) {
  89. wx.navigateTo({
  90. url: '/pages/order/addAddress/addAddress?id=' + e.currentTarget.dataset.id
  91. })
  92. },
  93. getDetail() {
  94. util.query('customer/wxapi/findbyid', {
  95. id: this.data.id
  96. }, function(res) {
  97. if (res.code === 10000) {
  98. // var levelname = ''
  99. // switch (res.data.customerLevel) {
  100. // case '1':
  101. // levelname = ''
  102. // break;
  103. // }
  104. var orderda = []
  105. res.orderList.forEach(function(e) {
  106. var payWayname = ''
  107. var pw = that.data.payWayarray
  108. for (var i = 0; i < pw.length; i++) {
  109. if (pw[i].key === e.payWay) {
  110. payWayname = pw[i].name
  111. break;
  112. }
  113. }
  114. orderda.push({
  115. time: e.submitDate ? (e.submitDate.split(' ')[0]) : '',
  116. realReceive: e.realReceive ? e.realReceive : 0,
  117. debt: e.debt ? e.debt : 0,
  118. salesPrice: e.salesPrice ? e.salesPrice : 0,
  119. freight: e.freight ? e.freight : 0,
  120. payWayname: payWayname
  121. })
  122. })
  123. var payBackList = []
  124. res.payBackList.forEach(function(e) {
  125. var payWayname = ''
  126. var pw = that.data.payWayarray
  127. for (var i = 0; i < pw.length; i++) {
  128. if (pw[i].key === e.payWay) {
  129. payWayname = pw[i].name
  130. break;
  131. }
  132. }
  133. payBackList.push({
  134. time: e.createTime ? e.createTime.split(' ')[0] : '',
  135. payAmount: e.payAmount,
  136. payWayname: payWayname,
  137. username: e.userName
  138. })
  139. })
  140. that.setData({
  141. custom: res.data,
  142. orderList: orderda,
  143. payBackList: payBackList,
  144. totalAmount: res.totalAmount,
  145. totalDebt: res.totalDebt,
  146. totalFreight: res.totalFreight,
  147. totalPayed: res.totalPayed,
  148. })
  149. that.getAddressList()
  150. } else {
  151. util.showToast('未找到该客户信息')
  152. }
  153. })
  154. },
  155. getAddressList() {
  156. util.query('customeraddress/wxapi/listpage', {
  157. customerOnlyId: this.data.custom.onlyID,
  158. pageNo: 1,
  159. pageSize: 9999
  160. }, function(res) {
  161. if (res.code === 10000) {
  162. that.setData({
  163. addresslist: res.data.content
  164. })
  165. } else {
  166. that.setData({
  167. addresslist: []
  168. })
  169. }
  170. })
  171. },
  172. /**
  173. * 生命周期函数--监听页面加载
  174. */
  175. onLoad: function(options) {
  176. that = this
  177. util.checklogin(
  178. function() {
  179. var ui = wx.getStorageSync('userinfo')
  180. if (ui) {
  181. that.setData({
  182. user: ui
  183. })
  184. }
  185. if (options.id) {
  186. that.setData({
  187. id: options.id,
  188. onlyID: options.onlyID
  189. })
  190. that.getDetail()
  191. }
  192. util.getPayWay(function(e) {
  193. that.setData({
  194. payWayarray: e
  195. })
  196. })
  197. }
  198. )
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onReady: function() {
  204. },
  205. /**
  206. * 生命周期函数--监听页面显示
  207. */
  208. onShow: function() {
  209. if (!this.data.isfirst) {
  210. that.getDetail()
  211. }
  212. },
  213. /**
  214. * 生命周期函数--监听页面隐藏
  215. */
  216. onHide: function() {
  217. this.setData({
  218. isfirst: false
  219. })
  220. },
  221. /**
  222. * 生命周期函数--监听页面卸载
  223. */
  224. onUnload: function() {
  225. },
  226. /**
  227. * 页面相关事件处理函数--监听用户下拉动作
  228. */
  229. onPullDownRefresh: function() {
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. onReachBottom: function() {
  235. },
  236. /**
  237. * 用户点击右上角分享
  238. */
  239. onShareAppMessage: function() {
  240. }
  241. })