form.vue 9.0 KB

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