photoInspection.vue 11 KB

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