photoInspection.vue 9.2 KB

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