submit.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="danger-submit-wrap">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="80">
  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="accountId" required>
  36. <uni-data-select v-model="formData.accountId" :localdata="userList"></uni-data-select>
  37. </uni-forms-item>
  38. <uni-forms-item label="描述" name="dangerDesc">
  39. <uni-easyinput v-model="formData.dangerDesc" type="textarea" :maxlength="-1" autoHeight placeholder="隐患描述" />
  40. </uni-forms-item>
  41. <uni-section title="上传附件" type="line">
  42. <view class="example-body">
  43. <uni-file-picker v-model="formData.attachList"
  44. fileMediatype="image"
  45. title="请上传附件"
  46. limit="1"
  47. @select="uploadSuccess"
  48. @delete="deleteFile"></uni-file-picker>
  49. </view>
  50. </uni-section>
  51. </uni-forms>
  52. <button type="primary" @click="onSubmit" class="submit-BT">提交</button>
  53. </view>
  54. </template>
  55. <script>
  56. import {getUserList} from '@/api/system/user.js'
  57. import {getGroupView,getGroupByList} from '@/api/system/groupApi.js'
  58. import {getDangerCatByList} from '@/api/danger.js'
  59. import {getRiskPointByList} from '@/api/riskPiont.js'
  60. import { startWorkflow, handleWorkflow } from '@/api/system/wfApi'
  61. import { handleDanger } from '@/api/system/dangerApi.js'
  62. import {upload} from '@/api/system/upload.js'
  63. export default {
  64. data() {
  65. return {
  66. dangerSourceRange:[
  67. { value: 0, text: "自查" },
  68. { value: 1, text: "内部反馈" },
  69. { value: 2, text: "上级检查" },
  70. { value: 3, text: "政府执法" },
  71. ],
  72. dangerLevelRange:[
  73. { value: 1, text: "一般隐患" },
  74. { value: 2, text: "重大隐患" }
  75. ],
  76. groupList:[],
  77. riskPointRange:[],
  78. dangerCatRange:[],
  79. userList:[],
  80. formData:{
  81. formCode: 'submit',
  82. dangerId: undefined,
  83. dangerCode: '',
  84. dangerTitle: '',
  85. dangerSource: 0,
  86. dangerDesc: '',
  87. dangerLevel: 1,
  88. dangerCatId: undefined,
  89. dangerCatTitle: '',
  90. riskPointId: undefined,
  91. dangerLocation: '',
  92. attachList:[]
  93. },
  94. rules: {
  95. dangerTitle: {
  96. rules:[
  97. {required: true,errorMessage: '请填写姓名',},
  98. ]
  99. },
  100. dangerCode: {rules:[{required: true,errorMessage: '请填写隐患编码'}]},
  101. dangerDeadLine: {rules:[{required: true,errorMessage: '请填写整改截止时间'}]}
  102. },
  103. flowData:{}
  104. }
  105. },
  106. onReady() {
  107. this.$refs.form.setRules(this.rules)
  108. },
  109. created() {
  110. this.init()
  111. },
  112. methods: {
  113. init(){
  114. this.getDangerCat()
  115. this.getRiskPoint()
  116. this.getUserList()
  117. this.getGroupRange()
  118. this.start(1)
  119. },
  120. // 启动流程
  121. async start(wfDefId) {
  122. const { data } = await startWorkflow(wfDefId)
  123. this.flowData = data
  124. },
  125. getDangerCat(){
  126. getDangerCatByList().then((res)=>{
  127. this.dangerCatRange=res.data.map(item=>{
  128. return{
  129. value: item.dangerCatId,
  130. text: item.dangerCatTitle
  131. }
  132. })
  133. })
  134. },
  135. getRiskPoint(){
  136. let app=uni.getStorageSync('qrcode');
  137. this.formData.dangerLocation=app.riskPointTitle
  138. this.formData.riskPointId=app.riskPointId
  139. },
  140. getGroupRange(){
  141. getGroupByList().then((res)=>{
  142. this.groupList=res.data.map(item=>{
  143. return{
  144. ...item,
  145. value: item.groupId,
  146. text: item.groupName
  147. }
  148. })
  149. })
  150. },
  151. getUserList(){
  152. getUserList().then((res)=>{
  153. var userList=[]
  154. for (var i = 0; i < res.data.length; i++) {
  155. userList.push({
  156. value: -i,
  157. text: res.data[i].name,
  158. disable:true
  159. })
  160. for(let j = 0; j < res.data[i].children.length; j++){
  161. userList.push({
  162. ...res.data[i].children[j],
  163. value: res.data[i].children[j].accountId,
  164. text: res.data[i].children[j].accountName
  165. })
  166. }
  167. }
  168. this.userList=userList
  169. })
  170. },
  171. onNodeclickGroup(node){
  172. // console.log({node})
  173. },
  174. onChangeGroup({detail}){
  175. // console.log(detail)
  176. },
  177. onSubmit(){
  178. this.$refs.form.validate().then(res=>{
  179. let flow=this.userList.filter(item=>this.formData.accountId===item.accountId)[0]
  180. let group=this.groupList.filter(item=>this.formData.groupId===item.groupId)[0]
  181. res.curGroupId = res.groupId
  182. res.curGroupName = group.groupName
  183. res.curPositionId = flow.positionId
  184. res.curPositionName = flow.positionName
  185. res.curAccountId = flow.accountId
  186. res.curAccountName = flow.accountName
  187. res.formCode= 'submit'
  188. res.dangerId=this.flowData.wfInsId
  189. res.dangerLocation=this.formData.dangerLocation
  190. res.riskPointId=this.formData.riskPointId
  191. res.submitRemark=this.formData.dangerDesc
  192. /*start*/
  193. let workflowForm={
  194. "actionId": 1,
  195. "wfDefId":this.flowData.wfDefId,
  196. "wfInsId":this.flowData.wfInsId,
  197. "activityDefId":this.flowData.activityDefId,
  198. "activityInsId":this.flowData.activityInsId,
  199. "activityCode":this.flowData.activityCode,
  200. "actionInsId":this.flowData.actionInsId,
  201. "actionDefId":this.flowData.actionDefList[0].actionDefId,
  202. "actionCode":this.flowData.actionDefList[0].actionCode,
  203. "groupIdTo": res.groupId||flow.groupId,
  204. "accountIdTo": flow.accountId,
  205. "accountNameTo": flow.accountName,
  206. "groupNameTo": group.groupName||flow.groupName,
  207. "positionIdTo": flow.positionId,
  208. "positionNameTo": flow.positionName,
  209. "actionRemark":this.formData.dangerDesc
  210. }
  211. this.handleSubmit({res,workflowForm})
  212. }).catch(err =>{
  213. console.log('表单错误信息:', err);
  214. })
  215. },
  216. async handleSubmit({res,workflowForm}) {
  217. let attachList=[]
  218. for(let i=0;i<this.formData.attachList.length;i++){
  219. let filePath=this.formData.attachList[i].url
  220. let fileresq=await upload({filePath})
  221. fileresq=JSON.parse(fileresq)
  222. attachList.push(fileresq.data)
  223. }
  224. let data=await handleWorkflow({...workflowForm,attachList})
  225. let resq=await handleDanger({...res,attachList,status:1})
  226. uni.showToast({
  227. icon:'none',
  228. title:"提交成功!",
  229. complete() {
  230. uni.$emit('type',2)
  231. uni.switchTab({
  232. url:'/pages/history/history?type=dangersubmit'
  233. })
  234. }
  235. })
  236. },
  237. uploadSuccess(e){
  238. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  239. attachList.push(e.tempFiles[0])
  240. this.formData.attachList=attachList
  241. },
  242. deleteFile(e){
  243. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  244. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  245. this.formData.attachList=attachList
  246. },
  247. }
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .danger-submit-wrap{
  252. padding: 20rpx;
  253. .submit-BT {
  254. height: 72rpx;
  255. line-height: 72rpx;
  256. text-align: center;
  257. background:#3D90F4;
  258. border-radius: 42rpx;
  259. font-size: 32rpx;
  260. font-family: PingFang SC;
  261. font-weight: 400;
  262. color: #FFFFFF;
  263. margin: 50rpx auto;
  264. }
  265. }
  266. </style>