index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. const util = require('../../utils/util')
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. currentTab: 0,
  9. bgColor: "linear-gradient(90deg, rgb(255, 118, 38), rgb(252, 30, 82))",
  10. navbar: [{
  11. name: "进库"
  12. }, {
  13. name: "出库"
  14. }],
  15. searchParams: {
  16. storeId:'',
  17. pageNo: 1,
  18. pageSize: 20,
  19. storeName: ''
  20. },
  21. params: {
  22. storeId:'',
  23. pageNo: 1,
  24. pageSize: 20,
  25. },
  26. storeList:[],
  27. orderList:[],
  28. loadding: false,
  29. pullUpOn: true,
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. this.bindStoreList()
  36. this.bindOrderist()
  37. },
  38. /**
  39. * 页面相关事件处理函数--监听用户下拉动作
  40. */
  41. onPullDownRefresh: function () {
  42. this.setData({
  43. ["searchParams.pageNo"]: 1,
  44. pullUpOn: true,
  45. loadding: false,
  46. orderList: []
  47. })
  48. this.bindOrderist()
  49. setTimeout(() => {
  50. wx.stopPullDownRefresh()
  51. }, 300);
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. //只是测试效果,逻辑以实际数据为准
  58. this.setData({
  59. loadding: true,
  60. pullUpOn: true
  61. })
  62. var that = this
  63. this.setData({
  64. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  65. })
  66. this.bindOrderist()
  67. },
  68. bindStorePickerChange: function (e) {
  69. var item = this.data.storeList[e.detail.value]
  70. console.log(item)
  71. this.setData({
  72. ['searchParams.storeId']: item.id,
  73. ['searchParams.storeName']: item.storeName,
  74. ["searchParams.pageNo"]: 1,
  75. orderList: []
  76. })
  77. this.bindOrderist()
  78. },
  79. changeTab(e) {
  80. console.log(e)
  81. this.setData({
  82. currentTab: e.detail.index,
  83. ["searchParams.pageNo"]: 1,
  84. pullUpOn: true,
  85. loadding: false,
  86. orderList: []
  87. })
  88. this.bindOrderist()
  89. },
  90. bindOrderist(){
  91. var that = this
  92. if(!that.data.searchParams.storeId){
  93. this.setData({
  94. orderList: []
  95. })
  96. return;
  97. }
  98. if(that.data.currentTab == 0){
  99. that.data.params.storeId = that.data.searchParams.storeId;
  100. that.data.params.pageNo = that.data.searchParams.pageNo;
  101. that.data.params.pageSize = that.data.searchParams.pageSize;
  102. // that.data.params = Object.assign( that.data.params, that.data.searchParams)
  103. console.log(that.data.params)
  104. util.request(util.api.productOrderDetailPage, that.data.params, "GET", false, false, app.globalData.token).then((res) => {
  105. if (res.code == 200) {
  106. console.log(res)
  107. if (res.result.records.length > 0) {
  108. if (that.data.orderList.length > 0) {
  109. let list = that.data.orderList
  110. res.result.records.forEach(element => {
  111. var item = {}
  112. item.orderSn = element.orderSn
  113. item.productName = element.productName
  114. item.productNum = element.productQuantity
  115. list.push(item)
  116. });
  117. that.setData({
  118. orderList: list
  119. })
  120. } else {
  121. let list = []
  122. res.result.records.forEach(element => {
  123. var item = {}
  124. item.orderSn = element.orderSn
  125. item.productName = element.productName
  126. item.productNum = element.productQuantity
  127. list.push(item)
  128. });
  129. that.setData({
  130. orderList: list
  131. })
  132. }
  133. } else {
  134. that.setData({
  135. loadding: false,
  136. pullUpOn: false,
  137. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  138. })
  139. }
  140. }
  141. }).catch((res) => {})
  142. }else{
  143. util.request(util.api.orderListPage, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => {
  144. if (res.code == 200) {
  145. if (res.result.records.length > 0) {
  146. if (that.data.orderList.length > 0) {
  147. let list = that.data.orderList
  148. res.result.records.forEach(element => {
  149. var item = {}
  150. item.orderSn = element.orderSn
  151. item.productName = element.productName
  152. item.productNum = 1
  153. list.push(item)
  154. });
  155. that.setData({
  156. orderList: list
  157. })
  158. } else {
  159. let list = []
  160. res.result.records.forEach(element => {
  161. var item = {}
  162. item.orderSn = element.orderSn
  163. item.productName = element.productName
  164. item.productNum = 1
  165. list.push(item)
  166. });
  167. that.setData({
  168. orderList: list
  169. })
  170. }
  171. } else {
  172. that.setData({
  173. loadding: false,
  174. pullUpOn: false,
  175. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  176. })
  177. }
  178. }
  179. }).catch((res) => {})
  180. }
  181. },
  182. bindStoreList() {
  183. var that = this
  184. util.request(util.api.storeList, {}, "GET", false, true,app.globalData.token).then((res) => {
  185. if (res.code == 200) {
  186. that.setData({
  187. storeList: res.result
  188. })
  189. }
  190. }).catch((res) => {})
  191. },
  192. })