submit.vue 12 KB

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