form.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <div class="body">
  3. <uni-forms ref="form" label-position="top" :model="formData">
  4. <uni-forms-item label="预警说明">
  5. <uni-easyinput type="textarea" autoHeight disabled v-model="formData.hdangerDesc" placeholder="请输入描述"></uni-easyinput>
  6. </uni-forms-item>
  7. <uni-forms-item label="预警等级" name="hdangerLevel" required>
  8. <uni-data-checkbox v-model="formData.hdangerLevel" :localdata="hdangerLevels"></uni-data-checkbox>
  9. </uni-forms-item>
  10. <uni-forms-item label="截止时间" name="dangerDeadline" required>
  11. <uni-datetime-picker
  12. type="datetime"
  13. v-model="formData.dangerDeadline"
  14. />
  15. </uni-forms-item>
  16. <uni-forms-item label="处理动作" name="actionId" required v-if="actionList.length>0">
  17. <uni-data-checkbox v-model="flowData.actionId" :localdata="actionList" @change="changeCheck"/>
  18. </uni-forms-item>
  19. <uni-forms-item label="处理说明" name="reviewRemark" required>
  20. <uni-easyinput type="textarea" autoHeight v-model="formData.reviewRemark" placeholder="请输入描述"></uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item label="整改人" name="rectifyAccountId" required>
  23. <view style="padding-bottom: 16rpx;">
  24. <uni-data-picker
  25. v-model="groupId"
  26. :map='groupMap'
  27. placeholder="请选择组织"
  28. popup-title="请选择组织"
  29. :localdata="groupList"
  30. @nodeclick="onnodeclick"
  31. @change="onchangeGroup">
  32. </uni-data-picker>
  33. </view>
  34. <uni-data-select
  35. v-model="formData.rectifyAccountId"
  36. :localdata="userList"
  37. ></uni-data-select>
  38. </uni-forms-item>
  39. <uni-forms-item label="附件">
  40. <div class="upload-container">
  41. <image @click="upload" class="upload" src="/static/icon/upload.png" mode="widthFix"></image>
  42. <p class="tip">注:单个附件上传不超过10M,附件累计不超过20M</p>
  43. </div>
  44. <view class="preview" v-if="formData.attachList.length>0">
  45. <image class="preview-item" :src="attach.fileUrl" mode="widthFix" v-for="(attach,index) in formData.attachList" :key="index"></image>
  46. </view>
  47. </uni-forms-item>
  48. </uni-forms>
  49. <view class="footer" @click="onSubmit">提交</view>
  50. </div>
  51. </template>
  52. <script>
  53. import {getUserByPage} from '@/api/user.js'
  54. import {upload} from '@/api/index.js'
  55. import { startWorkflow, getWorkflowById, handleWorkflow } from '@/api/system/wfApi'
  56. import { updateDanger, getDangerById } from '@/api/dangerApi'
  57. import { getGroupByList } from '@/api/system/groupApi'
  58. import {parseTime,packageTreeData} from '@/libs'
  59. export default {
  60. name:"reviewForm",
  61. data() {
  62. return {
  63. formData:{
  64. 'hdangerId': undefined,
  65. 'formCode': 'review',
  66. 'hdangerTitle': '', // 预警标题
  67. 'dangerCatId': undefined, // 预警类别ID
  68. 'hdangerLevel': 0, // 预警等级
  69. 'reviewRemark': '', // 描述
  70. 'hdangerDesc':"",
  71. 'reviewTime': parseTime(new Date()),
  72. 'dangerDeadline': '', // 截止时间
  73. 'goafId': undefined,
  74. 'checklistId': '',
  75. "attachList":[]
  76. },
  77. flowData:{},
  78. hdangerLevels:[
  79. {"value": 0,"text": "较低" },
  80. {"value": 1,"text": "一般"},
  81. {"value": 2,"text": "较大"},
  82. {"value": 3,"text": "重大"},
  83. ],
  84. groupId:"",
  85. groupList:[],
  86. groupMap:{text:"groupName",value:"groupId"},
  87. actionList:[],
  88. userList:[]
  89. }
  90. },
  91. created() {
  92. this.init()
  93. },
  94. methods: {
  95. // 启动流程
  96. async start(wfDefId) {
  97. const { code, data, msg } = await startWorkflow(wfDefId)
  98. if (code === 0) {
  99. this.flowData = data
  100. this.flowData.wfDefId = data.wfDefId
  101. this.flowData.wfInsId = data.wfInsId
  102. this.flowData.activityDefId = data.curActivityIns.activityDefId
  103. this.flowData.activityInsId = data.curActivityIns.activityInsId
  104. this.flowData.activityCode = data.curActivityIns.activityCode
  105. this.formData.hdangerId=data.wfInsId
  106. return data.wfInsId
  107. }
  108. },
  109. // 获取流程
  110. get(wfInsId) {
  111. getWorkflowById(wfInsId).then((resp) => {
  112. const { code, data, msg } = resp
  113. if (code === 0) {
  114. this.$emit('success',data)
  115. this.flowData = data
  116. this.flowData.wfDefId = data.wfDefId
  117. this.flowData.wfInsId = data.wfInsId
  118. this.flowData.activityDefId = data.curActivityIns.activityDefId
  119. this.flowData.activityInsId = data.curActivityIns.activityInsId
  120. this.flowData.activityCode = data.curActivityIns.activityCode
  121. if(data.curActivityIns.actionList){
  122. let actionList=data.curActivityIns.actionList.map(function(item){
  123. item.value=item.actionId
  124. item.text=item.actionTitle
  125. return item
  126. })
  127. this.actionList=JSON.parse(JSON.stringify(actionList))
  128. this.flowData.actionId=actionList[0].actionId
  129. this.flowData.actionCode=actionList[0].actionCode
  130. }
  131. }
  132. })
  133. },
  134. init(){
  135. let data=uni.getStorageSync('submit-data')
  136. //初始化流程
  137. let danger_info=uni.getStorageSync('danger-info')
  138. this.formData={...this.formData,...danger_info}
  139. this.get(danger_info.hdangerId)
  140. this.getUser()
  141. this.getGroup()
  142. if(data){
  143. this.formData.checklistId = data.checklistId
  144. this.formData.goafId = data.goafId
  145. this.formData.hdangerDesc = data.checkItemNopass
  146. }
  147. },
  148. async onSubmit(){
  149. let user=this.userList.filter(item=>item.accountId===this.formData.rectifyAccountId)[0]
  150. if(user){
  151. this.formData.rectifyAccountName = user.accountName
  152. this.formData.rectifyGroupId = user.groupId
  153. this.formData.rectifyGroupName = user.groupName
  154. this.formData.rectifyPositionId = user.positionId
  155. this.formData.rectifyPositionName = user.positionName
  156. this.formData.ocId=user.ocId
  157. }
  158. if(!this.verify()){
  159. return
  160. }
  161. handleWorkflow({
  162. "wfDefId": this.flowData.wfDefId,
  163. "wfInsId": this.flowData.wfInsId,
  164. "activityDefId": this.flowData.activityDefId,
  165. "activityInsId": this.flowData.activityInsId,
  166. "activityCode": this.flowData.activityCode,
  167. "actionId": this.flowData.actionId,
  168. "actionCode": this.flowData.actionCode,
  169. "actionRemark": this.formData.reviewRemark,
  170. "attachList":this.formData.attachList,
  171. "groupIdTo": user.groupId,
  172. "positionIdTo": user.positionId,
  173. "accountIdTo": user.accountId,
  174. "groupNameTo": user.groupName,
  175. "positionNameTo": user.positionName,
  176. "accountNameTo": user.accountName,
  177. }).then((res)=>{
  178. let flow=res.data
  179. if (flow.curActivityCode === 'review') {
  180. this.formData.status = 1
  181. }
  182. if (flow.curActivityCode === 'rectify') {
  183. this.formData.status = 2
  184. }
  185. if (flow.curActivityCode === 'accept') {
  186. this.formData.status = 3
  187. }
  188. this.formData.reviewTime=parseTime(this.formData.reviewTime)
  189. this.formData.dangerDeadline=parseTime(this.formData.dangerDeadline)
  190. updateDanger(this.formData).then((resp) => {
  191. uni.switchTab({
  192. url:'/pages/risk/risk'
  193. })
  194. })
  195. })
  196. },
  197. onchangeGroup({detail}){
  198. let groupVal=detail.value
  199. let groupId=groupVal[groupVal.length-1].value
  200. this.formData.rectifyAccountId=""
  201. this.getUser(groupId)
  202. },
  203. onnodeclick(node){
  204. this.formData.rectifyAccountId=""
  205. this.groupId=node.groupId
  206. this.getUser(node.groupId)
  207. },
  208. getGroup(){
  209. getGroupByList().then((res)=>{
  210. let items=packageTreeData({
  211. data:res.data,
  212. id:"groupId"
  213. })
  214. this.groupList=items
  215. })
  216. },
  217. getUser(groupId=""){
  218. getUserByPage({
  219. page: 1,
  220. limit: 999999,
  221. groupId
  222. }).then((res)=>{
  223. this.userList=res.data.map(item=>{
  224. return{
  225. ...item,
  226. value:item.accountId,
  227. text:item.accountName
  228. }
  229. })
  230. })
  231. },
  232. upload(){
  233. let self=this;
  234. let attachList= JSON.parse(JSON.stringify(this.formData.attachList))
  235. uni.chooseImage({
  236. success:(files)=>{
  237. let filePath = files.tempFilePaths[0]
  238. upload({
  239. filePath
  240. }).then((res)=>{
  241. let result=JSON.parse(res);
  242. attachList.push(result.data)
  243. self.$set(self.formData,'attachList',attachList)
  244. self.$nextTick(()=>{
  245. self.scrollBottom()
  246. })
  247. })
  248. }
  249. })
  250. },
  251. scrollBottom(duration=100){
  252.  uni.createSelectorQuery().select(".footer").boundingClientRect((res)=>{
  253. const scrollH = res.top;
  254.   uni.pageScrollTo({
  255.     duration,// 过渡时间
  256.     scrollTop: scrollH,// 滚动的实际距离
  257.   })
  258. }).exec()
  259. },
  260. verify(){
  261. let items={
  262. 'reviewRemark': '处理说明', //
  263. 'rectifyAccountId':"整改人"
  264. }
  265. for(let key in items){
  266. if(this.formData[key]===""||this.formData[key]===undefined||this.formData[key]==="undefined"){
  267. uni.showToast({
  268. icon:'none',
  269. title:`请填写${items[key]}`
  270. })
  271. return false;
  272. }
  273. }
  274. return true
  275. },
  276. changeCheck(){
  277. let actionCode=this.actionList.filter(item=>item.actionId===this.flowData.actionId)[0].actionCode
  278. this.flowData.actionCode=actionCode
  279. }
  280. }
  281. }
  282. </script>
  283. <style lang="scss" scoped>
  284. .body{
  285. min-height: 100vh;
  286. box-sizing: border-box;
  287. padding:21rpx 16rpx;
  288. background-color: #F3F5FB;
  289. padding-bottom: 160rpx;
  290. .status-item{
  291. padding: 22rpx 32rpx;
  292. background-color: #fff;
  293. font-size: 28rpx;
  294. line-height: 1;
  295. display: inline-block;
  296. color: #434343;
  297. margin-right: 20rpx;
  298. border-radius: 2px;
  299. &.active{
  300. background: rgba(22, 141, 236, 0.16);
  301. color:#168DEC ;
  302. }
  303. }
  304. ::v-deep .uni-forms-item__content{
  305. .uni-easyinput,.uni-select{
  306. background-color: #fff;
  307. }
  308. }
  309. .upload-container{
  310. .upload{
  311. width: 216rpx;
  312. display: block;
  313. }
  314. .tip{
  315. font-size: 24rpx;
  316. line-height: 28rpx;
  317. color: #999999;
  318. padding-top: 20rpx;
  319. }
  320. }
  321. .footer{
  322. width: 100%;
  323. height: 136upx;
  324. background: #FFFFFF;
  325. border-radius: 16upx 16upx 0px 0px;
  326. position: fixed;
  327. left: 0;
  328. bottom: 0;
  329. text-align: center;
  330. color: #168DEC;
  331. font-size: 32upx;
  332. padding-top: 20upx;
  333. letter-spacing: 2px;
  334. }
  335. .preview{
  336. padding-top: 50rpx;
  337. .preview-item{
  338. width: 200rpx;
  339. height: 200rpx;
  340. }
  341. }
  342. }
  343. </style>