detail.js 3.8 KB

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