list.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import * as requestAPI from '../../models/dataModel'
  2. Page({
  3. data: {
  4. qcList: [],
  5. sscCode: '',
  6. pCode: '',
  7. current: 1,
  8. size: 5,
  9. total: 0,
  10. selectQCList: []
  11. },
  12. onLoad: function (options) {
  13. this.setData({
  14. pCode: options?options.pCode:this.data.pCode,
  15. sscCode: options?options.sscCode:this.data.sscCode
  16. })
  17. },
  18. onReady() {
  19. this.getQcList()
  20. },
  21. onUnload() {
  22. if(this.getRecordSelectList().length>0) {
  23. wx.setStorageSync('selectQcList', JSON.stringify(this.getRecordSelectList()))
  24. }
  25. },
  26. // 获取样品单列表
  27. getQcList() {
  28. wx.showLoading({title: '加载中', icon: 'loading'});
  29. let form = {
  30. current: this.data.current,
  31. size: this.data.size,
  32. sscCode: this.data.sscCode,
  33. pCode: this.data.pCode
  34. }
  35. requestAPI.getQcList(form).then(res => {
  36. for (let i =0; i<res.data.data.records.length;i++) {
  37. if(wx.getStorageSync('selectQcList')&&JSON.parse(wx.getStorageSync('selectQcList')).length!==0){
  38. let selectList = JSON.parse(wx.getStorageSync('selectQcList'))
  39. let filterList = selectList.filter(item=>{return item.pid == res.data.data.records[i].pid&&item.sscId== res.data.data.records[i].sscId})
  40. if(filterList.length !== 0) {
  41. res.data.data.records.splice(i, 1)
  42. break
  43. // 搜索全部list有则在全部list里删除
  44. }
  45. }
  46. res.data.data.records[i].checked = false
  47. res.data.data.records[i].productImgUrl = res.data.data.records[i].pictures[0].bigPicture
  48. }
  49. // 合并已选择的list和全部list
  50. if(wx.getStorageSync('selectQcList')&&JSON.parse(wx.getStorageSync('selectQcList')).length!==0){
  51. res.data.data.records = JSON.parse(wx.getStorageSync('selectQcList')).concat(res.data.data.records)
  52. }
  53. this.setData({
  54. qcList: res.data.data.records,
  55. total: res.data.data.total
  56. })
  57. })
  58. },
  59. // 获取样品单详情
  60. getDetail: function (event) {
  61. wx.navigateTo({
  62. url: `/pages/qc/detail?sscId=${event.currentTarget.dataset.sscid}&pId=${event.currentTarget.dataset.pid}`,
  63. })
  64. },
  65. selectList:function(e) {
  66. let tempList = this.data.qcList
  67. tempList[e.currentTarget.dataset.index].checked = !tempList[e.currentTarget.dataset.index].checked
  68. this.setData({
  69. qcList: tempList
  70. })
  71. },
  72. // 记录已选择的列
  73. getRecordSelectList() {
  74. let tempList = []
  75. for(let i of this.data.qcList) {
  76. if(i.checked) {
  77. tempList.push(i)
  78. }
  79. }
  80. return tempList
  81. },
  82. // 下拉刷新
  83. onPullDownRefresh: function () {
  84. wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
  85. this.onLoad(); //刷新页面
  86. setTimeout(function () {
  87. wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
  88. wx.stopPullDownRefresh(); //停止下拉动作
  89. }, 2000)
  90. },
  91. // 下拉加载
  92. onReachBottom: function () {
  93. if (this.data.size > this.data.total) {
  94. return;
  95. } else {
  96. this.getQcList();
  97. this.setData({
  98. size: this.data.size+10
  99. })
  100. }
  101. },
  102. openPreview: function (event) {
  103. wx.previewImage({
  104. urls: new Array(event.currentTarget.dataset.url),
  105. })
  106. },
  107. // 生成QC验货初检报告
  108. generate() {
  109. let tempList = []
  110. for(let i of this.data.qcList) {
  111. if(i.checked) {
  112. tempList.push(i)
  113. }
  114. }
  115. requestAPI.generateQcReport(tempList).then(res=>{
  116. wx.showToast({
  117. title: `生成报告${res.data.data}`,
  118. icon: 'success',
  119. duration: 30000
  120. })
  121. wx.removeStorageSync('selectQcList')
  122. setTimeout(() => {
  123. this.getQcList()
  124. }, 500);
  125. })
  126. }
  127. })