supplierdetail.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. let util = require('../../../utils/util.js');
  2. var that
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. index: 1,
  9. imageurl: '',
  10. showpay: false,
  11. payWayarray: [],
  12. payWayindex: 0,
  13. paydate: ''
  14. },
  15. savepay() {
  16. if (!this.data.payAmount) {
  17. util.showToast('请输入金额')
  18. return
  19. }
  20. util.query('supplierpayback/wxapi/create', {
  21. supplier: {
  22. id: this.data.id,
  23. onlyID: this.data.onlyid
  24. },
  25. payAmount: this.data.payAmount,
  26. payWay: this.data.payWayarray[this.data.payWayindex].key,
  27. createTime: this.data.paydate + ' 00:00:00'
  28. }, function(res) {
  29. if (res.code === 10000) {
  30. util.showToast('保存成功')
  31. that.getpayback()
  32. that.getData()
  33. that.setData({
  34. showpay: false
  35. })
  36. } else {
  37. util.showToast('保存失败')
  38. }
  39. }, 'POST')
  40. },
  41. payback() {
  42. this.setData({
  43. showpay: true,
  44. paydate: util.formatShortTime(new Date()),
  45. payWayindex: 0,
  46. payAmount: ''
  47. })
  48. },
  49. paytimechange(e) {
  50. this.setData({
  51. paydate: e.detail.value
  52. })
  53. },
  54. setprice(e) {
  55. this.setData({
  56. payAmount: util.PointNum(e.detail.value)
  57. })
  58. },
  59. payWayChange(e) {
  60. this.setData({
  61. payWayindex: e.detail.value
  62. })
  63. },
  64. setindex(e) {
  65. this.setData({
  66. index: e.currentTarget.dataset.index
  67. })
  68. },
  69. del(e) {
  70. wx.showModal({
  71. title: '确认',
  72. content: '是否确定删除供应商',
  73. success(res) {
  74. if (res.confirm) {
  75. util.query("supplier/wxapi/delete", {
  76. id: that.data.id
  77. }, function(res) {
  78. if (res.code == 10000) {
  79. util.showToast('删除成功')
  80. setTimeout(function() {
  81. let pages = getCurrentPages()
  82. let prevPage = pages[pages.length - 2]
  83. wx.navigateBack({
  84. delta: 1
  85. })
  86. }, 2000)
  87. } else {
  88. util.showToast(res.message)
  89. }
  90. }, "POST")
  91. } else if (res.cancel) {
  92. }
  93. }
  94. })
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. onLoad: function(options) {
  100. that = this
  101. if (options.id) {
  102. this.setData({
  103. id: options.id,
  104. onlyid: options.onlyid
  105. })
  106. util.getPayWay(function(e) {
  107. that.setData({
  108. payWayarray: e
  109. })
  110. that.getData()
  111. that.getpayback()
  112. that.getbuyrecord()
  113. })
  114. }
  115. },
  116. hidepay() {
  117. this.setData({
  118. showpay: false,
  119. })
  120. },
  121. delpay(e) {
  122. wx.showModal({
  123. title: '确认',
  124. content: '是否确定删除付款记录',
  125. success(res) {
  126. if (res.confirm) {
  127. util.query("supplierpayback/wxapi/delete", {
  128. id: e.currentTarget.dataset.id
  129. }, function(res) {
  130. if (res.code == 10000) {
  131. util.showToast('删除成功')
  132. that.getpayback()
  133. that.getData()
  134. } else {
  135. util.showToast(res.message)
  136. }
  137. }, "POST")
  138. } else if (res.cancel) {
  139. }
  140. }
  141. })
  142. },
  143. getData() {
  144. util.query('/supplier/wxapi/findbyid', {
  145. id: this.data.id
  146. }, function(res) {
  147. if (res.code === 10000) {
  148. res.alreadyPayed = res.alreadyPayed.toFixed(2)
  149. res.needPay = res.needPay.toFixed(2)
  150. res.purchaseNum = res.purchaseNum.toFixed(2)
  151. res.stockNum = res.stockNum.toFixed(2)
  152. res.sumAmount = res.sumAmount.toFixed(2)
  153. res.totalAmount = res.totalAmount.toFixed(2)
  154. res.totalDiscount = res.totalDiscount.toFixed(2)
  155. that.setData(res)
  156. }
  157. })
  158. },
  159. getpayback() {
  160. util.query('supplierpayback/wxapi/listpage', {
  161. supplierOnlyId: this.data.onlyid,
  162. pageNo: 1,
  163. pageSize: 9999
  164. }, function(res) {
  165. if (res.code === 10000) {
  166. res.data.content.forEach(function(e) {
  167. var pyname = ''
  168. that.data.payWayarray.forEach(function(fe) {
  169. if (fe.key === e.payWay) {
  170. pyname = fe.name
  171. }
  172. })
  173. e.pyname = pyname
  174. })
  175. that.setData({
  176. plist: res.data.content
  177. })
  178. }
  179. })
  180. },
  181. getbuyrecord() {
  182. util.query('supplier/wxapi/findPurchaseRecord', {
  183. id: this.data.id
  184. }, function(res) {
  185. if (res.code === 10000) {
  186. that.setData({
  187. bdata: res.data
  188. })
  189. }
  190. })
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady: function() {
  196. },
  197. /**
  198. * 生命周期函数--监听页面显示
  199. */
  200. onShow: function() {
  201. },
  202. /**
  203. * 生命周期函数--监听页面隐藏
  204. */
  205. onHide: function() {
  206. },
  207. /**
  208. * 生命周期函数--监听页面卸载
  209. */
  210. onUnload: function() {
  211. },
  212. /**
  213. * 页面相关事件处理函数--监听用户下拉动作
  214. */
  215. onPullDownRefresh: function() {
  216. },
  217. /**
  218. * 页面上拉触底事件的处理函数
  219. */
  220. onReachBottom: function() {
  221. },
  222. /**
  223. * 用户点击右上角分享
  224. */
  225. onShareAppMessage: function() {
  226. }
  227. })