detail.vue 14 KB

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