form.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="wrap">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="300" label-position="top">
  4. <uni-forms-item label="隐患等级" name="checkResult" required>
  5. <view class="uni-data-checkbox-wrap">
  6. <uni-data-checkbox v-model="formData.action" :localdata="actions" />
  7. </view>
  8. </uni-forms-item>
  9. <uni-forms-item label="处理结果" name="remark" v-if="formData.action===1">
  10. <uni-easyinput v-model="formData.handleRemark" type="textarea" :maxlength="-1" autoHeight placeholder="备注" />
  11. </uni-forms-item>
  12. <uni-forms-item label="执行人" name="accountId" required v-if="formData.action===2">
  13. <uni-data-select v-model="formData.accountId" :localdata="userList"></uni-data-select>
  14. </uni-forms-item>
  15. <uni-file-picker v-model="formData.attachList"
  16. fileMediatype="image"
  17. title="附件"
  18. limit="1"
  19. @select="uploadSuccess"
  20. @delete="deleteFile"></uni-file-picker>
  21. </uni-forms>
  22. <button type="primary" @click="onSubmit" class="submit-BT">提交</button>
  23. </view>
  24. </template>
  25. <script>
  26. import {upload} from '@/api/system/upload.js'
  27. import {getUserList} from '@/api/system/user.js'
  28. import {updateChecklistHazardRecordDoing} from '@/api/aqpt/checklistHazardRecordApi.js'
  29. import { getSnapshotById, completeSnapshot, transferSnapshot } from '@/api/aqpt/snapshotApi'
  30. export default {
  31. data() {
  32. return {
  33. actions:[
  34. {text:"完成处理",value:1},
  35. {text:"转交",value:2},
  36. ],
  37. formData:{
  38. action:1,
  39. handleRemark:"",
  40. attachList:[]
  41. },
  42. userList:[],
  43. rules:{},
  44. snapshotId:undefined,
  45. snapshot:{}
  46. }
  47. },
  48. onLoad(options) {
  49. this.init()
  50. this.snapshotId=options.snapshotId
  51. this.formData.snapshotId=options.snapshotId
  52. },
  53. methods: {
  54. init(){
  55. this.getUserList()
  56. },
  57. async onSubmit() {
  58. let snapshotId=this.snapshotId
  59. let attachList=[]
  60. for(let i=0;i<this.formData.attachList.length;i++){
  61. let filePath=this.formData.attachList[i].url
  62. let fileresq=await upload({filePath})
  63. fileresq=JSON.parse(fileresq)
  64. attachList.push(fileresq.data)
  65. }
  66. let flow=this.userList.filter(item=>this.formData.accountId===item.accountId)[0]
  67. this.handleSelectUser(flow)
  68. if(this.formData.action===1){
  69. await completeSnapshot(this.formData).catch(()=>{
  70. uni.showToast({
  71. icon:'none',
  72. title:"提交失败!"
  73. })
  74. })
  75. }else{
  76. await transferSnapshot(snapshotId,this.formData).catch(()=>{
  77. uni.showToast({
  78. icon:'none',
  79. title:"提交失败!"
  80. })
  81. })
  82. }
  83. uni.showToast({
  84. icon:'none',
  85. title:"提交成功!",
  86. complete() {
  87. uni.$emit('type',3)
  88. uni.switchTab({
  89. url:'/pages/history/history'
  90. })
  91. }
  92. })
  93. },
  94. uploadSuccess(e){
  95. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  96. attachList.push(e.tempFiles[0])
  97. this.formData.attachList=attachList
  98. },
  99. deleteFile(e){
  100. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  101. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  102. this.formData.attachList=attachList
  103. },
  104. handleSelectUser(obj) {
  105. this.formData.accountIdTo = obj.accountId
  106. this.formData.groupIdTo = obj.groupId
  107. this.formData.positionIdTo = obj.positionId
  108. this.formData.accountNameTo = obj.accountName
  109. this.formData.groupNameTo = obj.groupName
  110. this.formData.positionNameTo = obj.positionName
  111. },
  112. getUserList(){
  113. getUserList().then((res)=>{
  114. var userList=[]
  115. for (var i = 0; i < res.data.length; i++) {
  116. userList.push({
  117. value: -i,
  118. text: res.data[i].name,
  119. disable:true
  120. })
  121. for(let j = 0; j < res.data[i].children.length; j++){
  122. userList.push({
  123. ...res.data[i].children[j],
  124. value: res.data[i].children[j].accountId,
  125. text: res.data[i].children[j].accountName
  126. })
  127. }
  128. }
  129. this.userList=userList
  130. })
  131. }
  132. },
  133. onUnload() {
  134. uni.removeStorageSync('hazard')
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .wrap{
  140. padding: 32rpx;
  141. padding-bottom: 200rpx;
  142. .submit-BT {
  143. width: 750rpx;
  144. height:156rpx;
  145. line-height:88rpx;
  146. color: #4D73FF;
  147. text-align: center;
  148. font-size: 32rpx;
  149. padding-bottom: 68rpx;
  150. background-color: #fff;
  151. position: fixed;
  152. left: 0;
  153. bottom: 0;
  154. z-index: 99;
  155. box-shadow: 0px 0px 12px 0px #0000000A;
  156. border-radius: 8px 8px 0px 0px
  157. }
  158. }
  159. </style>