detail.js 3.7 KB

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