list.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import * as requestAPI from '../../models/dataModel'
  2. Page({
  3. data: {
  4. sampleList: [],
  5. sdDocument: '',
  6. pCode: '',
  7. current: 1,
  8. size: 5,
  9. total: 0
  10. },
  11. onLoad: function (options) {
  12. this.setData({
  13. pCode: options?options.pCode:this.data.pCode,
  14. sdDocument: options?options.sdDocument:this.data.sdDocument
  15. })
  16. this.getSampleList()
  17. },
  18. // 获取样品单列表
  19. getSampleList() {
  20. wx.showLoading({title: '加载中', icon: 'loading'});
  21. let form = {
  22. current: this.data.current,
  23. size: this.data.size,
  24. sdDocument: this.data.sdDocument,
  25. pCode: this.data.pCode
  26. }
  27. requestAPI.getSampleList(form).then(res => {
  28. for (let i of res.data.data.records) {
  29. i.productImgUrl = i.pictures[0].bigPicture
  30. }
  31. this.setData({
  32. sampleList: res.data.data.records,
  33. total: res.data.data.total
  34. })
  35. })
  36. },
  37. // 获取样品单详情
  38. getDetail: function (event) {
  39. wx.navigateTo({
  40. url: `/pages/sample/detail?sdpId=${event.currentTarget.dataset.id}`,
  41. })
  42. },
  43. // 下拉刷新
  44. onPullDownRefresh: function () {
  45. wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
  46. this.onLoad(); //刷新页面
  47. setTimeout(function () {
  48. wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
  49. wx.stopPullDownRefresh(); //停止下拉动作
  50. }, 2000)
  51. },
  52. // 下拉加载
  53. onReachBottom: function () {
  54. if (this.data.size > this.data.total) {
  55. return;
  56. } else {
  57. this.getSampleList();
  58. this.setData({
  59. size: this.data.size+10
  60. })
  61. }
  62. },
  63. openPreview: function (event) {
  64. wx.previewImage({
  65. urls: new Array(event.currentTarget.dataset.url),
  66. })
  67. }
  68. })