photoInspection.vue 9.1 KB

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