index.js 7.7 KB

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