photoInspection.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <!-- 拍照检查 -->
  2. <template>
  3. <view id="photoInspection">
  4. <view class="photInspection-max">
  5. <view class="picker-max-box">
  6. <view class="picker-title-box">
  7. <view>*</view>
  8. <view>实验室:</view>
  9. </view>
  10. <picker @change="buttonChange"
  11. :range-key="'subjectName'" :value="subjectId" :range="buttonArray">
  12. <view class="picker-min-box">
  13. <view>{{buttonArrayIndex?buttonArray[buttonArrayIndex].subjectName:'请选择'}}</view>
  14. <img src="@/images/basicsModules/icon_06.png">
  15. </view>
  16. </picker>
  17. </view>
  18. <view class="photo-max-box">
  19. <view class="photo-button" v-if="!newData.subUrl" @click="upImg('subUrl')">+ 添加</view>
  20. <img :src="baseUrl+newData.subUrl" v-else @click="upImg('subUrl')">
  21. <view class="photo-title">{{newData.sub}}</view>
  22. </view>
  23. <view class="photo-max-box">
  24. <view class="photo-button" v-if="!newData.garbageUrl" @click="upImg('garbageUrl')">+ 添加</view>
  25. <img :src="baseUrl+newData.garbageUrl" v-else @click="upImg('garbageUrl')">
  26. <view class="photo-title">{{newData.garbage}}</view>
  27. </view>
  28. <view class="photo-max-box">
  29. <view class="photo-button" v-if="!newData.dangerousUrl" @click="upImg('dangerousUrl')">+ 添加</view>
  30. <img :src="baseUrl+newData.dangerousUrl" v-else @click="upImg('dangerousUrl')">
  31. <view class="photo-title">{{newData.dangerous}}</view>
  32. </view>
  33. <view class="photo-max-box">
  34. <view class="photo-button" v-if="!newData.sourceRiskUrl" @click="upImg('sourceRiskUrl')">+ 添加</view>
  35. <img :src="baseUrl+newData.sourceRiskUrl" v-else @click="upImg('sourceRiskUrl')">
  36. <view class="photo-title">{{newData.sourceRisk}}</view>
  37. </view>
  38. </view>
  39. <view class="up-data-button" @click="upButton">提交</view>
  40. <helang-compress ref="helangCompress"></helang-compress>
  41. </view>
  42. </template>
  43. <script>
  44. import helangCompress from './component/compress.vue';
  45. import { config } from '@/api/request/config.js'
  46. import { addPhotoInspection,outSubjectList } from '@/api/apiDemo/index.js'
  47. export default {
  48. components: {
  49. helangCompress
  50. },
  51. data() {
  52. return {
  53. baseUrl:config.base_url,
  54. newData:{},
  55. buttonArray:[],
  56. buttonArrayIndex:"",
  57. params: {
  58. maxSize: 400,
  59. fileType: 'png',
  60. quality: 0.85,
  61. minSize: 320
  62. }
  63. }
  64. },
  65. onLoad(option) {
  66. this.newData = JSON.parse(decodeURIComponent(option.newData));
  67. console.log(this.newData)
  68. },
  69. onShow(){
  70. this.outSubjectList();
  71. },
  72. methods: {
  73. buttonChange(e){
  74. console.log("e",e.mp.detail.value);
  75. this.buttonArrayIndex = e.mp.detail.value;
  76. },
  77. async outSubjectList(){
  78. const {data} = await outSubjectList();
  79. if(data.code == 200){
  80. this.buttonArray = data.data;
  81. }
  82. },
  83. upButton(){
  84. let self = this;
  85. if(!this.buttonArrayIndex){
  86. uni.showToast({
  87. title: '请选择实验室',
  88. icon:"none",
  89. mask:true,
  90. duration: 2000
  91. });
  92. return
  93. }
  94. if(!this.newData.subUrl){
  95. uni.showToast({
  96. title: '请上传实验室照片',
  97. icon:"none",
  98. mask:true,
  99. duration: 2000
  100. });
  101. return
  102. }
  103. if(!this.newData.garbageUrl){
  104. uni.showToast({
  105. title: '请上传垃圾桶清理后照片',
  106. icon:"none",
  107. mask:true,
  108. duration: 2000
  109. });
  110. return
  111. }
  112. uni.showModal({
  113. // title: '确认要退出吗?',
  114. content: '确认提交吗?',
  115. cancelColor:"#999",
  116. confirmColor:"#0183FA",
  117. success: function (res) {
  118. if (res.confirm) {
  119. self.addPhotoInspection();
  120. console.log('用户点击确定');
  121. } else if (res.cancel) {
  122. console.log('用户点击取消');
  123. }
  124. }
  125. });
  126. },
  127. //拍照检查提交
  128. async addPhotoInspection(){
  129. let obj = {
  130. subjectId:this.buttonArray[this.buttonArrayIndex].subjectId,
  131. subUrl:this.newData.subUrl,
  132. garbageUrl:this.newData.garbageUrl,
  133. dangerousUrl:this.newData.dangerousUrl,
  134. sourceRiskUrl:this.newData.sourceRiskUrl,
  135. }
  136. if(this.newData.id){
  137. obj.id = this.newData.id
  138. }
  139. const {data} = await addPhotoInspection(obj);
  140. if(data.code == 200){
  141. uni.showToast({
  142. title: '提交成功',
  143. icon:"none",
  144. mask:true,
  145. duration: 2000
  146. });
  147. setTimeout(function(){
  148. uni.navigateBack();
  149. },2000);
  150. }
  151. },
  152. upImg(name){
  153. let self = this;
  154. wx.chooseImage({
  155. count: 1,
  156. sizeType: ["original", "compressed"],
  157. sourceType: ["album", "camera"],
  158. success: function(res) {
  159. //let tempFilePaths = res.tempFilePaths[0];
  160. //self.uploadImg(tempFilePaths,name);
  161. self.compress(res.tempFilePaths,name);
  162. }
  163. });
  164. },
  165. //图片压缩
  166. compress(tempFilePaths,name) {
  167. let self = this;
  168. uni.showLoading({
  169. title: '压缩中',
  170. mask: true
  171. });
  172. this.$refs.helangCompress.compress({
  173. src: tempFilePaths[0],
  174. maxSize: this.params.maxSize,
  175. fileType: this.params.fileType,
  176. quality: this.params.quality,
  177. minSize: this.params.minSize
  178. }).then((res) => {
  179. uni.hideLoading();
  180. console.log('压缩成功')
  181. self.uploadImg(res,name);
  182. }).catch((err) => {
  183. uni.hideLoading();
  184. uni.showToast({
  185. title: "压缩失败,请重新上传",
  186. icon: "none"
  187. })
  188. })
  189. },
  190. async uploadImg(tempFilePaths,name){
  191. var self = this;
  192. uni.showLoading({
  193. title: '上传中',
  194. mask: true
  195. });
  196. uni.uploadFile({
  197. url: config.base_url+'/base/file/upload', //仅为示例,非真实的接口地址
  198. header:{'Authorization':uni.getStorageSync('token')},
  199. filePath: tempFilePaths,
  200. name: 'file',
  201. formData: {
  202. 'user': 'test'
  203. },
  204. success: (uploadFileRes) => {
  205. let res = JSON.parse(uploadFileRes.data);
  206. if(res.code == 200){
  207. self.$set(self.newData,name,res.data.url);
  208. self.$set(self.newData,"real"+name,res.data.url);
  209. }else{
  210. uni.showToast({
  211. title: res.msg,
  212. icon:"none",
  213. mask:true,
  214. duration: 2000
  215. });
  216. }
  217. },
  218. fail: err => {},
  219. complete: () => {
  220. uni.hideLoading()
  221. }
  222. });
  223. },
  224. }
  225. }
  226. </script>
  227. <style lang="stylus" scoped>
  228. #photoInspection{
  229. height:100%;
  230. width:100%;
  231. display:flex;
  232. flex-direction:column;
  233. .photInspection-max{
  234. flex:1;
  235. padding-bottom:40rpx;
  236. overflow-y:scroll;
  237. .photo-max-box{
  238. width:702rpx;
  239. height:422rpx;
  240. border-radius: 20rpx;
  241. background: #FFFFFF;
  242. border:4rpx dashed #E0E0E0;
  243. margin:20rpx 20rpx 0;
  244. .photo-button{
  245. height:336rpx;
  246. width:702rpx;
  247. color: #999999;
  248. font-size:30rpx;
  249. line-height 336rpx
  250. text-align center
  251. }
  252. img{
  253. height:336rpx;
  254. width:702rpx;
  255. border-top-left-radius :20rpx
  256. border-top-right-radius :20rpx
  257. }
  258. .photo-title{
  259. border-top:4rpx dashed #E0E0E0;
  260. line-height:82rpx;
  261. color: #333333;
  262. font-size: 30rpx;
  263. padding-left:28rpx;
  264. }
  265. }
  266. .null-view-box{
  267. text-align center;
  268. line-height:100rpx;
  269. color:#999;
  270. font-size:26rpx;
  271. }
  272. .picker-max-box{
  273. margin:20px 0;
  274. display:flex;
  275. .picker-title-box{
  276. padding:0 20rpx;
  277. display flex
  278. view{
  279. line-height:80rpx;
  280. font-size:28rpx;
  281. }
  282. view:nth-child(1){
  283. color:red;
  284. }
  285. view:nth-child(2){
  286. }
  287. view:nth-child(3){
  288. color:#999;
  289. }
  290. }
  291. .picker-min-box{
  292. display flex;
  293. height:80rpx;
  294. width:556rpx;
  295. border:1rpx solid #a2a2a2;
  296. border-radius:10rpx;
  297. margin:0 20rpx;
  298. view{
  299. flex:1;
  300. line-height:80rpx;
  301. padding:0 20rpx;
  302. color:#999;
  303. font-size:28rpx;
  304. overflow: hidden;
  305. text-overflow:ellipsis;
  306. white-space: nowrap;
  307. }
  308. img{
  309. width:24rpx;
  310. height:12rpx;
  311. margin:35rpx 23rpx;
  312. }
  313. }
  314. }
  315. }
  316. .up-data-button{
  317. width: 750rpx;
  318. height: 120rpx;
  319. background: #0183FA;
  320. line-height:120rpx;
  321. text-align center
  322. color:#fff;
  323. font-size: 30rpx;
  324. }
  325. }
  326. </style>