warning.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="warning-handle-page">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="300" label-position="top">
  4. <uni-forms-item label="处理动作" required >
  5. <div class="uni-data-checkbox-wrap">
  6. <view class="action":class="action===1?'active':''" @click="changeAction(1)">
  7. <text>完成处理</text>
  8. </view>
  9. <view class="action":class="action===2?'active':''" @click="changeAction(2)">
  10. <text>转交</text>
  11. </view>
  12. </div>
  13. </uni-forms-item>
  14. <uni-forms-item v-if="handleRemarkVisible" label="原因分析" prop="actionRemark">
  15. <uni-easyinput v-model="formData.warnReason" type="textarea" :maxlength="-1" autoHeight placeholder="原因分析" />
  16. </uni-forms-item>
  17. <uni-forms-item v-if="handleRemarkVisible" label="处理措施" prop="actionRemark">
  18. <uni-easyinput v-model="formData.handleMeasure" type="textarea" :maxlength="-1" autoHeight placeholder="处理说明" />
  19. </uni-forms-item>
  20. <uni-forms-item v-if="handlerVisible" label="执行人" prop="accountIdTo">
  21. <uni-data-select v-model="formData.accountId" :localdata="userList"></uni-data-select>
  22. </uni-forms-item>
  23. <uni-forms-item v-if="handlerVisible" label="备注" prop="remark">
  24. <uni-easyinput v-model="transferData.remark" type="textarea" :maxlength="-1" autoHeight placeholder="请输入备注" />
  25. </uni-forms-item>
  26. <uni-file-picker v-model="formData.attachList"
  27. fileMediatype="image"
  28. title="请上传附件"
  29. limit="1"
  30. @select="uploadSuccess"
  31. @delete="deleteFile">
  32. </uni-file-picker>
  33. <view class="btn-group">
  34. <uni-button type="primary" @click="handleSubmit">提交</uni-button>
  35. </view>
  36. </uni-forms>
  37. </view>
  38. </template>
  39. <script>
  40. import {upload} from '@/api/system/upload.js'
  41. import {getUserList} from '@/api/system/user.js'
  42. import { getWarningById, completeWarning, transferWarning } from '@/api/aqpt/warningApi'
  43. export default {
  44. data() {
  45. return {
  46. formData:{
  47. warnId: undefined,
  48. attachList: []
  49. },
  50. transferData:{
  51. },
  52. viewData:{},
  53. rules:{},
  54. userList:[],
  55. action:1,
  56. warnId:undefined,
  57. handleRemarkVisible:false,
  58. handlerVisible:false
  59. }
  60. },
  61. created() {
  62. this.changeAction(1)
  63. this.getUserList()
  64. },
  65. onLoad({id}) {
  66. this.warnId=id
  67. this.formData.warnId = id
  68. this.getData()
  69. },
  70. methods: {
  71. // Fetch Data
  72. getData() {
  73. const warnId = this.warnId
  74. getWarningById(warnId).then((resp) => {
  75. const { data } = resp
  76. this.viewData = data
  77. })
  78. },
  79. changeAction(iMode){
  80. this.action=iMode;
  81. if (iMode === 1) {
  82. this.handleRemarkVisible = true
  83. this.handlerVisible = false
  84. } else if (iMode === 2) {
  85. this.handleRemarkVisible = false
  86. this.handlerVisible = true
  87. }
  88. },
  89. getUserList(){
  90. getUserList().then((res)=>{
  91. var userList=[]
  92. for (var i = 0; i < res.data.length; i++) {
  93. userList.push({
  94. value: -i,
  95. text: res.data[i].name,
  96. disable:true
  97. })
  98. for(let j = 0; j < res.data[i].children.length; j++){
  99. userList.push({
  100. ...res.data[i].children[j],
  101. value: res.data[i].children[j].accountId,
  102. text: res.data[i].children[j].accountName
  103. })
  104. }
  105. }
  106. this.userList=userList
  107. })
  108. },
  109. // 提交
  110. async handleSubmit() {
  111. const action = this.action
  112. if (action === 1) {
  113. let attachList=[]
  114. for(let i=0;i<this.formData.attachList.length;i++){
  115. let filePath=this.formData.attachList[i].url
  116. let fileresq=await upload({filePath})
  117. fileresq=JSON.parse(fileresq)
  118. attachList.push(fileresq.data)
  119. }
  120. this.formData.attachList=attachList
  121. await completeWarning(this.formData).then((resp) => {
  122. const { msg } = resp
  123. uni.showToast({
  124. icon:"none",
  125. title:msg||'处理成功!'
  126. })
  127. setTimeout(()=>{
  128. uni.navigateBack()
  129. },1000)
  130. })
  131. } else {
  132. let user=this.userList.filter(item=>this.formData.accountId===item.accountId)[0]
  133. this.handleSelectUser(user)
  134. transferWarning(this.warnId, this.transferData).then((resp) => {
  135. const { msg } = resp
  136. uni.showToast({
  137. icon:"none",
  138. title:msg||'处理成功!'
  139. })
  140. setTimeout(()=>{
  141. uni.navigateBack()
  142. },1000)
  143. })
  144. }
  145. },
  146. handleSelectUser(obj) {
  147. this.transferData.accountIdTo = obj.accountId
  148. this.transferData.groupIdTo = obj.groupId
  149. this.transferData.positionIdTo = obj.positionId
  150. this.transferData.accountNameTo = obj.accountName
  151. this.transferData.groupNameTo = obj.groupName
  152. this.transferData.positionNameTo = obj.positionName
  153. },
  154. uploadSuccess(e){
  155. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  156. attachList.push(e.tempFiles[0])
  157. this.formData.attachList=attachList
  158. },
  159. deleteFile(e){
  160. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  161. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  162. this.formData.attachList=attachList
  163. },
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .warning-handle-page{
  169. padding: 32rpx;
  170. ::v-deep .uni-forms-item{
  171. .uni-forms-item__content{
  172. .uni-data-checkbox-wrap{
  173. height: 100%;
  174. display: flex;
  175. align-items: center;
  176. .action{
  177. padding: 22rpx 32rpx;
  178. background-color: #fff;
  179. border-radius: 2px;
  180. margin-right: 20rpx;
  181. font-size: 28rpx;
  182. line-height: 1;
  183. &.active{
  184. background: rgba(77, 115, 255, 0.16);
  185. color: #4D73FF;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. .btn-group{
  192. margin-top: 100rpx;
  193. }
  194. }
  195. </style>