submit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <div class="body">
  3. <uni-forms ref="form" label-position="top" :rules="rules" :model="formData">
  4. <uni-forms-item label="预警标题" name="desc" required>
  5. <uni-easyinput v-model="formData.hdangerTitle" placeholder="请输入描述"></uni-easyinput>
  6. </uni-forms-item>
  7. <uni-forms-item label="采空区" name="goafId" required>
  8. <uni-data-select
  9. v-model="formData.goafId"
  10. :localdata="goafList"
  11. ></uni-data-select>
  12. </uni-forms-item>
  13. <uni-forms-item v-if="formState!=='form_checkList'" label="检查表" name="checklistId" required>
  14. <uni-data-select
  15. v-model="formData.checklistId"
  16. :localdata="checkList"
  17. ></uni-data-select>
  18. </uni-forms-item>
  19. <uni-forms-item label="评审人" name="reviewAccountId" required>
  20. <view style="padding-bottom: 16rpx;">
  21. <uni-data-picker :map='groupMap'
  22. placeholder="请选择组织"
  23. popup-title="请选择组织"
  24. :localdata="groupList"
  25. @change="onchangeGroup">
  26. </uni-data-picker>
  27. </view>
  28. <uni-data-select
  29. v-model="formData.reviewAccountId"
  30. :localdata="userList"
  31. ></uni-data-select>
  32. </uni-forms-item>
  33. <uni-forms-item label="预警等级" name="hdangerLevel" required>
  34. <uni-data-checkbox v-model="formData.hdangerLevel" :localdata="hdangerLevels"></uni-data-checkbox>
  35. </uni-forms-item>
  36. <uni-forms-item label="发生时间" name="submitTime" required>
  37. <uni-datetime-picker
  38. type="datetime"
  39. v-model="formData.submitTime"
  40. />
  41. </uni-forms-item>
  42. <uni-forms-item label="截止时间" name="dangerDeadline" required>
  43. <uni-datetime-picker
  44. type="datetime"
  45. v-model="formData.dangerDeadline"
  46. />
  47. </uni-forms-item>
  48. <uni-forms-item label="描述" name="hdangerDesc" required>
  49. <uni-easyinput type="textarea" autoHeight v-model="formData.hdangerDesc" placeholder="请输入描述"></uni-easyinput>
  50. </uni-forms-item>
  51. <uni-forms-item label="附件">
  52. <div class="upload-container">
  53. <image @click="upload" class="upload" src="/static/icon/upload.png" mode="widthFix"></image>
  54. <p class="tip">注:单个附件上传不超过10M,附件累计不超过20M</p>
  55. </div>
  56. <view class="preview" v-if="formData.attachList.length>0">
  57. <image class="preview-item" :src="attach.fileUrl" mode="widthFix" v-for="(attach,index) in formData.attachList" :key="index"></image>
  58. </view>
  59. </uni-forms-item>
  60. </uni-forms>
  61. <view class="footer" @click="onSubmit">提交</view>
  62. </div>
  63. </template>
  64. <script>
  65. import { getGroupByList } from '@/api/system/groupApi'
  66. import {getUserByPage} from '@/api/user.js'
  67. import {upload} from '@/api/index.js'
  68. import { getChecklist } from '@/api/check'
  69. import { getGoafBaseInfo } from '@/api/goaf'
  70. import { startWorkflow, getWorkflowById, handleWorkflow } from '@/api/system/wfApi'
  71. import { handleDanger, getDangerById } from '@/api/dangerApi'
  72. import {parseTime,packageTreeData} from '@/libs'
  73. export default {
  74. data() {
  75. return {
  76. formData:{
  77. 'hdangerId': undefined,
  78. 'formCode': 'submit',
  79. 'hdangerTitle': '', // 预警标题
  80. 'dangerCatId': undefined, // 预警类别ID
  81. 'hdangerLevel': 0, // 预警等级
  82. 'hdangerDesc': '', // 描述
  83. 'submitTime': parseTime(new Date()),
  84. 'dangerDeadline': '', // 截止时间
  85. 'goafId': undefined,
  86. 'checklistId': '',
  87. "attachList":[]
  88. },
  89. formState:undefined,
  90. flowData:{},
  91. groupList:[],
  92. groupMap:{text:"groupName",value:"groupId"},
  93. userList:[],
  94. checkList:[],
  95. goafList:[],
  96. hdangerLevels:[
  97. {"value": 0,"text": "较低" },
  98. {"value": 1,"text": "一般"},
  99. {"value": 2,"text": "较大"},
  100. {"value": 3,"text": "重大"},
  101. ],
  102. rules:{
  103. reviewAccountId:{
  104. rules:[
  105. {
  106. required: true,
  107. errorMessage: '请选择评审人',
  108. },
  109. ],
  110. },
  111. desc:{
  112. rules:[
  113. {
  114. required: true,
  115. errorMessage: '请填写描述',
  116. },
  117. ]
  118. }
  119. },
  120. }
  121. },
  122. created() {
  123. this.init()
  124. },
  125. methods: {
  126. // 启动流程
  127. async start(wfDefId) {
  128. const { code, data, msg } = await startWorkflow(wfDefId)
  129. if (code === 0) {
  130. this.flowData = data
  131. this.flowData.wfDefId = data.wfDefId
  132. this.flowData.wfInsId = data.wfInsId
  133. this.flowData.activityDefId = data.curActivityIns.activityDefId
  134. this.flowData.activityInsId = data.curActivityIns.activityInsId
  135. this.flowData.activityCode = data.curActivityIns.activityCode
  136. this.formData.hdangerId=data.wfInsId
  137. this.renderAction()
  138. return data.wfInsId
  139. }
  140. },
  141. // 获取流程
  142. get(wfInsId) {
  143. this.resetFormData()
  144. getWorkflowById(wfInsId).then((resp) => {
  145. const { code, data, msg } = resp
  146. if (code === 0) {
  147. this.flowData = data
  148. this.flowData.wfDefId = data.wfDefId
  149. this.flowData.wfInsId = data.wfInsId
  150. this.flowData.activityDefId = data.curActivityIns.activityDefId
  151. this.flowData.activityInsId = data.curActivityIns.activityInsId
  152. this.flowData.activityCode = data.curActivityIns.activityCode
  153. this.renderAction()
  154. } else {
  155. this.$message.error(msg)
  156. }
  157. })
  158. },
  159. init(){
  160. let data=uni.getStorageSync('submit-data')
  161. if(data){
  162. this.formData.checklistId = data.checklistId
  163. this.formData.goafId = data.goafId
  164. this.formData.hdangerDesc = data.checkItemNopass
  165. this.formData.hdangerTitle = `${data.taskTitle}未通过检查`
  166. this.formState = 'form_checkList'
  167. }
  168. this.getUser()
  169. this.getGroup()
  170. this.getChecklist()
  171. this.getGoafBaseInfo()
  172. //初始化流程
  173. this.start(1)
  174. },
  175. getGroup(){
  176. getGroupByList().then((res)=>{
  177. let items=packageTreeData({
  178. data:res.data,
  179. id:"groupId"
  180. })
  181. this.groupList=items
  182. })
  183. },
  184. getUser(groupId){
  185. getUserByPage({
  186. page: 1,
  187. limit: 999999,
  188. groupId
  189. }).then((res)=>{
  190. this.userList=res.data.map(item=>{
  191. return{
  192. ...item,
  193. value:item.accountId,
  194. text:item.accountName
  195. }
  196. })
  197. })
  198. },
  199. getChecklist(){
  200. getChecklist().then((res)=>{
  201. this.checkList=res.data.map(item=>{
  202. return{
  203. ...item,
  204. value:item.checklistId,
  205. text:item.checklistTitle
  206. }
  207. })
  208. })
  209. },
  210. getGoafBaseInfo(){
  211. getGoafBaseInfo().then((res)=>{
  212. this.goafList=res.data.map(item=>{
  213. return{
  214. ...item,
  215. value:item.goafId,
  216. text:item.goafName
  217. }
  218. })
  219. })
  220. },
  221. onSubmit(){
  222. let user=this.userList.filter(item=>item.accountId===this.formData.reviewAccountId)[0]
  223. if(!this.verify()){
  224. return
  225. }
  226. handleWorkflow({
  227. "wfDefId": this.flowData.wfDefId,
  228. "wfInsId": this.flowData.wfInsId,
  229. "activityDefId": this.flowData.activityDefId,
  230. "activityInsId": this.flowData.activityInsId,
  231. "activityCode": this.flowData.activityCode,
  232. "actionId": this.flowData.actionId,
  233. "actionCode": this.flowData.actionCode,
  234. "actionRemark": this.flowData.hdangerDesc,
  235. "attachList":this.formData.attachList,
  236. "groupIdTo": user.groupId,
  237. "positionIdTo": user.positionId,
  238. "accountIdTo": this.formData.reviewAccountId,
  239. "groupNameTo": user.groupName,
  240. "positionNameTo": user.positionName,
  241. "accountNameTo": user.accountName,
  242. }).then((flow_resq)=>{
  243. let flow=flow_resq.data
  244. if (flow.curActivityCode === 'review') {
  245. this.formData.status = 1
  246. }
  247. if (flow.curActivityCode === 'rectify') {
  248. this.formData.status = 2
  249. }
  250. if (flow.curActivityCode === 'accept') {
  251. this.formData.status = 3
  252. }
  253. /**提交人*/
  254. let userData=uni.getStorageSync('accountInfo');
  255. this.formData.submitGroupId = userData.groupId
  256. this.formData.submitGroupName = userData.groupName
  257. this.formData.submitPositionId = userData.positionId
  258. this.formData.submitPositionName = userData.positionName
  259. this.formData.submitAccountId = userData.userId
  260. this.formData.submitAccountName = userData.userName
  261. this.formData.reviewRemark = this.flowData.hdangerDesc
  262. this.formData.reviewAccountName = user.accountName
  263. this.formData.reviewGroupId = user.groupId
  264. this.formData.reviewGroupName = user.groupName
  265. this.formData.reviewPositionId = user.positionId
  266. this.formData.reviewPositionName = user.positionName
  267. this.formData.ocId=user.ocId
  268. this.formData.submitTime=parseTime(this.formData.submitTime)
  269. this.formData.dangerDeadline=parseTime(this.formData.dangerDeadline)
  270. handleDanger(this.formData).then((resp) => {
  271. uni.switchTab({
  272. url:'/pages/risk/risk'
  273. })
  274. })
  275. })
  276. },
  277. upload(){
  278. let self=this;
  279. let attachList= JSON.parse(JSON.stringify(this.formData.attachList))
  280. uni.chooseImage({
  281. success:(files)=>{
  282. let filePath = files.tempFilePaths[0]
  283. upload({
  284. filePath
  285. }).then((res)=>{
  286. let result=JSON.parse(res);
  287. attachList.push(result.data)
  288. self.$set(self.formData,'attachList',attachList)
  289. self.$nextTick(()=>{
  290. self.scrollBottom()
  291. })
  292. })
  293. }
  294. })
  295. },
  296. // 渲染功能操作按钮
  297. renderAction() {
  298. if (this.flowData && this.flowData.curActivityIns && this.flowData.curActivityIns.actionList) {
  299. const arr = this.flowData.curActivityIns.actionList
  300. if (arr.length > 1) {
  301. this.actionVisible = true
  302. const item = arr[0]
  303. this.flowData.actionId = item.actionId
  304. this.flowData.actionCode = item.actionCode
  305. this.actionId = item.actionId
  306. } else if (arr.length === 1) {
  307. const item = arr[0]
  308. this.flowData.actionId = item.actionId
  309. this.flowData.actionCode = item.actionCode
  310. this.actionId = item.actionId
  311. } else {
  312. uni.showToast({
  313. icon:'none',
  314. title:'数据配置有误!请联系管理员'
  315. })
  316. }
  317. }
  318. },
  319. onchangeGroup({detail}){
  320. let groupVal=detail.value
  321. let groupId=groupVal[groupVal.length-1].value
  322. this.formData.reviewAccountId=""
  323. this.getUser(groupId)
  324. },
  325. scrollBottom(duration=100){
  326.  uni.createSelectorQuery().select(".footer").boundingClientRect((res)=>{
  327. const scrollH = res.top;
  328.   uni.pageScrollTo({
  329.     duration,// 过渡时间
  330.     scrollTop: scrollH,// 滚动的实际距离
  331.   })
  332. }).exec()
  333. },
  334. verify(){
  335. let items={
  336. 'hdangerTitle': '预警标题', //
  337. "reviewAccountId":'评审人',
  338. 'hdangerLevel': "预警等级", // 预警等级
  339. // 'hdangerDesc': '描述', //
  340. 'submitTime': "发生时间",
  341. 'dangerDeadline': '截止时间', //
  342. 'goafId': "采空区",
  343. 'checklistId': '检查表',
  344. // 'attachList':"附件"
  345. }
  346. for(let key in items){
  347. if(this.formData[key]===""||this.formData[key]===undefined||this.formData[key]==="undefined"){
  348. uni.showToast({
  349. icon:'none',
  350. title:`请填写${items[key]}`
  351. })
  352. return false;
  353. }
  354. }
  355. return true
  356. }
  357. }
  358. }
  359. </script>
  360. <style lang="scss" scoped>
  361. .body{
  362. min-height: 100vh;
  363. box-sizing: border-box;
  364. padding:21rpx 16rpx;
  365. background-color: #F3F5FB;
  366. padding-bottom: 160rpx;
  367. .status-item{
  368. padding: 22rpx 32rpx;
  369. background-color: #fff;
  370. font-size: 28rpx;
  371. line-height: 1;
  372. display: inline-block;
  373. color: #434343;
  374. margin-right: 20rpx;
  375. border-radius: 2px;
  376. &.active{
  377. background: rgba(22, 141, 236, 0.16);
  378. color:#168DEC ;
  379. }
  380. }
  381. ::v-deep .uni-forms-item__content{
  382. .uni-easyinput,.uni-select{
  383. background-color: #fff;
  384. }
  385. }
  386. .upload-container{
  387. .upload{
  388. width: 216rpx;
  389. display: block;
  390. }
  391. .tip{
  392. font-size: 24rpx;
  393. line-height: 28rpx;
  394. color: #999999;
  395. padding-top: 20rpx;
  396. }
  397. }
  398. .footer{
  399. width: 100%;
  400. height: 136upx;
  401. background: #FFFFFF;
  402. border-radius: 16upx 16upx 0px 0px;
  403. position: fixed;
  404. left: 0;
  405. bottom: 0;
  406. text-align: center;
  407. color: #168DEC;
  408. font-size: 32upx;
  409. padding-top: 20upx;
  410. letter-spacing: 2px;
  411. }
  412. .preview{
  413. padding-top: 50rpx;
  414. .preview-item{
  415. width: 200rpx;
  416. height: 200rpx;
  417. }
  418. }
  419. }
  420. </style>