settlement.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. let util = require('../../../utils/util.js');
  2. var that
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isPinkage: false,
  9. freight: 0,
  10. salesPrice: 0,
  11. addressname: '',
  12. customerid: 0,
  13. customeronlyid: '',
  14. addressid: 0,
  15. addressonlyid: '',
  16. isReceivables: false,
  17. isPayment: false,
  18. payWayarray: [],
  19. payWayindex: 0,
  20. deliveryTypeArray: [{
  21. key: 1,
  22. name: '快递'
  23. }, {
  24. key: 2,
  25. name: '上门'
  26. }, {
  27. key: 3,
  28. name: '自取'
  29. }],
  30. deliveryTypeIndex: 0,
  31. deliveryType: 1,
  32. realReceive: 0
  33. },
  34. deliveryTypeChange(e) {
  35. this.setData({
  36. deliveryTypeIndex: e.detail.value,
  37. deliveryType: this.data.deliveryTypeArray[e.detail.value].key
  38. })
  39. },
  40. freshdebt() {
  41. if (this.data.isReceivables) {
  42. this.setData({
  43. debt: parseFloat(parseFloat(this.data.salesPrice ? this.data.salesPrice : 0) - parseFloat(this.data.realReceive ? this.data.realReceive : 0)).toFixed(2)
  44. })
  45. }
  46. },
  47. freshsalesPrice() {
  48. var salesPrice = 0
  49. this.data.goods.forEach(function(e) {
  50. salesPrice += parseFloat((e.sale ? e.sale : 0) * (e.num ? e.num : 0))
  51. })
  52. this.setData({
  53. salesPrice: salesPrice.toFixed(2)
  54. })
  55. this.freshdebt()
  56. },
  57. payWayChange(e) {
  58. this.setData({
  59. payWayindex: e.detail.value,
  60. payWay: this.data.payWayarray[e.detail.value].key,
  61. payWayname: this.data.payWayarray[e.detail.value].name
  62. })
  63. },
  64. setrealReceive(e) {
  65. this.setData({
  66. realReceive: util.PointNum(e.detail.value)
  67. })
  68. this.freshdebt()
  69. },
  70. save() {
  71. // if (!this.data.customerid) {
  72. // util.showToast('请选择收货人')
  73. // return
  74. // }
  75. var goods = []
  76. this.data.goods.forEach(function(e) {
  77. goods.push({
  78. goods: {
  79. id: e.goodid,
  80. onlyID: e.goodonlyid
  81. },
  82. goodsBatch: {
  83. id: e.goodsBatchid,
  84. onlyID: e.goodsBatchonlyid
  85. },
  86. number: e.num,
  87. salesVolume: e.sale,
  88. id: e.ordergoodid
  89. })
  90. })
  91. var data = {
  92. orderGoodsList: goods,
  93. isPinkage: this.data.isPinkage ? 1 : 0,
  94. salesPrice: this.data.salesPrice,
  95. submitDate: this.data.submitDate + ' 00:00:00',
  96. salenote: this.data.salenote,
  97. isReceivables: this.data.isReceivables ? 1 : 0,
  98. isPayment: this.data.isPayment ? 1 : 0,
  99. isSend: this.data.isSend ? 1 : 0,
  100. freight: this.data.freight ? this.data.freight : 0
  101. }
  102. if (this.data.customerid) {
  103. data.customer = {
  104. id: this.data.customerid,
  105. onlyID: this.data.customeronlyid
  106. }
  107. data.customerAddress = {
  108. id: this.data.addressid,
  109. onlyID: this.data.addressonlyid
  110. }
  111. }
  112. if (this.data.isReceivables) {
  113. data.realReceive = this.data.realReceive
  114. data.debt = this.data.debt
  115. data.payWay = this.data.payWayarray[this.data.payWayindex].key
  116. }
  117. if (this.data.isSend) {
  118. data.deliveryType = this.data.deliveryTypeArray[this.data.deliveryTypeIndex].key
  119. data.courierCompany = this.data.courierCompany
  120. data.courierNumber = this.data.courierNumber
  121. }
  122. var url = ''
  123. if (this.data.orderid) {
  124. url = 'order/wxapi/update'
  125. data = Object.assign(this.data.olddata, data)
  126. } else {
  127. url = 'order/wxapi/create'
  128. }
  129. util.query(url, data, function(res) {
  130. if (res.code === 10000) {
  131. util.showToast('保存成功')
  132. setTimeout(function() {
  133. wx.switchTab({
  134. url: '/pages/order/order/order',
  135. })
  136. }, 2000)
  137. } else {
  138. util.showToast('保存失败')
  139. }
  140. }, 'POST')
  141. },
  142. delgood(e) {
  143. var goods = this.data.goods
  144. goods.splice(e.currentTarget.dataset.index, 1)
  145. this.setData({
  146. goods: goods
  147. })
  148. this.freshsalesPrice()
  149. },
  150. setcourierNumber(e) {
  151. this.setData({
  152. courierNumber: e.detail.value
  153. })
  154. },
  155. setcourierCompany(e) {
  156. this.setData({
  157. courierCompany: e.detail.value
  158. })
  159. },
  160. setnum(e) {
  161. var goods = this.data.goods
  162. goods[e.currentTarget.dataset.index].num = util.PointNum(e.detail.value)
  163. this.setData({
  164. goods: goods
  165. })
  166. this.freshsalesPrice()
  167. },
  168. setsale(e) {
  169. var goods = this.data.goods
  170. goods[e.currentTarget.dataset.index].sale = util.PointNum(e.detail.value)
  171. this.setData({
  172. goods: goods
  173. })
  174. this.freshsalesPrice()
  175. },
  176. setsalenote(e) {
  177. this.setData({
  178. salenote: e.detail.value
  179. })
  180. },
  181. setsalesPrice(e) {
  182. this.setData({
  183. salesPrice: e.detail.value
  184. })
  185. },
  186. setfreight(e) {
  187. this.setData({
  188. freight: util.PointNum(e.detail.value)
  189. })
  190. },
  191. setisPinkage(e) {
  192. this.setData({
  193. isPinkage: e.detail.value
  194. })
  195. },
  196. setisSend(e) {
  197. if (e.detail.value && this.data.customerid === 0) {
  198. util.showToast('请选择收货人')
  199. this.setData({
  200. isSend: false
  201. })
  202. return
  203. }
  204. this.setData({
  205. isSend: e.detail.value
  206. })
  207. },
  208. setisPayment(e) {
  209. this.setData({
  210. isPayment: e.detail.value
  211. })
  212. },
  213. setisReceivables(e) {
  214. this.setData({
  215. isReceivables: e.detail.value
  216. })
  217. this.freshdebt()
  218. },
  219. bindtime(e) {
  220. this.setData({
  221. submitDate: e.detail.value
  222. })
  223. },
  224. tochoiseAddress() {
  225. wx.navigateTo({
  226. url: '/pages/order/choiseAddress/choiseAddress',
  227. })
  228. },
  229. getDetail() {
  230. util.query('order/wxapi/findbyid', {
  231. id: this.data.orderid
  232. }, function(res) {
  233. if (res.code === 10000) {
  234. var pws = that.data.payWayarray
  235. var payWayindex = 0
  236. for (var i = 0; i < pws.length; i++) {
  237. if (pws[i].key === res.data.payWay) {
  238. payWayindex = i
  239. break
  240. }
  241. }
  242. var dts = that.data.deliveryTypeArray,
  243. deliveryTypeIndex
  244. for (var i = 0; i < dts.length; i++) {
  245. if (dts[i].key + '' === res.data.deliveryType) {
  246. deliveryTypeIndex = i
  247. }
  248. }
  249. var goods = []
  250. res.data.orderGoodsList.forEach(function(e) {
  251. goods.push({
  252. goodid: e.goods.id,
  253. goodname: e.goods.name,
  254. price: e.goodsBatch.purchasePrice,
  255. goodonlyid: e.goods.onlyID,
  256. goodsBatchid: e.goodsBatch.id,
  257. goodsBatchonlyid: e.goodsBatch.onlyID,
  258. num: e.number,
  259. sale: e.salesVolume,
  260. ordergoodid: e.id
  261. })
  262. })
  263. that.setData({
  264. isPinkage: res.data.isPinkage === '1' ? true : false,
  265. freight: res.data.freight,
  266. salesPrice: res.data.salesPrice,
  267. addressname: res.data.customerAddress ? res.data.customerAddress.name : '',
  268. customerid: res.data.customer ? res.data.customer.id : 0,
  269. customeronlyid: res.data.customer ? res.data.customer.onlyID : '',
  270. addressid: res.data.customerAddress ? res.data.customerAddress.id : 0,
  271. addressonlyid: res.data.customerAddress ? res.data.customerAddress.onlyID : '',
  272. isReceivables: res.data.isReceivables === 1 ? true : false,
  273. isPayment: res.data.isPayment === 1 ? true : false,
  274. payWayindex: payWayindex,
  275. deliveryTypeIndex: deliveryTypeIndex,
  276. realReceive: res.data.realReceive,
  277. submitDate: res.data.submitDate ? res.data.submitDate.split(' ')[0] : '',
  278. salenote: res.data.salenote,
  279. isSend: res.data.isSend === 1 ? true : false,
  280. debt: res.data.debt,
  281. courierCompany: res.data.courierCompany,
  282. courierNumber: res.data.courierNumber,
  283. goods: goods,
  284. olddata: res.data
  285. })
  286. } else {
  287. util.showToast('获取详情失败')
  288. }
  289. })
  290. },
  291. del() {
  292. wx.showModal({
  293. title: '确认',
  294. content: '是否确定删除订单',
  295. success(res) {
  296. if (res.confirm) {
  297. util.query("order/wxapi/delete", {
  298. id: that.data.olddata.id
  299. }, function(res) {
  300. if (res.code == 10000) {
  301. util.showToast('删除成功')
  302. setTimeout(function() {
  303. wx.navigateBack({
  304. delta: 1
  305. })
  306. }, 2000)
  307. } else {
  308. util.showToast(res.message)
  309. }
  310. }, "POST")
  311. } else if (res.cancel) {
  312. }
  313. }
  314. })
  315. },
  316. /**
  317. * 生命周期函数--监听页面加载
  318. */
  319. onLoad: function(options) {
  320. // options.goods = JSON.stringify([{
  321. // goodid: 234776,
  322. // goodname: '红米手机',
  323. // price: 10,
  324. // goodonlyid: '928502452021897932341492096432414',
  325. // goodsBatchid: 308787,
  326. // goodsBatchonlyid: '902801730046553607347570690271441'
  327. // }, {
  328. // goodid: 234775,
  329. // goodname: '红米手机',
  330. // price: 20,
  331. // goodonlyid: '873890605297730500447478226706003',
  332. // goodsBatchid: 308785,
  333. // goodsBatchonlyid: '811124563377812956890532518415719'
  334. // }])
  335. that = this
  336. util.checklogin(function() {
  337. util.getPayWay(function(e) {
  338. that.setData({
  339. payWayarray: e
  340. })
  341. if (options.id) {
  342. that.setData({
  343. orderid: options.id
  344. })
  345. that.getDetail()
  346. } else if (options.goods) {
  347. var goods = JSON.parse(options.goods)
  348. for (var i = 0; i < goods.length; i++) {
  349. //goods[i].sale = goods[i].price
  350. goods[i].num = 1
  351. goods[i].lastprice = 0
  352. // that.getLastPrice(goods[i].goodid, i)
  353. }
  354. // goods.forEach(function(res) {
  355. // res.sale = res.price
  356. // res.num = 1
  357. // })
  358. that.setData({
  359. goods: goods
  360. })
  361. that.freshsalesPrice()
  362. }
  363. that.setData({
  364. submitDate: util.formatTime(new Date()).split(' ')[0]
  365. })
  366. })
  367. })
  368. },
  369. updatelast(customerId) {
  370. for (var i = 0; i < this.data.goods.length; i++) {
  371. this.getLastPrice(this.data.goods[i].goodid, customerId, i)
  372. }
  373. },
  374. getLastPrice(id, customerId, num) {
  375. util.query('order/wxapi/getLastPrice', {
  376. productId: id,
  377. customerId: customerId
  378. }, function(res) {
  379. if (res.code === 10000) {
  380. var goods = that.data.goods
  381. goods[num].lastprice = res.data
  382. that.setData({
  383. goods: goods
  384. })
  385. }
  386. })
  387. },
  388. /**
  389. * 生命周期函数--监听页面初次渲染完成
  390. */
  391. onReady: function() {
  392. },
  393. /**
  394. * 生命周期函数--监听页面显示
  395. */
  396. onShow: function() {
  397. },
  398. /**
  399. * 生命周期函数--监听页面隐藏
  400. */
  401. onHide: function() {
  402. },
  403. /**
  404. * 生命周期函数--监听页面卸载
  405. */
  406. onUnload: function() {
  407. },
  408. /**
  409. * 页面相关事件处理函数--监听用户下拉动作
  410. */
  411. onPullDownRefresh: function() {
  412. },
  413. /**
  414. * 页面上拉触底事件的处理函数
  415. */
  416. onReachBottom: function() {
  417. },
  418. /**
  419. * 用户点击右上角分享
  420. */
  421. onShareAppMessage: function() {
  422. }
  423. })