select-source-purchase-order.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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', }],
  17. contentSaveList: [{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.intoStatus = Constants.intoStatus.inBounded
  35. params.fromId = this.data.id
  36. return params
  37. },
  38. /**
  39. * @desc : 父级商品信息选择
  40. * @date : 2024/2/1 15:49
  41. * @author : 于继渤
  42. */
  43. onListItemChange(e) {
  44. let tableData = this.data.tableData
  45. let index = e.currentTarget.dataset.index
  46. tableData.forEach(item=>{
  47. item.checked = false
  48. item.inboundItemList.forEach(it => {
  49. it.checked = false
  50. })
  51. })
  52. tableData[index].checked = e.detail
  53. let inboundItemList = tableData[index].inboundItemList
  54. if (inboundItemList && inboundItemList.length > 0) {
  55. inboundItemList.forEach(res => {
  56. res.checked = tableData[index].checked
  57. })
  58. }
  59. //商品不能跨入库单选择
  60. this.setData({
  61. tableData: tableData
  62. })
  63. this.calculateTotal()
  64. },
  65. /**
  66. * @desc : 子级商品信息选择
  67. * @date : 2024/2/1 15:49
  68. * @author : 于继渤
  69. */
  70. onChangeItemCheckbox(e) {
  71. let tableData = this.data.tableData
  72. let index = e.currentTarget.dataset.index
  73. let index_ = e.currentTarget.dataset.index_
  74. tableData.forEach(item=>{
  75. item.checked = false
  76. item.inboundItemList.forEach(it => {
  77. it.checked = false
  78. })
  79. })
  80. tableData[index].inboundItemList[index_].checked = e.detail
  81. this.setData({
  82. tableData: tableData
  83. })
  84. this.calculateTotal()
  85. },
  86. /**
  87. * @desc : 全退
  88. * @date : 2024/2/1 15:49
  89. * @author : 于继渤
  90. */
  91. onCheckboxChange(e) {
  92. let checked = e.detail.checked
  93. let tableData = this.data.tableData
  94. tableData.forEach(res => {
  95. res.checked = checked
  96. if (res.inboundItemList && res.inboundItemList.length > 0) {
  97. res.inboundItemList.forEach(item => {
  98. item.checked = checked
  99. })
  100. }
  101. })
  102. this.setData({
  103. tableData: tableData
  104. })
  105. this.calculateTotal()
  106. },
  107. /**
  108. * @desc : 计算金额/过滤出已选数据
  109. * @date : 2024/2/1 15:49
  110. * @author : 于继渤
  111. */
  112. calculateTotal() {
  113. let tableData = this.data.tableData
  114. let contentSaveList = this.data.contentSaveList
  115. let choooseInboundItemList = []
  116. let returnTotalAmount = Number(0)
  117. //过滤出已选数据
  118. tableData.forEach(res => {
  119. if (res.inboundItemList && res.inboundItemList.length > 0) {
  120. res.inboundItemList.forEach(item => {
  121. if (item.checked) {
  122. item.itemQty = Number(item.rejectQty * -1)
  123. item.itemQtyMin = Number(item.rejectQty * -1)
  124. item.itemQtyMax = Number(-1)
  125. item.priceReturn = Number(item.priceInto * -1)
  126. item.itemAmt = Number(item.rejectQty * item.priceInto * -1)
  127. choooseInboundItemList.push(item)
  128. }
  129. })
  130. }
  131. })
  132. if (choooseInboundItemList && choooseInboundItemList.length > 0) {
  133. choooseInboundItemList.forEach(res => {
  134. returnTotalAmount += Number(res.rejectQty * res.priceInto)
  135. })
  136. }
  137. contentSaveList[1]['content'] = returnTotalAmount.toFixed(2)
  138. this.setData({
  139. returnTotalAmount:returnTotalAmount,
  140. choooseInboundItemList: choooseInboundItemList,
  141. contentSaveList: contentSaveList,
  142. })
  143. },
  144. /**
  145. * @desc : 跳转退货页
  146. * @date : 2024/2/1 15:49
  147. * @author : 于继渤
  148. */
  149. toAdd() {
  150. let choooseInboundItemList = this.data.choooseInboundItemList
  151. let fromNo = []
  152. choooseInboundItemList.forEach(res=>{
  153. if(fromNo.indexOf(res.intoNo) == -1){
  154. fromNo.push(res.intoNo)
  155. }
  156. })
  157. let that = this
  158. let formData = that.data.formData
  159. let item = that.data.item
  160. item.fromNo = fromNo
  161. if(this.data.id){
  162. wx.navigateTo({
  163. url: this.data.route.addReturn.url,
  164. success: function (res) {
  165. // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的,实际中,需要从route中读取
  166. res.eventChannel.emit('params', {
  167. formMode:'add',
  168. choooseInboundItemList: choooseInboundItemList,
  169. beforeSumAmount: that.data.returnTotalAmount * -1,
  170. item: JSON.stringify(item)
  171. })
  172. }
  173. })
  174. }else{
  175. const eventChannel = this.getOpenerEventChannel();
  176. eventChannel.emit('bindData', {
  177. data:{itemList: choooseInboundItemList,
  178. beforeSumAmount: that.data.returnTotalAmount * -1}
  179. })
  180. wx.navigateBack({
  181. data: 1
  182. })
  183. }
  184. },
  185. /**
  186. * 生命周期函数--监听页面加载
  187. */
  188. loadInit() {
  189. this.setData({
  190. searchText: this.data.item.purNo
  191. })
  192. },
  193. })