detail.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import * as requestAPI from '../../models/dataModel'
  2. Page({
  3. data: {
  4. sampleDetail: {},
  5. mark: '',
  6. tempMark: '',
  7. sdpId: '',
  8. imageList: [],
  9. showAllPic: false,
  10. allImgList: []
  11. },
  12. onLoad: function (options) {
  13. this.setData({
  14. sdpId: options.sdpId
  15. })
  16. this.getDetail(options.sdpId)
  17. this.getQaLog(options.sdpId)
  18. },
  19. // 获取样品单详情
  20. getDetail(sdpId) {
  21. requestAPI.getSampleDetail(sdpId).then(res => {
  22. this.setData({
  23. sampleDetail: res.data.data
  24. })
  25. })
  26. },
  27. // 获取qa日志
  28. getQaLog(sdpId) {
  29. requestAPI.getSampleQaLog(sdpId).then(res => {
  30. let allImgList = [] // 全部图片
  31. let lessImgList = [] // 部分图片
  32. if (res.data.data.length !== 0) {
  33. this.setData({
  34. mark: res.data.data[0].mark
  35. })
  36. allImgList = res.data.data[0].picture.split(',')
  37. for(let i = 0;i<res.data.data[0].picture.split(',').length&&i<2;i++) {
  38. lessImgList.push(res.data.data[0].picture.split(',')[i])
  39. }
  40. this.setData({
  41. allImgList: allImgList
  42. })
  43. this.setData({
  44. imageList: this.data.showAllPic?allImgList:lessImgList
  45. })
  46. }
  47. })
  48. },
  49. getAllImg() {
  50. this.setData({
  51. showAllPic: true
  52. })
  53. this.getQaLog(this.data.sdpId)
  54. },
  55. getTempMark(e) {
  56. this.setData({
  57. tempMark: e.detail.value
  58. })
  59. },
  60. // 保存或添加qa日志
  61. saveQaLog(e) {
  62. this.setData({
  63. mark: e.detail.value
  64. })
  65. if (this.data.mark !== this.data.tempMark) {
  66. if (this.data.tempMark) {
  67. requestAPI.changeSampleQaLog(this.data.sdpId, this.data.mark).then(res => {
  68. if (res.data.code === 0) {
  69. wx.showToast({
  70. title: '保存成功',
  71. icon: 'success',
  72. duration: 3000
  73. })
  74. setTimeout(() => {
  75. this.getQaLog(this.data.sdpId)
  76. }, 500)
  77. }
  78. })
  79. } else {
  80. requestAPI.addSampleQaLog(this.data.sdpId, this.data.mark).then(res => {
  81. if (res.data.code === 0) {
  82. wx.showToast({
  83. title: '保存成功',
  84. icon: 'success',
  85. duration: 3000
  86. })
  87. setTimeout(() => {
  88. this.getQaLog(this.data.sdpId)
  89. }, 500)
  90. }
  91. })
  92. }
  93. }
  94. },
  95. // 拍照
  96. takePhoto() {
  97. this.getPhotos(1, 'camera')
  98. },
  99. choosePhoto() {
  100. this.getPhotos(9, 'albumn')
  101. },
  102. getPhotos(count, type) {
  103. let _this = this
  104. wx.chooseImage({
  105. count: count,
  106. sizeType: ['original', 'compressed'],
  107. sourceType: [type],
  108. success(res) {
  109. for (let i of res.tempFilePaths) {
  110. wx.uploadFile({
  111. url: `http://192.168.20.52:9999/inventory/sample/qalog/upload/picture?sdpId=${_this.data.sdpId}`, //此处换上你的接口地址
  112. filePath: i,
  113. name: 'file',
  114. header: {
  115. "Content-Type": "multipart/form-data",
  116. 'Authorization': `Bearer ${wx.getStorageSync('token')}`,
  117. },
  118. success: function (res) {
  119. wx.showToast({
  120. title: '上传成功',
  121. icon: 'success',
  122. duration: 2000
  123. })
  124. _this.getQaLog(_this.data.sdpId)
  125. }
  126. })
  127. }
  128. }
  129. })
  130. },
  131. // 删除qa图片
  132. delImg: function (event) {
  133. requestAPI.delSamplePic(this.data.sdpId,event.currentTarget.dataset.url).then(res=>{
  134. this.getQaLog(this.data.sdpId)
  135. })
  136. },
  137. openPreview: function (event) {
  138. wx.previewImage({
  139. urls: this.data.imageList,
  140. current: event.currentTarget.dataset.current
  141. })
  142. }
  143. })