submit.vue 12 KB

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