form.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div class="body">
  3. <uni-forms ref="form" label-position="top" :model="formData">
  4. <uni-forms-item label="预警描述" >
  5. <p class="desc">{{formData.hdangerDesc}}</p>
  6. </uni-forms-item>
  7. <uni-forms-item label="处理动作" name="actionId" required>
  8. <uni-data-checkbox v-model="flowData.actionId" :localdata="actionList" @change="changeCheck"/>
  9. </uni-forms-item>
  10. <uni-forms-item label="处理说明" name="rectifyRemark" required>
  11. <uni-easyinput type="textarea" autoHeight v-model="formData.acceptRemark" placeholder="请输入描述"></uni-easyinput>
  12. </uni-forms-item>
  13. <uni-forms-item label="验收人" name="acceptAccountId" required>
  14. <view style="padding-bottom: 16rpx;">
  15. <uni-data-picker :map='groupMap'
  16. placeholder="请选择组织"
  17. popup-title="请选择组织"
  18. :localdata="groupList"
  19. @change="onchangeGroup">
  20. </uni-data-picker>
  21. </view>
  22. <uni-data-select
  23. v-model="formData.acceptAccountId"
  24. :localdata="userList"
  25. ></uni-data-select>
  26. </uni-forms-item>
  27. <uni-forms-item label="附件">
  28. <div class="upload-container">
  29. <image @click="upload" class="upload" src="/static/icon/upload.png" mode="widthFix"></image>
  30. <p class="tip">注:单个附件上传不超过10M,附件累计不超过20M</p>
  31. </div>
  32. <view class="preview" v-if="formData.attachList.length>0">
  33. <image class="preview-item" :src="attach.fileUrl" mode="widthFix" v-for="(attach,index) in formData.attachList" :key="index"></image>
  34. </view>
  35. </uni-forms-item>
  36. </uni-forms>
  37. <view class="footer" @click="onSubmit">提交</view>
  38. </div>
  39. </template>
  40. <script>
  41. import {getUserByPage} from '@/api/user.js'
  42. import {upload} from '@/api/index.js'
  43. import { startWorkflow, getWorkflowById, handleWorkflow } from '@/api/system/wfApi'
  44. import { updateDanger, getDangerById } from '@/api/dangerApi'
  45. import { getGroupByList } from '@/api/system/groupApi'
  46. import {parseTime,packageTreeData} from '@/libs'
  47. export default {
  48. data() {
  49. return {
  50. formData:{
  51. 'hdangerId': undefined,
  52. 'formCode': 'submit',
  53. 'hdangerTitle': '', // 预警标题
  54. 'dangerCatId': undefined, // 预警类别ID
  55. 'hdangerLevel': 1, // 预警等级
  56. 'acceptRemark': '', // 描述
  57. 'submitTime': parseTime(new Date()),
  58. 'dangerDeadline': '', // 截止时间
  59. 'goafId': undefined,
  60. 'checklistId': '',
  61. "attachList":[]
  62. },
  63. flowData:{
  64. },
  65. groupList:[],
  66. groupMap:{text:"groupName",value:"groupId"},
  67. actionList:[],
  68. userList:[]
  69. }
  70. },
  71. created() {
  72. this.init()
  73. },
  74. methods: {
  75. // 获取流程
  76. get(wfInsId) {
  77. // this.resetFormData()
  78. getWorkflowById(wfInsId).then((resp) => {
  79. const { code, data, msg } = resp
  80. if (code === 0) {
  81. this.$emit('success',data)
  82. this.flowData = data
  83. this.flowData.wfDefId = data.wfDefId
  84. this.flowData.wfInsId = data.wfInsId
  85. this.flowData.activityDefId = data.curActivityIns.activityDefId
  86. this.flowData.activityInsId = data.curActivityIns.activityInsId
  87. this.flowData.activityCode = data.curActivityIns.activityCode
  88. if(data.curActivityIns.actionList){
  89. let actionList=data.curActivityIns.actionList.map(function(item){
  90. item.value=item.actionId
  91. item.text=item.actionTitle
  92. return item
  93. })
  94. this.actionList=JSON.parse(JSON.stringify(actionList))
  95. this.flowData.actionId=actionList[0].actionId
  96. this.flowData.actionCode=actionList[0].actionCode
  97. }
  98. }
  99. })
  100. },
  101. init(){
  102. let data=uni.getStorageSync('submit-data')
  103. //初始化流程
  104. let danger_info=uni.getStorageSync('danger-info')
  105. this.formData={...this.formData,...danger_info}
  106. this.get(danger_info.hdangerId)
  107. this.getUser()
  108. this.getGroup()
  109. if(data){
  110. this.formData.checklistId = data.checklistId
  111. this.formData.goafId = data.goafId
  112. this.formData.acceptRemark = data.checkItemNopass
  113. this.formData.hdangerTitle = data.checkItemNopass
  114. }
  115. },
  116. async onSubmit(){
  117. let user=this.userList.filter(item=>item.accountId===this.formData.acceptAccountId)[0]
  118. if(!user){
  119. uni.showToast({
  120. icon:'none',
  121. title:"请选择验收人"
  122. })
  123. return
  124. }
  125. this.formData.acceptAccountName = user.accountName
  126. this.formData.acceptGroupId = user.groupId
  127. this.formData.acceptGroupName = user.groupName
  128. this.formData.acceptPositionId = user.positionId
  129. this.formData.acceptPositionName = user.positionName
  130. this.formData.ocId=user.ocId
  131. if(!this.verify()){
  132. return
  133. }
  134. handleWorkflow({
  135. "wfDefId": this.flowData.wfDefId,
  136. "wfInsId": this.flowData.wfInsId,
  137. "activityDefId": this.flowData.activityDefId,
  138. "activityInsId": this.flowData.activityInsId,
  139. "activityCode": this.flowData.activityCode,
  140. "actionId": this.flowData.actionId,
  141. "actionCode": this.flowData.actionCode,
  142. "actionRemark": this.formData.acceptRemark,
  143. "attachList":this.formData.attachList,
  144. "groupIdTo": user.groupId,
  145. "positionIdTo": user.positionId,
  146. "accountIdTo": user.accountId,
  147. "groupNameTo": user.groupName,
  148. "positionNameTo": user.positionName,
  149. "accountNameTo": user.accountName,
  150. }).then((res)=>{
  151. let flow=res.data
  152. if (flow.curActivityCode === 'review') {
  153. this.formData.status = 1
  154. }
  155. if (flow.curActivityCode === 'rectify') {
  156. this.formData.status = 2
  157. }
  158. if (flow.curActivityCode === 'accept') {
  159. this.formData.status = 3
  160. }
  161. this.formData.submitTime=parseTime(this.formData.submitTime)
  162. this.formData.dangerDeadline=parseTime(this.formData.dangerDeadline)
  163. updateDanger(this.formData).then((resp) => {
  164. uni.switchTab({
  165. url:'/pages/risk/risk'
  166. })
  167. })
  168. })
  169. },
  170. onchangeGroup({detail}){
  171. let groupVal=detail.value
  172. let groupId=groupVal[groupVal.length-1].value
  173. this.formData.acceptAccountId=""
  174. this.getUser(groupId)
  175. },
  176. getGroup(){
  177. getGroupByList().then((res)=>{
  178. let items=packageTreeData({
  179. data:res.data,
  180. id:"groupId"
  181. })
  182. this.groupList=items
  183. })
  184. },
  185. getUser(groupId){
  186. getUserByPage({
  187. page: 1,
  188. limit: 999999,
  189. groupId
  190. }).then((res)=>{
  191. this.userList=res.data.map(item=>{
  192. return{
  193. ...item,
  194. value:item.accountId,
  195. text:item.accountName
  196. }
  197. })
  198. })
  199. },
  200. upload(){
  201. let self=this;
  202. let attachList= JSON.parse(JSON.stringify(this.formData.attachList))
  203. uni.chooseImage({
  204. success:(files)=>{
  205. let filePath = files.tempFilePaths[0]
  206. upload({
  207. filePath
  208. }).then((res)=>{
  209. let result=JSON.parse(res);
  210. attachList.push(result.data)
  211. self.$set(self.formData,'attachList',attachList)
  212. self.$nextTick(()=>{
  213. self.scrollBottom()
  214. })
  215. })
  216. }
  217. })
  218. },
  219. scrollBottom(duration=100){
  220.  uni.createSelectorQuery().select(".footer").boundingClientRect((res)=>{
  221. const scrollH = res.top;
  222.   uni.pageScrollTo({
  223.     duration,// 过渡时间
  224.     scrollTop: scrollH,// 滚动的实际距离
  225.   })
  226. }).exec()
  227. },
  228. verify(){
  229. let items={
  230. 'rectifyRemark': '处理说明', //
  231. }
  232. for(let key in items){
  233. if(this.formData[key]===""||this.formData[key]===undefined||this.formData[key]==="undefined"){
  234. uni.showToast({
  235. icon:'none',
  236. title:`请填写${items[key]}`
  237. })
  238. return false;
  239. }
  240. }
  241. return true
  242. },
  243. changeCheck(){
  244. let actionCode=this.actionList.filter(item=>item.actionId===this.flowData.actionId)[0].actionCode
  245. this.flowData.actionCode=actionCode
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .body{
  252. min-height: 100vh;
  253. box-sizing: border-box;
  254. padding:21rpx 16rpx;
  255. background-color: #F3F5FB;
  256. padding-bottom: 160rpx;
  257. .desc{
  258. padding-left: 24rpx;
  259. color: #666;
  260. background-color: #fff;
  261. border-radius: 10rpx;
  262. padding: 10rpx;
  263. }
  264. .status-item{
  265. padding: 22rpx 32rpx;
  266. background-color: #fff;
  267. font-size: 28rpx;
  268. line-height: 1;
  269. display: inline-block;
  270. color: #434343;
  271. margin-right: 20rpx;
  272. border-radius: 2px;
  273. &.active{
  274. background: rgba(22, 141, 236, 0.16);
  275. color:#168DEC ;
  276. }
  277. }
  278. ::v-deep .uni-forms-item__content{
  279. .uni-easyinput,.uni-select{
  280. background-color: #fff;
  281. }
  282. }
  283. .upload-container{
  284. .upload{
  285. width: 216rpx;
  286. display: block;
  287. }
  288. .tip{
  289. font-size: 24rpx;
  290. line-height: 28rpx;
  291. color: #999999;
  292. padding-top: 20rpx;
  293. }
  294. }
  295. .footer{
  296. width: 100%;
  297. height: 136upx;
  298. background: #FFFFFF;
  299. border-radius: 16upx 16upx 0px 0px;
  300. position: fixed;
  301. left: 0;
  302. bottom: 0;
  303. text-align: center;
  304. color: #168DEC;
  305. font-size: 32upx;
  306. padding-top: 20upx;
  307. letter-spacing: 2px;
  308. }
  309. .preview{
  310. padding-top: 50rpx;
  311. .preview-item{
  312. width: 200rpx;
  313. height: 200rpx;
  314. border: 1px solid #ccc;
  315. margin: 10rpx;
  316. }
  317. }
  318. }
  319. </style>