select-source-purchase-order.js 5.5 KB

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