photoInspection.vue 8.2 KB

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