form.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="wrap">
  3. <uni-section :title="measure.hazardTitle" type="line">
  4. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="300" label-position="top">
  5. <uni-forms-item label="检查内容" required>
  6. {{measure.measureContent}}
  7. </uni-forms-item>
  8. <uni-forms-item label="检查结果" name="checkResult" required>
  9. <view class="uni-data-checkbox-wrap">
  10. <uni-data-checkbox v-model="formData.checkResult" :localdata="checkResults" />
  11. </view>
  12. </uni-forms-item>
  13. <uni-forms-item label="备注" name="remark">
  14. <uni-easyinput v-model="formData.remark" type="textarea" :maxlength="-1" autoHeight placeholder="备注" />
  15. </uni-forms-item>
  16. <uni-file-picker v-model="formData.attachList"
  17. fileMediatype="image"
  18. title="请上传附件"
  19. limit="1"
  20. @select="uploadSuccess"
  21. @delete="deleteFile"></uni-file-picker>
  22. </uni-forms>
  23. </uni-section>
  24. <button type="primary" @click="onSubmit" class="submit-BT">提交</button>
  25. </view>
  26. </template>
  27. <script>
  28. import {upload} from '@/api/system/upload.js'
  29. import {
  30. getChecklistHazardRecordById,
  31. updateChecklistHazardRecordDoing ,
  32. } from '@/api/aqpt/checklistHazardRecordApi'
  33. import { getChecklistHazardRecordView } from '@/api/aqpt/checklistRecordHazardApi'
  34. export default {
  35. data() {
  36. return {
  37. checkResults:[
  38. {text:"通过",value:1},
  39. {text:"不通过",value:-1},
  40. ],
  41. formData:{
  42. checkResult:1,
  43. remark:"",
  44. attachList:[]
  45. },
  46. rules:{},
  47. measure:{},
  48. handles:[],
  49. itemList:[]
  50. }
  51. },
  52. created() {
  53. this.init()
  54. },
  55. methods: {
  56. init(){
  57. let measure=uni.getStorageSync('measure');
  58. this.measure=measure;
  59. this.getLocation()
  60. this.getchecklist()
  61. },
  62. getchecklist(){
  63. getChecklistHazardRecordView(this.measure.recordId).then((res)=>{
  64. let itemList=res.data.hazardList
  65. let measures=[]
  66. for(let i=0;i<itemList.length;i++){
  67. if(itemList[i].riskList){
  68. itemList[i].riskList.map(child=>{
  69. child.recordList.map(measure=>{
  70. measures.push(measure)
  71. })
  72. })
  73. }
  74. }
  75. let index=measures.findIndex(item=>item.measureId===this.measure.measureId)
  76. if(index>0){
  77. let temp=measures[0];
  78. measures[0]=JSON.parse(JSON.stringify(this.measure))
  79. measures[index]=temp
  80. }
  81. this.handles=measures
  82. })
  83. },
  84. getLocation(){
  85. const self=this;
  86. uni.getLocation({
  87. type: 'wgs84',
  88. success: function (res) {
  89. self.formData.dutyLongitude=res.longitude
  90. self.formData.dutyLatitude=res.latitude
  91. }
  92. });
  93. },
  94. async onSubmit() {
  95. let measure=uni.getStorageSync('measure')
  96. let attachList=[]
  97. for(let i=0;i<this.formData.attachList.length;i++){
  98. let filePath=this.formData.attachList[i].url
  99. let fileresq=await upload({filePath,formData:{
  100. additions: `经度:${this.formData.dutyLongitude};纬度:${this.formData.dutyLatitude}`
  101. }}).catch(()=>{
  102. uni.showToast({
  103. icon:'none',
  104. title:"提交失败!"
  105. })
  106. })
  107. if(fileresq.includes('html')){
  108. uni.showToast({
  109. icon:'none',
  110. title:"图片上传异常"
  111. })
  112. return
  113. }
  114. fileresq=JSON.parse(fileresq)
  115. attachList.push(fileresq.data)
  116. }
  117. await updateChecklistHazardRecordDoing({
  118. recordId:measure.recordId,
  119. checklistId:measure.checklistId,
  120. riskId:measure.riskId,
  121. hazardId:measure.hazardId,
  122. measureId:measure.measureId,
  123. checkResult:this.formData.checkResult,
  124. remark:this.formData.remark,
  125. attachList,
  126. }).catch(()=>{
  127. uni.showToast({
  128. icon:'none',
  129. title:"提交失败!"
  130. })
  131. })
  132. this.batchHandle()
  133. },
  134. // 批量处理未处理的
  135. batchHandle(){
  136. let measure=uni.getStorageSync('measure')
  137. let handles=JSON.parse(JSON.stringify(this.handles))
  138. handles.shift()
  139. this.handles=handles
  140. if(handles.length<1){
  141. uni.showToast({
  142. icon:'none',
  143. title:"处理完毕",
  144. duration:1000,
  145. complete() {
  146. uni.redirectTo({
  147. url:`/pages/index/detail/detail?type=task&name=待办任务`
  148. })
  149. }
  150. })
  151. return
  152. }
  153. this.formData={
  154. checkResult:1,
  155. remark:"",
  156. attachList:[]
  157. }
  158. uni.setStorageSync('measure',handles[0]);
  159. this.measure=handles[0];
  160. },
  161. // 批量处理未处理的【按顺序走到最后一个】
  162. goOnNext(){
  163. let point=uni.getStorageSync('point')
  164. let pointIdex=this.itemList.findIndex(item=>point.pointId===item.pointId)
  165. let handles=this.itemList.slice(pointIdex+1);
  166. let nextPointIdx=handles.findIndex(item=>(!item.checkResult))
  167. nextPointIdx=nextPointIdx+pointIdex
  168. if(handles.length<1||nextPointIdx<0){
  169. uni.showToast({
  170. icon:'none',
  171. title:"处理完毕",
  172. duration:1000,
  173. complete() {
  174. uni.redirectTo({
  175. url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  176. })
  177. }
  178. })
  179. return
  180. }
  181. this.formData={
  182. checkResult:1,
  183. remark:"",
  184. attachList:[]
  185. }
  186. let nextPoint=this.itemList[nextPointIdx+1]
  187. uni.setStorageSync('measure',nextPoint);//防止测试刷新数据丢失
  188. this.measure=nextPoint;
  189. },
  190. uploadSuccess(e){
  191. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  192. attachList.push(e.tempFiles[0])
  193. this.formData.attachList=attachList
  194. },
  195. deleteFile(e){
  196. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  197. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  198. this.formData.attachList=attachList
  199. },
  200. },
  201. onUnload() {
  202. uni.removeStorageSync('point')
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .wrap{
  208. padding: 20rpx;
  209. padding-bottom: 200rpx;
  210. .submit-BT {
  211. width: 750rpx;
  212. color: #4D73FF;
  213. text-align: center;
  214. font-size: 32rpx;
  215. padding-bottom: 68rpx;
  216. background-color: #fff;
  217. position: fixed;
  218. left: 0;
  219. bottom: 0;
  220. z-index: 99;
  221. box-shadow: 0px 0px 12px 0px #0000000A;
  222. border-radius: 8px 8px 0px 0px
  223. }
  224. ::v-deep .uni-forms-item{
  225. .uni-forms-item__content{
  226. .uni-data-checkbox-wrap{
  227. height: 100%;
  228. display: flex;
  229. align-items: center;
  230. }
  231. }
  232. }
  233. }
  234. </style>