form.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 { getChecklistHazardRecordById,updateChecklistHazardRecordDoing} from '@/api/aqpt/checklistHazardRecordApi'
  30. import { getChecklistHazardRecordView } from '@/api/aqpt/checklistRecordHazardApi'
  31. import {completeCheckTask} from '@/api/aqpt/task.js'
  32. export default {
  33. data() {
  34. return {
  35. checkResults:[
  36. {text:"通过",value:1},
  37. {text:"不通过",value:-1},
  38. ],
  39. formData:{
  40. checkResult:1,
  41. remark:"",
  42. attachList:[]
  43. },
  44. rules:{},
  45. measure:{},
  46. handles:[],
  47. itemList:[]
  48. }
  49. },
  50. created() {
  51. this.init()
  52. },
  53. methods: {
  54. init(){
  55. let measure=uni.getStorageSync('measure');
  56. this.measure=measure;
  57. this.getLocation()
  58. this.getchecklist()
  59. },
  60. getchecklist(){
  61. getChecklistHazardRecordView(this.measure.recordId).then((res)=>{
  62. let itemList=res.data.hazardList
  63. let measures=[]
  64. for(let i=0;i<itemList.length;i++){
  65. if(itemList[i].riskList){
  66. itemList[i].riskList.map(child=>{
  67. child.recordList.map(measure=>{
  68. measures.push(measure)
  69. })
  70. })
  71. }
  72. }
  73. let index=measures.findIndex(item=>item.measureId===this.measure.measureId)
  74. if(index>0){
  75. let temp=measures[0];
  76. measures[0]=JSON.parse(JSON.stringify(this.measure))
  77. measures[index]=temp
  78. }
  79. this.itemList=measures
  80. this.handles=measures
  81. })
  82. },
  83. getLocation(){
  84. const self=this;
  85. uni.getLocation({
  86. type: 'wgs84',
  87. success: function (res) {
  88. self.formData.dutyLongitude=res.longitude
  89. self.formData.dutyLatitude=res.latitude
  90. }
  91. });
  92. },
  93. async onSubmit() {
  94. let measure=uni.getStorageSync('measure')
  95. let attachList=[]
  96. for(let i=0;i<this.formData.attachList.length;i++){
  97. let filePath=this.formData.attachList[i].url
  98. let fileresq=await upload({filePath,formData:{
  99. additions: `经度:${this.formData.dutyLongitude};纬度:${this.formData.dutyLatitude}`
  100. }}).catch(()=>{
  101. uni.showToast({
  102. icon:'none',
  103. title:"提交失败!"
  104. })
  105. })
  106. if(fileresq.includes('html')){
  107. uni.showToast({
  108. icon:'none',
  109. title:"图片上传异常"
  110. })
  111. return
  112. }
  113. fileresq=JSON.parse(fileresq)
  114. attachList.push(fileresq.data)
  115. }
  116. await updateChecklistHazardRecordDoing({
  117. recordId:measure.recordId,
  118. checklistId:measure.checklistId,
  119. riskId:measure.riskId,
  120. hazardId:measure.hazardId,
  121. measureId:measure.measureId,
  122. checkResult:this.formData.checkResult,
  123. remark:this.formData.remark,
  124. attachList,
  125. }).catch(()=>{
  126. uni.showToast({
  127. icon:'none',
  128. title:"提交失败!"
  129. })
  130. })
  131. let idx=this.itemList.findIndex(item=>item.measureId==measure.measureId)
  132. this.itemList[idx].checkResult=this.formData.checkResult
  133. this.batchHandle()
  134. },
  135. // 批量处理未处理的
  136. batchHandle(){
  137. let measure=uni.getStorageSync('measure')
  138. let handles=JSON.parse(JSON.stringify(this.handles))
  139. handles.shift()
  140. this.handles=handles
  141. if(handles.length<1){
  142. const key=this.itemList.find(item=>item.checkResult===-1)
  143. if(!key){
  144. completeCheckTask(measure.recordId).then(()=>{
  145. uni.showToast({
  146. icon:'none',
  147. title:"处理完毕",
  148. duration:1000,
  149. complete() {
  150. uni.reLaunch({
  151. url:`/pages/index/detail/detail?type=task&name=待办任务`
  152. })
  153. }
  154. })
  155. })
  156. .catch(()=>{
  157. uni.showToast({
  158. icon:"none",
  159. title:"操作失败"
  160. })
  161. })
  162. }else{
  163. let cid=measure.checklistId;
  164. let rid=measure.recordId;
  165. uni.showToast({
  166. icon:'none',
  167. title:"处理完毕",
  168. duration:1000,
  169. complete() {
  170. uni.reLaunch({
  171. url:`/pages/index/handle/task/hazardRecord/hazardRecord?rid=${rid}&cid=${cid}&title=${measure.hazardTitle}`
  172. })
  173. }
  174. })
  175. }
  176. return
  177. }
  178. this.formData={
  179. checkResult:1,
  180. remark:"",
  181. attachList:[]
  182. }
  183. uni.setStorageSync('measure',handles[0]);
  184. this.measure=handles[0];
  185. },
  186. uploadSuccess(e){
  187. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  188. attachList.push(e.tempFiles[0])
  189. this.formData.attachList=attachList
  190. },
  191. deleteFile(e){
  192. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  193. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  194. this.formData.attachList=attachList
  195. },
  196. },
  197. onUnload() {
  198. uni.removeStorageSync('point')
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .wrap{
  204. padding: 20rpx;
  205. padding-bottom: 200rpx;
  206. .submit-BT {
  207. width: 750rpx;
  208. color: #4D73FF;
  209. text-align: center;
  210. font-size: 32rpx;
  211. padding-bottom: 68rpx;
  212. background-color: #fff;
  213. position: fixed;
  214. left: 0;
  215. bottom: 0;
  216. z-index: 99;
  217. box-shadow: 0px 0px 12px 0px #0000000A;
  218. border-radius: 8px 8px 0px 0px
  219. }
  220. ::v-deep .uni-forms-item{
  221. .uni-forms-item__content{
  222. .uni-data-checkbox-wrap{
  223. height: 100%;
  224. display: flex;
  225. align-items: center;
  226. }
  227. }
  228. }
  229. }
  230. </style>