detail.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import * as requestAPI from '../../models/dataModel'
  2. import baseURL from '../../api/baseUrlConfig.js'
  3. Page({
  4. data: {
  5. // qcDetail: {},
  6. // mark: '',
  7. // tempMark: '',
  8. scCode: '',
  9. scpCode: '',
  10. poCode: '',
  11. picture: '',
  12. ids: '',
  13. imageList: [],
  14. showAllPic: false,
  15. showDeleteBtn: true,
  16. allImgList: []
  17. },
  18. onLoad: function (options) {
  19. this.setData({
  20. ids: options.ids,
  21. picture: options.picture,
  22. poCode: options.poCode,
  23. scCode: options.scCode,
  24. scpCode: options.scpCode
  25. })
  26. this.getImages()
  27. },
  28. // 获取图片
  29. getImages() {
  30. let allImgList = [] // 全部图片
  31. let lessImgList = [] // 部分图片
  32. if(this.data.picture) {
  33. allImgList = this.data.picture.split(',')
  34. for(let i = 0;i<this.data.picture.split(',').length&&i<2;i++) {
  35. lessImgList.push(this.data.picture.split(',')[i])
  36. }
  37. this.setData({
  38. allImgList: allImgList
  39. })
  40. this.setData({
  41. imageList: this.data.showAllPic?allImgList:lessImgList
  42. })
  43. }
  44. },
  45. getAllImg() {
  46. this.setData({
  47. showAllPic: true
  48. })
  49. this.getImages()
  50. },
  51. showDeleteBtn() {
  52. this.setData({
  53. showDeleteBtn: !this.data.showDeleteBtn
  54. })
  55. },
  56. // 拍照
  57. takePhoto() {
  58. this.getPhotos(1, 'camera')
  59. },
  60. choosePhoto() {
  61. this.getPhotos(9, 'album')
  62. },
  63. getPhotos(count, type) {
  64. let _this = this
  65. wx.chooseImage({
  66. count: count,
  67. sizeType: ['original', 'compressed'],
  68. sourceType: [type],
  69. success(res) {
  70. let that=_this
  71. for (let i of res.tempFilePaths) {
  72. wx.uploadFile({
  73. url: baseURL.mainUrl + `/inventory/isnspection/mobile/picture?ids=${_this.data.ids}`, //此处换上你的接口地址
  74. filePath: i,
  75. name: 'file',
  76. header: {
  77. "Content-Type": "multipart/form-data",
  78. 'Authorization': `Bearer ${wx.getStorageSync('token')}`,
  79. },
  80. success: function (res) {
  81. var jsonObj = JSON.parse(res.data);
  82. that.setData({
  83. picture: jsonObj.data
  84. })
  85. wx.showToast({
  86. title: '上传成功',
  87. icon: 'success',
  88. duration: 2000
  89. })
  90. _this.getImages()
  91. }
  92. })
  93. }
  94. }
  95. })
  96. },
  97. // 删除qa图片
  98. delImg: function (event) {
  99. // requestAPI.delQcPic(this.data.sscId, this.data.pId, event.currentTarget.dataset.url).then(res=>{
  100. // this.getImages()
  101. // })
  102. },
  103. // 图片预览
  104. openPreview: function (event) {
  105. wx.previewImage({
  106. urls: this.data.imageList,
  107. current: event.currentTarget.dataset.current
  108. })
  109. }
  110. })