form.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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,attachList})
  70. .then(()=>{
  71. uni.showToast({
  72. icon:'none',
  73. title:"提交成功!",
  74. complete() {
  75. uni.$emit('type',5)
  76. uni.switchTab({
  77. url:'/pages/history/history'
  78. })
  79. }
  80. })
  81. })
  82. .catch(()=>{
  83. uni.showToast({
  84. icon:'none',
  85. title:"提交失败!"
  86. })
  87. })
  88. }else{
  89. await transferSnapshot(snapshotId,{...this.formData,attachList})
  90. .then(()=>{
  91. uni.showToast({
  92. icon:'none',
  93. title:"提交成功!",
  94. complete() {
  95. uni.$emit('type',5)
  96. uni.switchTab({
  97. url:'/pages/history/history'
  98. })
  99. }
  100. })
  101. })
  102. .catch(()=>{
  103. uni.showToast({
  104. icon:'none',
  105. title:"提交失败!"
  106. })
  107. })
  108. }
  109. },
  110. uploadSuccess(e){
  111. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  112. attachList.push(e.tempFiles[0])
  113. this.formData.attachList=attachList
  114. },
  115. deleteFile(e){
  116. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  117. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  118. this.formData.attachList=attachList
  119. },
  120. handleSelectUser(obj) {
  121. this.formData.accountIdTo = obj.accountId
  122. this.formData.groupIdTo = obj.groupId
  123. this.formData.positionIdTo = obj.positionId
  124. this.formData.accountNameTo = obj.accountName
  125. this.formData.groupNameTo = obj.groupName
  126. this.formData.positionNameTo = obj.positionName
  127. },
  128. getUserList(){
  129. getUserList().then((res)=>{
  130. var userList=[]
  131. for (var i = 0; i < res.data.length; i++) {
  132. userList.push({
  133. value: -i,
  134. text: res.data[i].name,
  135. disable:true
  136. })
  137. for(let j = 0; j < res.data[i].children.length; j++){
  138. userList.push({
  139. ...res.data[i].children[j],
  140. value: res.data[i].children[j].accountId,
  141. text: res.data[i].children[j].accountName
  142. })
  143. }
  144. }
  145. this.userList=userList
  146. })
  147. }
  148. },
  149. onUnload() {
  150. uni.removeStorageSync('hazard')
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .wrap{
  156. padding: 32rpx;
  157. padding-bottom: 200rpx;
  158. .submit-BT {
  159. width: 750rpx;
  160. height:156rpx;
  161. line-height:88rpx;
  162. color: #4D73FF;
  163. text-align: center;
  164. font-size: 32rpx;
  165. padding-bottom: 68rpx;
  166. background-color: #fff;
  167. position: fixed;
  168. left: 0;
  169. bottom: 0;
  170. z-index: 99;
  171. box-shadow: 0px 0px 12px 0px #0000000A;
  172. border-radius: 8px 8px 0px 0px
  173. }
  174. }
  175. </style>