detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <hc-sys id="app-sys" class="h-full hc-app-task-detail" :isNavBar="false">
  3. <view id="task-detail-content" class="task-detail-content">
  4. <view class="task-name-box">
  5. <view class="name-bar">{{taskInfo.taskName}}</view>
  6. <view class="arrow-bar">
  7. <zb-tooltip placement="bottom-end" ref="tooltipRef">
  8. <uni-icons type="bottom" size="22"/>
  9. <template #content>
  10. <view class="task-item" v-for="item in taskList" @click="taskClick(item)">{{item.taskName}}</view>
  11. </template>
  12. </zb-tooltip>
  13. </view>
  14. </view>
  15. <view class="task-report-info">
  16. <view>上报人:{{taskInfo.reportUserName}}</view>
  17. <view>{{taskInfo.startTime}}</view>
  18. </view>
  19. <view class="task-pdf-list-bar">
  20. <view class="task-pdf-info">
  21. <view class="file-name">{{taskFileInfo.fileName}}</view>
  22. <view class="file-num">共{{taskFileInfo.fileNum}}张表格</view>
  23. </view>
  24. <zb-tooltip placement="bottom-end" ref="tooltipRef1">
  25. <view class="task-pdf-info">
  26. <view class="file-name">{{taskFileInfo.fileName}}</view>
  27. <view class="file-num">共{{taskFileInfo.fileNum}}张表格</view>
  28. </view>
  29. <template #content>
  30. <view class="task-item" v-for="item in taskInfo.approvalFileList" @click="taskFileClick(item)">{{item.fileName}}</view>
  31. </template>
  32. </zb-tooltip>
  33. </view>
  34. </view>
  35. <!--pdf区域-->
  36. <hc-pdf :ui="webViewStyle" :src="taskFileInfo?.fileUrl" v-if="taskFileInfo?.fileUrl"/>
  37. <uv-empty icon="/static/image/list.png" marginTop="24" v-else/>
  38. <!--底部操作栏-->
  39. <template v-if="isTaskAuth">
  40. <HcTabbarBlock :height="77"/>
  41. <hc-tabbars id="action-bar">
  42. <button type="primary" class="action-bar-btn" @click="approveClick">
  43. <text>审</text>
  44. <text class="ml-10">批</text>
  45. </button>
  46. </hc-tabbars>
  47. </template>
  48. <view id="action-bar" v-else></view>
  49. <!-- 普通弹窗 -->
  50. <uni-popup ref="popupRef" class="hc-popup" type="bottom">
  51. <view class="task-popup-content">
  52. <template v-if="popupType === 1">
  53. <view class="title">请选择审批是否通过?</view>
  54. <view class="popup-btn-bar">
  55. <button type="primary" class="popup-btn c1" @click="agreeClick">同意签字审批</button>
  56. </view>
  57. <view class="popup-btn-bar">
  58. <button type="primary" class="popup-btn c2" @click="cancelTaskClick">废除任务</button>
  59. </view>
  60. <view class="popup-btn-bar">
  61. <button type="primary" class="popup-btn c3" @click="cancelApproval">取消审批</button>
  62. </view>
  63. </template>
  64. <template v-if="popupType === 2">
  65. <view class="title">请输入验证码验证是否为本人操作授权</view>
  66. <view class="popup-code-bar">
  67. <view class="btn-tel-code-bar">
  68. <view class="btn-tel">{{userInfo.phone}}</view>
  69. <view class="btn-code">
  70. <button type="primary" :disabled="isCodeDisabled" class="popup-btn code" size="mini" @click="getCodeClick">
  71. {{ isCodeDisabled ? `倒计时${currentCodeTime}s` : '发送验证码' }}
  72. </button>
  73. </view>
  74. </view>
  75. <view class="code-input-bar">
  76. <input class="code-input" v-model="smsCode" placeholder="请输入验证码"/>
  77. </view>
  78. </view>
  79. <view class="popup-btn-bar">
  80. <button type="primary" class="popup-btn c4" @click="confirmApproval">确认审批</button>
  81. </view>
  82. <view class="popup-btn-bar">
  83. <button type="primary" class="popup-btn c3" @click="cancelClick">取消操作</button>
  84. </view>
  85. </template>
  86. <template v-if="popupType === 3">
  87. <view class="popup-argument-bar">
  88. <textarea class="argument-input" v-model="argument" :maxlength="-1" placeholder="请输入废除任务的理由"/>
  89. </view>
  90. <view class="popup-btn-bar">
  91. <button type="primary" class="popup-btn c1" @click="confirmRepeal">确认废除</button>
  92. </view>
  93. <view class="popup-btn-bar">
  94. <button type="primary" class="popup-btn c3" @click="cancelClick">取消操作</button>
  95. </view>
  96. </template>
  97. </view>
  98. </uni-popup>
  99. </hc-sys>
  100. </template>
  101. <script setup>
  102. import {ref, nextTick, getCurrentInstance} from "vue";
  103. import {onLoad, onReady} from '@dcloudio/uni-app'
  104. import {arrToKey, getArrValue, getObjValue, isString} from "js-fast-way";
  105. import {errorToast, querySelect, successToast} from "@/utils/tools";
  106. import {checkFlowUserIsExistPfxFile, saveSmsTimeout, sendNotice} from "~api/other/index";
  107. import mainApi from '~api/tasks/data';
  108. import {useAppStore} from "@/store";
  109. import dayjs from "dayjs";
  110. //初始变量
  111. const store = useAppStore()
  112. const instance = getCurrentInstance().proxy
  113. const userInfo = ref(store.userInfo);
  114. const taskList = ref([])
  115. const taskInfo = ref({})
  116. const isTaskAuth = ref(false)
  117. //页面传参数据
  118. let eventChannel = null;
  119. const getEventChannel = async () => {
  120. await nextTick();
  121. eventChannel = instance.getOpenerEventChannel();
  122. }
  123. onLoad(({node}) => {
  124. const {rows, isTask} = node ? JSON.parse(decodeURIComponent(node)) : {};
  125. const res = getArrValue(rows);
  126. if (res.length > 0) {
  127. taskInfo.value = res[0]
  128. }
  129. taskList.value = res
  130. isTaskAuth.value = !!isTask
  131. getDataApi()
  132. })
  133. //渲染完成
  134. onReady(() => {
  135. setWebViewStyle()
  136. })
  137. //获取数据
  138. const getDataApi = async () => {
  139. uni.showLoading({title: '获取数据中...', mask: true});
  140. await getEventChannel()
  141. await getTaskInfo()
  142. checkSmsCode().then()
  143. uni.hideLoading();
  144. }
  145. //设置webview样式
  146. const webViewStyle = ref({})
  147. const setWebViewStyle = async () => {
  148. const appSys = await querySelect(instance,'app-sys')
  149. const appSysHeight = appSys.height
  150. //顶部
  151. const contentBar = await querySelect(instance,'task-detail-content')
  152. const contentBarHeight = contentBar?.height ?? 48
  153. // #ifdef H5
  154. webViewStyle.value.top = contentBarHeight + 'px'
  155. // #endif
  156. // #ifdef APP-PLUS
  157. const {statusBarHeight} = uni.getSystemInfoSync()
  158. webViewStyle.value.top = statusBarHeight + 45 + contentBarHeight
  159. // #endif
  160. //底部
  161. const actionBar = await querySelect(instance,'action-bar')
  162. const actionBarHeight = actionBar?.height ?? 80
  163. webViewStyle.value.height = (appSysHeight - contentBarHeight - actionBarHeight - 2) + 'px'
  164. }
  165. //切换任务
  166. const tooltipRef = ref(null)
  167. const taskClick = (item) => {
  168. taskInfo.value = item
  169. taskFileInfo.value = item.approvalFileList[0]
  170. tooltipRef.value?.close()
  171. }
  172. //切换PDF
  173. const tooltipRef1 = ref(null)
  174. const taskFileInfo = ref({})
  175. const taskFileClick = (item) => {
  176. taskFileInfo.value = item
  177. tooltipRef1.value?.close()
  178. }
  179. //获取任务详情
  180. const getTaskInfo = async () => {
  181. const rows = taskList.value
  182. if (rows.length <= 0) return false
  183. //处理详情数据
  184. for (let i = 0; i < rows.length; i++) {
  185. const res = await queryApprovalParameter(rows[i])
  186. rows[i].approvalFileList = res.approvalFileList
  187. }
  188. taskInfo.value = getObjValue(rows[0])
  189. taskFileInfo.value = getObjValue(rows[0].approvalFileList[0])
  190. taskList.value = rows
  191. }
  192. //获取审批详情
  193. const queryApprovalParameter = async ({parallelProcessInstanceId, formDataId, approvalType}) => {
  194. const { data } = await mainApi.queryApprovalParameter({
  195. parallelProcessInstanceId: parallelProcessInstanceId ?? '',
  196. formDataId: formDataId ?? '',
  197. approvalType: approvalType ?? ''
  198. })
  199. const res = getObjValue(data)
  200. const list = getArrValue(res.approvalFileList)
  201. for (let i = 0; i < list.length; i++) {
  202. list[i].fileNum = await queryPDFnumApi(list[i]?.fileUrl)
  203. }
  204. res.approvalFileList = list
  205. return getObjValue(data)
  206. }
  207. //查询PDF数量
  208. const queryPDFnumApi = async (pdfUrl) => {
  209. const { data } = await mainApi.queryPDFnum({
  210. url: pdfUrl
  211. })
  212. return data ? data : 0
  213. }
  214. //审批弹窗
  215. const popupRef = ref(null)
  216. const popupType = ref(1)
  217. const approveClick = () => {
  218. popupType.value = 1
  219. popupRef.value?.open()
  220. }
  221. //短信验证有效期
  222. const smsCodeTime = ref('')
  223. const checkSmsCode = async () => {
  224. const {data} = await mainApi.checkSmsCode()
  225. smsCodeTime.value = isString(data) ? data : '';
  226. }
  227. //验证短信有效期
  228. const isCheckSmsCodeTime = () => {
  229. const smsTime = smsCodeTime.value;
  230. if (!smsTime) return true
  231. const toDayTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
  232. return dayjs(smsTime).isBefore(toDayTime)
  233. }
  234. //同意审批短信验证
  235. const smsCode = ref('')
  236. const agreeClick = async () => {
  237. const showAuth = isCheckSmsCodeTime()
  238. if (showAuth) {
  239. smsCode.value = ''
  240. popupType.value = 2
  241. } else {
  242. const {error, code, msg, data} = await checkFlowUserIsExistPfxFile()
  243. if (!error && code === 200 && data === true) {
  244. const showAuth = isCheckSmsCodeTime()
  245. if (showAuth) {
  246. smsCode.value = ''
  247. popupType.value = 2
  248. } else {
  249. batchTaskApproval('ok').then()
  250. }
  251. } else {
  252. errorToast(msg)
  253. cancelApproval()
  254. }
  255. }
  256. }
  257. //验证码倒计时
  258. const totalTime = 60 //总时间,单位秒
  259. const isCodeDisabled = ref(false) //是否开启倒计时
  260. const recordingCodeTime = ref(0) //记录时间变量
  261. const currentCodeTime = ref(0) //显示时间变量
  262. //获取短信验证码
  263. const resCode = ref('')
  264. const getCodeClick = async () => {
  265. const {phone} = userInfo.value
  266. if (!phone) {
  267. errorToast('您的手机号是空的,无法获取验证码')
  268. return false
  269. }
  270. const { error, code, msg } = await sendNotice({
  271. phone: phone
  272. })
  273. //处理数据
  274. if (!error && code === 200 && msg) {
  275. resCode.value = msg
  276. //把显示时间设为总时间
  277. currentCodeTime.value = totalTime
  278. //开始倒计时
  279. isCodeDisabled.value = true
  280. //执行倒计时
  281. checkingTime()
  282. successToast('发送成功')
  283. } else {
  284. resCode.value = ''
  285. errorToast(msg)
  286. }
  287. }
  288. //倒计时
  289. const checkingTime = () => {
  290. //判断是否开启
  291. if (isCodeDisabled.value) {
  292. //判断显示时间是否已到0,判断记录时间是否已到总时间
  293. if (currentCodeTime.value > 0 && recordingCodeTime.value <= totalTime) {
  294. //记录时间增加 1
  295. recordingCodeTime.value++
  296. //显示时间,用总时间 - 记录时间
  297. currentCodeTime.value = totalTime - recordingCodeTime.value
  298. //1秒钟后,再次执行本方法
  299. setTimeout(() => {
  300. checkingTime()
  301. }, 1000)
  302. } else {
  303. //时间已完成,还原相关变量
  304. isCodeDisabled.value = false //关闭倒计时
  305. recordingCodeTime.value = 0 //记录时间为0
  306. currentCodeTime.value = totalTime //显示时间为总时间
  307. }
  308. } else {
  309. //倒计时未开启,初始化默认变量
  310. isCodeDisabled.value = false
  311. recordingCodeTime.value = 0
  312. currentCodeTime.value = totalTime
  313. }
  314. }
  315. //确认审批
  316. const confirmApproval = () => {
  317. if (!resCode.value) {
  318. errorToast('请先获取验证码')
  319. return false
  320. } else if (!smsCode.value) {
  321. errorToast('请先输入验证码')
  322. return false
  323. } else if (resCode.value !== smsCode.value) {
  324. errorToast('验证码错误')
  325. return false
  326. }
  327. //验证码过期时间
  328. saveSmsTimeout({code: resCode.value})
  329. //处理数据
  330. batchTaskApproval('ok')
  331. checkSmsCode()
  332. }
  333. //批量审批
  334. const batchTaskApproval = async (type) => {
  335. let res = {}, t = type === 'ok' ? '审批' : '废除';
  336. uni.showLoading({title: '提交审批中...', mask: true});
  337. if (type === 'ok') {
  338. res = await batchCompleteApprovalTaskApi({
  339. flag: 'OK',
  340. comment: 'OK',
  341. })
  342. } else {
  343. res = await batchCompleteApprovalTaskApi({
  344. flag: 'NO',
  345. comment: argument.value,
  346. })
  347. }
  348. //处理数据
  349. uni.hideLoading();
  350. const {error, code, msg} = res
  351. if (!error && code === 200) {
  352. successToast(`${t}成功`)
  353. cancelApproval()
  354. eventChannel.emit('finish');
  355. setTimeout(() => {
  356. uni.navigateBack()
  357. }, 3000)
  358. } else {
  359. errorToast(`${t}失败:${msg}`)
  360. }
  361. }
  362. //批量审批
  363. const batchCompleteApprovalTaskApi = async (obj = {}) => {
  364. const rows = taskList.value
  365. let taskIds = arrToKey(rows, 'taskId', ',')
  366. let approvalType = arrToKey(rows, 'approvalType', ',')
  367. let formDataId = arrToKey(rows, 'formDataId', ',')
  368. let parallelProcessInstanceIds = arrToKey(rows, 'parallelProcessInstanceId', ',')
  369. return await mainApi.batchCompleteApprovalTask({
  370. ...obj,
  371. taskIds,
  372. approvalType,
  373. formDataId,
  374. parallelProcessInstanceIds
  375. })
  376. }
  377. //废除任务并输入理由
  378. const argument = ref('')
  379. const cancelTaskClick = () => {
  380. argument.value = ''
  381. popupType.value = 3
  382. }
  383. //确认废除
  384. const confirmRepeal = () => {
  385. if (!argument.value) {
  386. errorToast('请先填写废除理由')
  387. return false
  388. }
  389. batchTaskApproval('no')
  390. }
  391. //取消审批
  392. const cancelApproval = () => {
  393. popupType.value = 1
  394. popupRef.value?.close()
  395. }
  396. //取消操作
  397. const cancelClick = () => {
  398. popupType.value = 1
  399. smsCode.value = ''
  400. argument.value = ''
  401. }
  402. </script>
  403. <style lang="scss">
  404. @import "@/style/task/detail.scss";
  405. </style>