detail.js 4.1 KB

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