select-source-purchase-order.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.itemQtyMax = Number(item.rejectQty * -1)
  112. item.priceReturn = Number(item.priceInto * -1)
  113. item.itemAmt = Number(item.rejectQty * item.priceInto * -1)
  114. choooseInboundItemList.push(item)
  115. }
  116. })
  117. }
  118. })
  119. if (choooseInboundItemList && choooseInboundItemList.length > 0) {
  120. choooseInboundItemList.forEach(res => {
  121. returnTotalAmount += Number(res.rejectQty * res.priceInto)
  122. })
  123. }
  124. contentSaveList[2]['content'] = returnTotalAmount.toFixed(2)
  125. this.setData({
  126. choooseInboundItemList: choooseInboundItemList,
  127. contentSaveList: contentSaveList,
  128. })
  129. },
  130. /**
  131. * @desc : 跳转退货页
  132. * @date : 2024/2/1 15:49
  133. * @author : 于继渤
  134. */
  135. toAdd() {
  136. let choooseInboundItemList = this.data.choooseInboundItemList
  137. let that = this
  138. let formData = that.data.formData
  139. let item = that.data.item
  140. wx.navigateTo({
  141. url: this.data.route.addReturn.url,
  142. success: function (res) {
  143. // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的,实际中,需要从route中读取
  144. res.eventChannel.emit('params', {
  145. formMode:'add',
  146. choooseInboundItemList: choooseInboundItemList,
  147. goodsRejectedAmount: that.data.returnTotalAmount,
  148. item: JSON.stringify(item)
  149. })
  150. }
  151. })
  152. },
  153. /**
  154. * 生命周期函数--监听页面加载
  155. */
  156. onLoad(options) {
  157. },
  158. })