form.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. console.log({
  144. "this.itemList":this.itemList,
  145. key
  146. })
  147. if(!key){
  148. completeCheckTask(measure.recordId).then(()=>{
  149. uni.showToast({
  150. icon:'none',
  151. title:"处理完毕",
  152. duration:1000,
  153. complete() {
  154. uni.redirectTo({
  155. url:`/pages/index/detail/detail?type=task&name=待办任务`
  156. })
  157. }
  158. })
  159. }).catch(()=>{
  160. uni.showToast({
  161. icon:"none",
  162. title:"操作失败"
  163. })
  164. })
  165. }else{
  166. let cid=measure.checklistId;
  167. let rid=measure.recordId;
  168. uni.showToast({
  169. icon:'none',
  170. title:"处理完毕",
  171. duration:1000,
  172. complete() {
  173. uni.redirectTo({
  174. url:`/pages/index/handle/task/hazardRecord/hazardRecord?rid=${rid}&cid=${cid}&title=${measure.hazardTitle}`
  175. })
  176. }
  177. })
  178. }
  179. return
  180. }
  181. this.formData={
  182. checkResult:1,
  183. remark:"",
  184. attachList:[]
  185. }
  186. uni.setStorageSync('measure',handles[0]);
  187. this.measure=handles[0];
  188. },
  189. uploadSuccess(e){
  190. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  191. attachList.push(e.tempFiles[0])
  192. this.formData.attachList=attachList
  193. },
  194. deleteFile(e){
  195. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  196. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  197. this.formData.attachList=attachList
  198. },
  199. },
  200. onUnload() {
  201. uni.removeStorageSync('point')
  202. }
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .wrap{
  207. padding: 20rpx;
  208. padding-bottom: 200rpx;
  209. .submit-BT {
  210. width: 750rpx;
  211. color: #4D73FF;
  212. text-align: center;
  213. font-size: 32rpx;
  214. padding-bottom: 68rpx;
  215. background-color: #fff;
  216. position: fixed;
  217. left: 0;
  218. bottom: 0;
  219. z-index: 99;
  220. box-shadow: 0px 0px 12px 0px #0000000A;
  221. border-radius: 8px 8px 0px 0px
  222. }
  223. ::v-deep .uni-forms-item{
  224. .uni-forms-item__content{
  225. .uni-data-checkbox-wrap{
  226. height: 100%;
  227. display: flex;
  228. align-items: center;
  229. }
  230. }
  231. }
  232. }
  233. </style>