form.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="wrap">
  3. <uni-section :title="hazard.measureContent" type="line">
  4. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="300" label-position="top">
  5. <uni-forms-item label="检查结果" name="checkResult" required>
  6. <view class="uni-data-checkbox-wrap">
  7. <uni-data-checkbox v-model="formData.checkResult" :localdata="checkResults" />
  8. </view>
  9. </uni-forms-item>
  10. <uni-forms-item label="备注" name="remark">
  11. <uni-easyinput v-model="formData.remark" type="textarea" :maxlength="-1" autoHeight placeholder="备注" />
  12. </uni-forms-item>
  13. <uni-file-picker v-model="formData.attachList"
  14. fileMediatype="image"
  15. title="请上传附件"
  16. limit="1"
  17. @select="uploadSuccess"
  18. @delete="deleteFile"></uni-file-picker>
  19. </uni-forms>
  20. </uni-section>
  21. <view v-if="handles.length>0" class="tip">还剩<text class="word">{{handles.length}}</text>条</view>
  22. <button type="primary" @click="onSubmit" class="submit-BT"> {{handles.length>0?'下一步':'提交'}}</button>
  23. </view>
  24. </template>
  25. <script>
  26. import {upload} from '@/api/system/upload.js'
  27. import {updateChecklistHazardRecordDoing,completeChecklistDoing} from '@/api/aqpt/checklistHazardRecordApi.js'
  28. import { getChecklistHazardRecordView } from '@/api/aqpt/checklistRecordHazardApi'
  29. export default {
  30. data() {
  31. return {
  32. checkResults:[
  33. {text:"通过",value:1},
  34. {text:"不通过",value:-1},
  35. ],
  36. formData:{
  37. checkResult:1,
  38. remark:"",
  39. attachList:[]
  40. },
  41. rules:{},
  42. hazard:{},
  43. itemList:[],
  44. handles:[]
  45. }
  46. },
  47. onLoad() {
  48. this.init()
  49. },
  50. methods: {
  51. init(){
  52. let hazard=uni.getStorageSync('hazard');
  53. this.hazard=hazard;
  54. this.getchecklist()
  55. },
  56. async onSubmit() {
  57. let hazard=uni.getStorageSync('hazard')
  58. let attachList=[]
  59. for(let i=0;i<this.formData.attachList.length;i++){
  60. let filePath=this.formData.attachList[i].url
  61. let fileresq=await upload({filePath})
  62. fileresq=JSON.parse(fileresq)
  63. attachList.push(fileresq.data)
  64. }
  65. await updateChecklistHazardRecordDoing({
  66. recordId:hazard.recordId,
  67. checklistId:hazard.checklistId,
  68. hazardId:hazard.hazardId,
  69. riskId:hazard.riskId,
  70. measureId:hazard.measureId,
  71. checkResult:this.formData.checkResult,
  72. remark:this.formData.remark,
  73. attachList,
  74. }).catch(()=>{
  75. uni.showToast({
  76. icon:'none',
  77. title:"提交失败!"
  78. })
  79. })
  80. // uni.showToast({
  81. // icon:'none',
  82. // title:"提交成功!",
  83. // complete() {
  84. // uni.redirectTo({
  85. // url:`/pages/app_views/hazard/index/index?type=form&id=${hazard.checklistId}&recordId=${hazard.recordId}`
  86. // })
  87. // }
  88. // })
  89. let idx=this.itemList.findIndex(item=>item.measureId===hazard.measureId)
  90. this.itemList[idx].checkResult=this.formData.checkResult
  91. this.batchHandle()
  92. },
  93. getchecklist(){
  94. getChecklistHazardRecordView(this.hazard.recordId).then((res)=>{
  95. let itemList=res.data.hazardList
  96. let measures=[]
  97. let measureId=this.hazard.measureId
  98. for(let i=0;i<itemList.length;i++){
  99. if(itemList[i].riskList){
  100. itemList[i].riskList.map(child=>{
  101. child.recordList.map(measure=>{
  102. measures.push(measure)
  103. })
  104. })
  105. }
  106. }
  107. let index=measures.findIndex(item=>item.measureId===measureId)
  108. if(index>0){
  109. let temp=measures[0];
  110. measures[0]=JSON.parse(JSON.stringify(this.hazard))
  111. measures[index]=temp
  112. }
  113. this.itemList=measures
  114. this.handles=measures
  115. })
  116. },
  117. // 批量处理未处理的
  118. batchHandle(){
  119. let measure=uni.getStorageSync('hazard')
  120. let handles=JSON.parse(JSON.stringify(this.handles))
  121. handles.shift()
  122. this.handles=handles
  123. if(handles.length<1){
  124. const key=this.itemList.find(item=>item.checkResult===-1);
  125. if(!key){
  126. completeChecklistDoing(measure.recordId,measure.checklistId).then(()=>{
  127. uni.showToast({
  128. icon:'none',
  129. title:"处理完毕",
  130. duration:1000,
  131. complete() {
  132. uni.$emit('type',4)
  133. uni.switchTab({
  134. url:'/pages/history/history'
  135. })
  136. }
  137. })
  138. }).catch(()=>{
  139. uni.showToast({
  140. icon:"none",
  141. title:"操作失败"
  142. })
  143. })
  144. }else{
  145. let cid=measure.checklistId;
  146. let rid=measure.recordId;
  147. completeChecklistDoing(measure.recordId,measure.checklistId).then(()=>{
  148. uni.showModal({
  149. title: '提示',
  150. content: '本次检查有未通过项,是否需要登记隐患?',
  151. success: function (res) {
  152. if (res.confirm) {
  153. uni.reLaunch({
  154. url:`/pages/app_views/danger/submit/submit?rid=${rid}&cid=${cid}&type=hazard`
  155. })
  156. } else if (res.cancel) {
  157. uni.$emit('type',4)
  158. uni.switchTab({
  159. url:'/pages/history/history'
  160. })
  161. }
  162. }
  163. });
  164. }).catch(()=>{
  165. uni.showToast({
  166. icon:"none",
  167. title:"操作失败"
  168. })
  169. })
  170. }
  171. return
  172. }
  173. this.formData={
  174. checkResult:1,
  175. remark:"",
  176. attachList:[]
  177. }
  178. uni.setStorageSync('hazard',handles[0]);
  179. this.hazard=handles[0];
  180. },
  181. uploadSuccess(e){
  182. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  183. attachList.push(e.tempFiles[0])
  184. this.formData.attachList=attachList
  185. },
  186. deleteFile(e){
  187. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  188. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  189. this.formData.attachList=attachList
  190. },
  191. },
  192. onUnload() {
  193. uni.removeStorageSync('hazard')
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .wrap{
  199. padding: 20rpx;
  200. .tip{
  201. padding: 20rpx 10rpx 10rpx;
  202. text-align: right;
  203. color: #666;
  204. .word{
  205. font-weight: bold;
  206. color: #222;
  207. padding: 0 10rpx;
  208. }
  209. }
  210. .submit-BT {
  211. height: 72rpx;
  212. line-height: 72rpx;
  213. text-align: center;
  214. background:#3D90F4;
  215. border-radius: 42rpx;
  216. font-size: 32rpx;
  217. font-family: PingFang SC;
  218. font-weight: 400;
  219. color: #FFFFFF;
  220. margin: 50rpx auto;
  221. }
  222. ::v-deep .uni-forms-item{
  223. .uni-forms-item__content{
  224. .uni-data-checkbox-wrap{
  225. height: 100%;
  226. display: flex;
  227. align-items: center;
  228. }
  229. }
  230. }
  231. }
  232. </style>