detail.vue 15 KB

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