index.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.currentTab == 0) {
  93. // that.data.params.storeId = that.data.searchParams.storeId;
  94. that.data.params.pageNo = that.data.searchParams.pageNo;
  95. that.data.params.pageSize = that.data.searchParams.pageSize;
  96. that.data.params.orderSn = that.data.searchParams.orderSn ? that.data.searchParams.orderSn : "";
  97. // that.data.params = Object.assign( that.data.params, that.data.searchParams)
  98. console.log(that.data.params)
  99. util.request(util.api.productOrderDetailPage, that.data.params, "GET", false, false, app.globalData.token).then((res) => {
  100. if (res.code == 200) {
  101. console.log(res)
  102. if (res.result.records.length > 0) {
  103. if (this.data.searchParams.pageNo > 1) {
  104. let list = that.data.orderList
  105. res.result.records.forEach(element => {
  106. var item = {}
  107. item.orderSn = element.orderSn
  108. item.productName = element.productName
  109. item.productNum = element.productQuantity
  110. list.push(item)
  111. });
  112. that.setData({
  113. orderList: list
  114. })
  115. } else {
  116. let list = []
  117. res.result.records.forEach(element => {
  118. var item = {}
  119. item.orderSn = element.orderSn
  120. item.productName = element.productName
  121. item.productNum = element.productQuantity
  122. list.push(item)
  123. });
  124. that.setData({
  125. orderList: list
  126. })
  127. }
  128. } else {
  129. that.setData({
  130. loadding: false,
  131. pullUpOn: false,
  132. ["searchParams.pageNo"]: that.data.searchParams.pageNo - 1,
  133. orderList: []
  134. })
  135. }
  136. }
  137. }).catch((res) => {})
  138. } else {
  139. if (!that.data.searchParams.storeId) {
  140. this.setData({
  141. orderList: []
  142. })
  143. return;
  144. }
  145. util.request(util.api.orderListPage, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => {
  146. if (res.code == 200) {
  147. if (res.result.records.length > 0) {
  148. if (this.data.searchParams.pageNo > 1) {
  149. let list = that.data.orderList
  150. res.result.records.forEach(element => {
  151. var item = {}
  152. item.orderSn = element.orderSn
  153. item.productName = element.productName
  154. item.productNum = 1
  155. list.push(item)
  156. });
  157. that.setData({
  158. orderList: list
  159. })
  160. } else {
  161. let list = []
  162. res.result.records.forEach(element => {
  163. var item = {}
  164. item.orderSn = element.orderSn
  165. item.productName = element.productName
  166. item.productNum = 1
  167. list.push(item)
  168. });
  169. that.setData({
  170. orderList: list
  171. })
  172. }
  173. } else {
  174. that.setData({
  175. loadding: false,
  176. pullUpOn: false,
  177. ["searchParams.pageNo"]: that.data.searchParams.pageNo - 1,
  178. orderList: []
  179. })
  180. }
  181. }
  182. }).catch((res) => {})
  183. }
  184. },
  185. bindStoreList() {
  186. var that = this
  187. util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => {
  188. if (res.code == 200) {
  189. that.setData({
  190. storeList: res.result
  191. })
  192. }
  193. }).catch((res) => {})
  194. },
  195. serchOrderNo(e) {
  196. let _this = this;
  197. let dataset = e.currentTarget.dataset;
  198. let value = e.detail.value;
  199. let name = dataset.name;
  200. _this.data[name] = value;
  201. _this.setData({
  202. [name]: _this.data[name]
  203. });
  204. this.bindOrderist()
  205. }
  206. })