submit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="danger-submit-wrap">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="300" label-position="top">
  4. <uni-forms-item label="隐患标题" name="dangerTitle" required>
  5. <uni-easyinput v-model="formData.dangerTitle" />
  6. </uni-forms-item>
  7. <!-- <uni-forms-item label="隐患编码" name="dangerCode" required>
  8. <uni-easyinput v-model="formData.dangerCode" />
  9. </uni-forms-item> -->
  10. <uni-forms-item label="所在部门" name="groupId" required>
  11. <!-- <uni-data-picker :localdata="groupList"
  12. v-model="formData.groupId"
  13. placeholder="请选择组织"
  14. popup-title="请选择组织"
  15. @nodeclick="onNodeclickGroup"
  16. @change="onChangeGroup"
  17. :map="{text:'groupName',value:'groupId'}"></uni-data-picker> -->
  18. <uni-data-select v-model="formData.groupId" :localdata="groupList"></uni-data-select>
  19. </uni-forms-item>
  20. <!-- <uni-forms-item label="所在位置" name="riskPointId" required>
  21. <p>{{formData.dangerLocation}}</p>
  22. </uni-forms-item> -->
  23. <uni-forms-item label="隐患类别" name="dangerCatId" required>
  24. <uni-data-select v-model="formData.dangerCatId" :localdata="dangerCatRange"></uni-data-select>
  25. </uni-forms-item>
  26. <uni-forms-item label="隐患来源" name="dangerSource" required>
  27. <uni-data-select v-model="formData.dangerSource" :localdata="dangerSourceRange"></uni-data-select>
  28. </uni-forms-item>
  29. <uni-forms-item label="隐患等级" name="dangerLevel" required>
  30. <uni-data-checkbox v-model="formData.dangerLevel" :localdata="dangerLevelRange" />
  31. </uni-forms-item>
  32. <uni-forms-item label="整改截止时间" name="dangerDeadLine" required>
  33. <uni-datetime-picker type="datetime" return-type="string" v-model="formData.dangerDeadLine"/>
  34. </uni-forms-item>
  35. <uni-forms-item label="评审部门" name="handleGroup" required>
  36. <uni-data-select v-model="formData.handleGroup" :localdata="groupList" @change="changeHandGroup"></uni-data-select>
  37. </uni-forms-item>
  38. <uni-forms-item label="评审人员" name="accountId" required>
  39. <uni-data-select v-model="formData.accountId" :localdata="userList"></uni-data-select>
  40. </uni-forms-item>
  41. <uni-forms-item label="描述" name="dangerDesc">
  42. <uni-easyinput v-model="formData.dangerDesc" type="textarea" :maxlength="-1" autoHeight placeholder="隐患描述" />
  43. </uni-forms-item>
  44. <uni-section title="上传附件" type="line">
  45. <view class="example-body">
  46. <uni-file-picker v-model="formData.attachList"
  47. fileMediatype="image"
  48. title="请上传附件"
  49. limit="1"
  50. @select="uploadSuccess"
  51. @delete="deleteFile"></uni-file-picker>
  52. </view>
  53. </uni-section>
  54. </uni-forms>
  55. <view class="button-container" @click="onSubmit">提交</view>
  56. </view>
  57. </template>
  58. <script>
  59. import {getUserList,selectUserByGroupId} from '@/api/system/user.js'
  60. import {getGroupView,getGroupByList} from '@/api/system/groupApi.js'
  61. import {getDangerCatByList} from '@/api/danger.js'
  62. import {getRiskPointByList} from '@/api/riskPiont.js'
  63. import { startWorkflow, handleWorkflow } from '@/api/system/wfApi'
  64. import { handleDanger } from '@/api/system/dangerApi.js'
  65. import {upload} from '@/api/system/upload.js'
  66. import {getchecklistRecord} from '@/api/aqpt/checklistPoint.js'
  67. import { getChecklistHazardRecordView } from '@/api/aqpt/checklistRecordHazardApi'
  68. export default {
  69. data() {
  70. return {
  71. dangerSourceRange:[
  72. { value: 0, text: "自查" },
  73. { value: 1, text: "内部反馈" },
  74. { value: 2, text: "上级检查" },
  75. { value: 3, text: "政府执法" },
  76. ],
  77. dangerLevelRange:[
  78. { value: 1, text: "重大隐患" },
  79. { value: 2, text: "较大隐患" },
  80. { value: 3, text: "严重隐患" },
  81. { value: 4, text: "一般隐患" }
  82. ],
  83. groupList:[],
  84. riskPointRange:[],
  85. dangerCatRange:[],
  86. userList:[],
  87. formData:{
  88. formCode: 'submit',
  89. dangerId: undefined,
  90. dangerCode: undefined,
  91. dangerTitle: '',
  92. dangerSource: 0,
  93. dangerDesc: '',
  94. dangerLevel: 1,
  95. dangerCatId: undefined,
  96. dangerCatTitle: '',
  97. riskPointId: undefined,
  98. dangerLocation: '',
  99. accountId:"",
  100. attachList:[]
  101. },
  102. rules: {
  103. dangerTitle: {
  104. rules:[
  105. {required: true,errorMessage: '请填写姓名',},
  106. ]
  107. },
  108. handleGroup: {
  109. rules:[
  110. {required: true,errorMessage: '请选择评审部门',},
  111. ]
  112. },
  113. accountId: {
  114. rules:[
  115. {required: true,errorMessage: '请选择评审人员',},
  116. ]
  117. },
  118. // dangerCode: {rules:[{required: true,errorMessage: '请填写隐患编码'}]},
  119. dangerDeadLine: {rules:[{required: true,errorMessage: '请填写整改截止时间'}]}
  120. },
  121. flowData:{}
  122. }
  123. },
  124. onReady() {
  125. this.$refs.form.setRules(this.rules)
  126. },
  127. created() {
  128. this.init()
  129. },
  130. onLoad(data) {
  131. this.getchecklist(data)
  132. },
  133. methods: {
  134. init(){
  135. this.getDangerCat()
  136. this.getRiskPoint()
  137. this.getUserList()
  138. this.getGroupRange()
  139. this.start(1)
  140. },
  141. // 启动流程
  142. async start(wfDefId) {
  143. const { data } = await startWorkflow(wfDefId)
  144. this.flowData = data
  145. },
  146. getDangerCat(){
  147. getDangerCatByList().then((res)=>{
  148. this.dangerCatRange=res.data.map(item=>{
  149. return{
  150. value: item.dangerCatId,
  151. text: item.dangerCatTitle
  152. }
  153. })
  154. })
  155. },
  156. changeHandGroup(id){
  157. this.userList=[]
  158. this.formData.accountId="";
  159. if(!id){
  160. this.getUserList();
  161. return;
  162. }
  163. selectUserByGroupId(id).then((res)=>{
  164. var userList=[]
  165. for (var i = 0; i < res.data.length; i++) {
  166. userList.push({
  167. value: -i,
  168. text: res.data[i].name,
  169. disable:true
  170. })
  171. for(let j = 0; j < res.data[i].children.length; j++){
  172. userList.push({
  173. ...res.data[i].children[j],
  174. value: res.data[i].children[j].accountId,
  175. text: res.data[i].children[j].accountName
  176. })
  177. }
  178. }
  179. console.log({userList})
  180. this.userList=userList
  181. })
  182. },
  183. getRiskPoint(){
  184. let app=uni.getStorageSync('qrcode');
  185. this.formData.dangerLocation=app.riskPointTitle
  186. this.formData.riskPointId=app.riskPointId
  187. },
  188. getchecklist({cid,rid,type}){
  189. if(type==='hazard'){
  190. getChecklistHazardRecordView(rid).then((res)=>{
  191. let itemList=res.data.hazardList
  192. let measures=[]
  193. for(let i=0;i<itemList.length;i++){
  194. if(itemList[i].riskList){
  195. itemList[i].riskList.map(child=>{
  196. child.recordList.map(measure=>{
  197. measures.push(measure)
  198. })
  199. })
  200. }
  201. }
  202. let noPassPoints=measures.filter(item=>item.checkResult===-1)
  203. let dangerDesc=noPassPoints.reduce((acc, cur) => `${cur.measureContent}【未通过】;\n` + acc, "")
  204. this.formData.dangerDesc=dangerDesc
  205. this.formData.dangerTitle=`${res.data.targetTitle}【${res.data.hazardList[0].hazardTitle}】`
  206. })
  207. }
  208. if(type==='point'){
  209. getchecklistRecord(cid,rid).then((res)=>{
  210. let itemList=res.data.itemList
  211. let points=[]
  212. for(let i=0;i<itemList.length;i++){
  213. if(itemList[i].children){
  214. itemList[i].children.map(child=>{
  215. child.recordList.map(pointitem=>{
  216. points.push(pointitem)
  217. })
  218. })
  219. }else{
  220. itemList[i].recordList.map(pointitem=>{
  221. points.push(pointitem)
  222. })
  223. }
  224. }
  225. let noPassPoints=points.filter(item=>item.checkResult===-1)
  226. let dangerDesc=noPassPoints.reduce((acc, cur) => `${cur?.pointContent}【未通过】;\n` + acc, "")
  227. this.formData.dangerDesc=dangerDesc
  228. this.formData.dangerTitle=res.data.targetTitle
  229. })
  230. }
  231. },
  232. getGroupRange(){
  233. getGroupByList().then((res)=>{
  234. this.groupList=res.data.map(item=>{
  235. return{
  236. ...item,
  237. value: item.groupId,
  238. text: item.groupName
  239. }
  240. })
  241. })
  242. },
  243. getUserList(){
  244. getUserList().then((res)=>{
  245. var userList=[]
  246. for (var i = 0; i < res.data.length; i++) {
  247. userList.push({
  248. value: -i,
  249. text: res.data[i].name,
  250. disable:true
  251. })
  252. for(let j = 0; j < res.data[i].children.length; j++){
  253. userList.push({
  254. ...res.data[i].children[j],
  255. value: res.data[i].children[j].accountId,
  256. text: res.data[i].children[j].accountName
  257. })
  258. }
  259. }
  260. this.userList=userList
  261. })
  262. },
  263. onNodeclickGroup(node){
  264. // console.log({node})
  265. },
  266. onChangeGroup({detail}){
  267. // console.log(detail)
  268. },
  269. onSubmit(){
  270. this.$refs.form.validate().then(res=>{
  271. let flow=this.userList.filter(item=>this.formData.accountId===item.accountId)[0]
  272. let group=this.groupList.filter(item=>this.formData.groupId===item.groupId)[0]
  273. res.curGroupId = flow.groupId
  274. res.curGroupName = flow.groupName
  275. res.curPositionId = flow.positionId
  276. res.curPositionName = flow.positionName
  277. res.curAccountId = flow.accountId
  278. res.curAccountName = flow.accountName
  279. res.groupId=this.formData.groupId
  280. res.formCode= 'submit'
  281. res.dangerId=this.flowData.wfInsId
  282. res.dangerLocation=this.formData.dangerLocation
  283. res.riskPointId=this.formData.riskPointId
  284. res.submitRemark=this.formData.dangerDesc
  285. /*start*/
  286. let workflowForm={
  287. "actionId": 1,
  288. "wfDefId":this.flowData.wfDefId,
  289. "wfInsId":this.flowData.wfInsId,
  290. "activityDefId":this.flowData.activityDefId,
  291. "activityInsId":this.flowData.activityInsId,
  292. "activityCode":this.flowData.activityCode,
  293. "actionInsId":this.flowData.actionInsId,
  294. "actionDefId":this.flowData.actionDefList[0].actionDefId,
  295. "actionCode":this.flowData.actionDefList[0].actionCode,
  296. "groupId":this.formData.groupId,
  297. "groupName":group.groupName,
  298. "groupIdTo": flow.groupId,
  299. "accountIdTo": flow.accountId,
  300. "accountNameTo": flow.accountName,
  301. "groupNameTo": flow.groupName,
  302. "positionIdTo": flow.positionId,
  303. "positionNameTo": flow.positionName,
  304. "actionRemark":this.formData.dangerDesc
  305. }
  306. this.handleSubmit({res,workflowForm})
  307. }).catch(err =>{
  308. console.log('表单错误信息:', err);
  309. })
  310. },
  311. async handleSubmit({res,workflowForm}) {
  312. let attachList=[]
  313. for(let i=0;i<this.formData.attachList.length;i++){
  314. let filePath=this.formData.attachList[i].url
  315. let fileresq=await upload({filePath})
  316. fileresq=JSON.parse(fileresq)
  317. attachList.push(fileresq.data)
  318. }
  319. let qrcode=uni.getStorageSync('qrcode')
  320. let qrcode_target={
  321. targetId:qrcode.targetId,
  322. targetType:qrcode.targetType,
  323. targetTitle:qrcode.targetTitle,
  324. targetGroupId:qrcode.groupId,
  325. targetGroupName:qrcode.groupName,
  326. }
  327. let flow=await handleWorkflow({...workflowForm,attachList})
  328. let resq=await handleDanger({... this.formData,...qrcode_target,attachList,status:1,riskPointId:qrcode.targetId})
  329. uni.showToast({
  330. icon:'none',
  331. title:"提交成功!",
  332. complete() {
  333. uni.$emit('type',2)
  334. uni.switchTab({
  335. url:'/pages/history/history?type=dangersubmit'
  336. })
  337. }
  338. })
  339. },
  340. uploadSuccess(e){
  341. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  342. attachList.push(e.tempFiles[0])
  343. this.formData.attachList=attachList
  344. },
  345. deleteFile(e){
  346. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  347. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  348. this.formData.attachList=attachList
  349. },
  350. }
  351. }
  352. </script>
  353. <style lang="scss" scoped>
  354. .danger-submit-wrap{
  355. padding: 20rpx 20rpx 200rpx 20rpx;
  356. .button-container{
  357. width: 750rpx;
  358. height:88rpx;
  359. line-height:88rpx;
  360. color: #4D73FF;
  361. text-align: center;
  362. font-size: 32rpx;
  363. padding-bottom: 68rpx;
  364. background-color: #fff;
  365. position: fixed;
  366. left: 0;
  367. bottom: 0;
  368. z-index: 2;
  369. box-shadow: 0px 0px 12px 0px #0000000A;
  370. border-radius: 8px 8px 0px 0px
  371. }
  372. }
  373. </style>