form.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. <button type="primary" @click="onSubmit" class="submit-BT">提交</button>
  22. </view>
  23. </template>
  24. <script>
  25. import {upload} from '@/api/system/upload.js'
  26. import {updateChecklistHazardRecordDoing} from '@/api/aqpt/checklistHazardRecordApi.js'
  27. export default {
  28. data() {
  29. return {
  30. checkResults:[
  31. {text:"通过",value:1},
  32. {text:"不通过",value:-1},
  33. ],
  34. formData:{
  35. checkResult:1,
  36. remark:"",
  37. attachList:[]
  38. },
  39. rules:{},
  40. hazard:{}
  41. }
  42. },
  43. onLoad() {
  44. this.init()
  45. },
  46. methods: {
  47. init(){
  48. let hazard=uni.getStorageSync('hazard');
  49. this.hazard=hazard;
  50. },
  51. async onSubmit() {
  52. let hazard=uni.getStorageSync('hazard')
  53. let attachList=[]
  54. for(let i=0;i<this.formData.attachList.length;i++){
  55. let filePath=this.formData.attachList[i].url
  56. let fileresq=await upload({filePath})
  57. fileresq=JSON.parse(fileresq)
  58. attachList.push(fileresq.data)
  59. }
  60. await updateChecklistHazardRecordDoing({
  61. recordId:hazard.recordId,
  62. checklistId:hazard.checklistId,
  63. hazardId:hazard.hazardId,
  64. riskId:hazard.riskId,
  65. measureId:hazard.measureId,
  66. checkResult:this.formData.checkResult,
  67. remark:this.formData.remark,
  68. attachList,
  69. }).catch(()=>{
  70. uni.showToast({
  71. icon:'none',
  72. title:"提交失败!"
  73. })
  74. })
  75. uni.showToast({
  76. icon:'none',
  77. title:"提交成功!",
  78. complete() {
  79. uni.redirectTo({
  80. url:`/pages/app_views/hazard/index/index?type=form&id=${hazard.checklistId}&recordId=${hazard.recordId}`
  81. })
  82. }
  83. })
  84. },
  85. uploadSuccess(e){
  86. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  87. attachList.push(e.tempFiles[0])
  88. this.formData.attachList=attachList
  89. },
  90. deleteFile(e){
  91. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  92. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  93. this.formData.attachList=attachList
  94. },
  95. },
  96. onUnload() {
  97. uni.removeStorageSync('hazard')
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .wrap{
  103. padding: 20rpx;
  104. .submit-BT {
  105. height: 72rpx;
  106. line-height: 72rpx;
  107. text-align: center;
  108. background:#3D90F4;
  109. border-radius: 42rpx;
  110. font-size: 32rpx;
  111. font-family: PingFang SC;
  112. font-weight: 400;
  113. color: #FFFFFF;
  114. margin: 50rpx auto;
  115. }
  116. ::v-deep .uni-forms-item{
  117. .uni-forms-item__content{
  118. .uni-data-checkbox-wrap{
  119. height: 100%;
  120. display: flex;
  121. align-items: center;
  122. }
  123. }
  124. }
  125. }
  126. </style>