select-source-purchase-order.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. const Constants = require('@/utils/Constants.js');
  2. const util = require('@/utils/util.js')
  3. const mixins = require('@/mixins/index.js')
  4. Page({
  5. mixins: [mixins],
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. returnTotalAmount: 0,
  11. allChecked: false,
  12. // 路由
  13. routeObjName: 'inbound',
  14. tableData: [],
  15. choooseInboundItemList: [],
  16. buttonSaveList: [{ code: 'add', title: mixins.$t('confirm'), width: '120rpx', color: '#1B365D' }],
  17. contentSaveList: [{code:'flag',title:'全退',type:'checkbox'},{code:'need',title:'退货总额',type:'str'},{code:'amount',content:0,type:'number'}],
  18. },
  19. /**
  20. * @desc : 加载数据源
  21. * @date : 2024/2/1 15:49
  22. * @author : 于继渤
  23. */
  24. getData(params) {
  25. return this.excute(this.data.service, this.data.service.selectInboundAndItem, params);
  26. },
  27. /**
  28. * @desc : 设置查询参数
  29. * @date : 2024/2/1 15:49
  30. * @author : 于继渤
  31. */
  32. setSearchParams(params) {
  33. params.intoType = Constants.intoType.pur
  34. params.fromId = this.data.id
  35. return params
  36. },
  37. /**
  38. * @desc : 父级商品信息选择
  39. * @date : 2024/2/1 15:49
  40. * @author : 于继渤
  41. */
  42. onListItemChange(e) {
  43. let tableData = this.data.tableData
  44. let index = e.currentTarget.dataset.index
  45. tableData[index].checked = !tableData[index].checked
  46. let inboundItemList = tableData[index].inboundItemList
  47. if (inboundItemList && inboundItemList.length > 0) {
  48. inboundItemList.forEach(res => {
  49. res.checked = tableData[index].checked
  50. })
  51. }
  52. this.setData({
  53. tableData: tableData
  54. })
  55. this.calculateTotal()
  56. },
  57. /**
  58. * @desc : 子级商品信息选择
  59. * @date : 2024/2/1 15:49
  60. * @author : 于继渤
  61. */
  62. onChangeItemCheckbox(e) {
  63. let tableData = this.data.tableData
  64. let index = e.currentTarget.dataset.index
  65. let index_ = e.currentTarget.dataset.index_
  66. console.log(index, index_)
  67. tableData[index].inboundItemList[index_].checked = !tableData[index].inboundItemList[index_].checked
  68. this.setData({
  69. tableData: tableData
  70. })
  71. this.calculateTotal()
  72. },
  73. /**
  74. * @desc : 全退
  75. * @date : 2024/2/1 15:49
  76. * @author : 于继渤
  77. */
  78. onCheckboxChange(e) {
  79. console.log(e.detail.checked)
  80. let checked = e.detail.checked
  81. let tableData = this.data.tableData
  82. tableData.forEach(res => {
  83. res.checked = checked
  84. if (res.inboundItemList && res.inboundItemList.length > 0) {
  85. res.inboundItemList.forEach(item => {
  86. item.checked = checked
  87. })
  88. }
  89. })
  90. this.setData({
  91. tableData: tableData
  92. })
  93. this.calculateTotal()
  94. },
  95. /**
  96. * @desc : 计算金额/过滤出已选数据
  97. * @date : 2024/2/1 15:49
  98. * @author : 于继渤
  99. */
  100. calculateTotal() {
  101. let tableData = this.data.tableData
  102. let contentSaveList = this.data.contentSaveList
  103. let choooseInboundItemList = []
  104. let returnTotalAmount = Number(0)
  105. //过滤出已选数据
  106. tableData.forEach(res => {
  107. if (res.inboundItemList && res.inboundItemList.length > 0) {
  108. res.inboundItemList.forEach(item => {
  109. if (item.checked) {
  110. item.itemQty = Number(item.rejectQty * -1)
  111. item.itemQtyMin = Number(item.rejectQty * -1)
  112. item.itemQtyMax = Number(-1)
  113. item.priceReturn = Number(item.priceInto * -1)
  114. item.itemAmt = Number(item.rejectQty * item.priceInto * -1)
  115. choooseInboundItemList.push(item)
  116. }
  117. })
  118. }
  119. })
  120. if (choooseInboundItemList && choooseInboundItemList.length > 0) {
  121. choooseInboundItemList.forEach(res => {
  122. returnTotalAmount += Number(res.rejectQty * res.priceInto)
  123. })
  124. }
  125. contentSaveList[2]['content'] = returnTotalAmount.toFixed(2)
  126. this.setData({
  127. returnTotalAmount:returnTotalAmount,
  128. choooseInboundItemList: choooseInboundItemList,
  129. contentSaveList: contentSaveList,
  130. })
  131. },
  132. /**
  133. * @desc : 跳转退货页
  134. * @date : 2024/2/1 15:49
  135. * @author : 于继渤
  136. */
  137. toAdd() {
  138. let choooseInboundItemList = this.data.choooseInboundItemList
  139. let that = this
  140. let formData = that.data.formData
  141. let item = that.data.item
  142. wx.navigateTo({
  143. url: this.data.route.addReturn.url,
  144. success: function (res) {
  145. // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的,实际中,需要从route中读取
  146. res.eventChannel.emit('params', {
  147. formMode:'add',
  148. choooseInboundItemList: choooseInboundItemList,
  149. beforeSumAmount: that.data.returnTotalAmount * -1,
  150. item: JSON.stringify(item)
  151. })
  152. }
  153. })
  154. },
  155. /**
  156. * 生命周期函数--监听页面加载
  157. */
  158. onLoad(options) {
  159. },
  160. })