detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. <template v-for="(item, index) in taskList" :key="index">
  86. <view class="relative mt-3" :class="item.id === taskInfo.id ? 'text-blue' :''" @click="taskClick(item)">{{item.taskName}}</view>
  87. </template>
  88. </view>
  89. </uni-popup>
  90. <!-- 表格列表 -->
  91. <uni-popup ref="popupTableRef" type="bottom">
  92. <view class="relative bg-white h-50vh hc-p br-t">
  93. <view class="text-black mb-3 text-center">选择表格数据</view>
  94. <template v-for="(item, index) in taskInfo.approvalFileList" :key="index">
  95. <view class="relative mt-3" :class="item.id === taskFileInfo.id ? 'text-blue' :''" @click="taskFileClick(item)">{{item.fileName}}</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, successToast, toPdfPreview} 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. uni.setNavigationBarTitle({title: '审批任务'})
  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. //切换任务
  146. const taskClick = (item) => {
  147. taskInfo.value = item
  148. taskFileInfo.value = item.approvalFileList[0]
  149. popupTaskRef.value?.close()
  150. }
  151. //切换PDF
  152. const taskFileInfo = ref({})
  153. const taskFileClick = (item) => {
  154. taskFileInfo.value = item
  155. popupTableRef.value?.close()
  156. }
  157. //获取任务详情
  158. const getTaskInfo = async () => {
  159. const rows = taskList.value
  160. if (rows.length <= 0) return false
  161. //处理详情数据
  162. for (let i = 0; i < rows.length; i++) {
  163. const res = await queryApprovalParameter(rows[i])
  164. rows[i].approvalFileList = res.approvalFileList
  165. }
  166. taskInfo.value = getObjValue(rows[0])
  167. taskFileInfo.value = getObjValue(rows[0].approvalFileList[0])
  168. taskList.value = rows
  169. }
  170. //获取审批详情
  171. const queryApprovalParameter = async ({parallelProcessInstanceId, formDataId, approvalType}) => {
  172. const { data } = await mainApi.queryApprovalParameter({
  173. parallelProcessInstanceId: parallelProcessInstanceId ?? '',
  174. formDataId: formDataId ?? '',
  175. approvalType: approvalType ?? ''
  176. })
  177. const res = getObjValue(data)
  178. const list = getArrValue(res.approvalFileList)
  179. for (let i = 0; i < list.length; i++) {
  180. list[i].fileNum = await queryPDFnumApi(list[i]?.fileUrl)
  181. }
  182. res.approvalFileList = list
  183. return getObjValue(data)
  184. }
  185. //查询PDF数量
  186. const queryPDFnumApi = async (pdfUrl) => {
  187. const { data } = await mainApi.queryPDFnum({
  188. url: pdfUrl
  189. })
  190. return data ? data : 0
  191. }
  192. //任务列表
  193. const popupTaskRef = ref(null)
  194. const taskPopupClick = () => {
  195. popupTaskRef.value?.open()
  196. }
  197. //表格列表
  198. const popupTableRef = ref(null)
  199. const tablePopupClick = () => {
  200. popupTableRef.value?.open()
  201. }
  202. //审批弹窗
  203. const popupRef = ref(null)
  204. const popupType = ref(1)
  205. const approveClick = () => {
  206. popupType.value = 1
  207. popupRef.value?.open()
  208. }
  209. //短信验证有效期
  210. const smsCodeTime = ref('')
  211. const checkSmsCode = async () => {
  212. const {data} = await mainApi.checkSmsCode()
  213. smsCodeTime.value = isString(data) ? data : '';
  214. }
  215. //验证短信有效期
  216. const isCheckSmsCodeTime = () => {
  217. const smsTime = smsCodeTime.value;
  218. if (!smsTime) return true
  219. const toDayTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
  220. return dayjs(smsTime).isBefore(toDayTime)
  221. }
  222. //同意审批短信验证
  223. const smsCode = ref('')
  224. const agreeClick = async () => {
  225. const showAuth = isCheckSmsCodeTime()
  226. if (showAuth) {
  227. smsCode.value = ''
  228. popupType.value = 2
  229. } else {
  230. const {error, code, msg, data} = await checkFlowUserIsExistPfxFile()
  231. if (!error && code === 200 && data === true) {
  232. const showAuth = isCheckSmsCodeTime()
  233. if (showAuth) {
  234. smsCode.value = ''
  235. popupType.value = 2
  236. } else {
  237. batchTaskApproval('ok').then()
  238. }
  239. } else {
  240. errorToast(msg)
  241. cancelApproval()
  242. }
  243. }
  244. }
  245. //验证码倒计时
  246. const totalTime = 60 //总时间,单位秒
  247. const isCodeDisabled = ref(false) //是否开启倒计时
  248. const recordingCodeTime = ref(0) //记录时间变量
  249. const currentCodeTime = ref(0) //显示时间变量
  250. //获取短信验证码
  251. const resCode = ref('')
  252. const getCodeClick = async () => {
  253. const {phone} = userInfo.value
  254. if (!phone) {
  255. errorToast('您的手机号是空的,无法获取验证码')
  256. return false
  257. }
  258. const { error, code, msg } = await sendNotice({
  259. phone: phone
  260. })
  261. //处理数据
  262. if (!error && code === 200 && msg) {
  263. resCode.value = msg
  264. //把显示时间设为总时间
  265. currentCodeTime.value = totalTime
  266. //开始倒计时
  267. isCodeDisabled.value = true
  268. //执行倒计时
  269. checkingTime()
  270. successToast('发送成功')
  271. } else {
  272. resCode.value = ''
  273. errorToast(msg)
  274. }
  275. }
  276. //倒计时
  277. const checkingTime = () => {
  278. //判断是否开启
  279. if (isCodeDisabled.value) {
  280. //判断显示时间是否已到0,判断记录时间是否已到总时间
  281. if (currentCodeTime.value > 0 && recordingCodeTime.value <= totalTime) {
  282. //记录时间增加 1
  283. recordingCodeTime.value++
  284. //显示时间,用总时间 - 记录时间
  285. currentCodeTime.value = totalTime - recordingCodeTime.value
  286. //1秒钟后,再次执行本方法
  287. setTimeout(() => {
  288. checkingTime()
  289. }, 1000)
  290. } else {
  291. //时间已完成,还原相关变量
  292. isCodeDisabled.value = false //关闭倒计时
  293. recordingCodeTime.value = 0 //记录时间为0
  294. currentCodeTime.value = totalTime //显示时间为总时间
  295. }
  296. } else {
  297. //倒计时未开启,初始化默认变量
  298. isCodeDisabled.value = false
  299. recordingCodeTime.value = 0
  300. currentCodeTime.value = totalTime
  301. }
  302. }
  303. //确认审批
  304. const confirmApproval = () => {
  305. if (!resCode.value) {
  306. errorToast('请先获取验证码')
  307. return false
  308. } else if (!smsCode.value) {
  309. errorToast('请先输入验证码')
  310. return false
  311. } else if (resCode.value !== smsCode.value) {
  312. errorToast('验证码错误')
  313. return false
  314. }
  315. //验证码过期时间
  316. saveSmsTimeout({code: resCode.value})
  317. //处理数据
  318. batchTaskApproval('ok')
  319. checkSmsCode()
  320. }
  321. //批量审批
  322. const batchTaskApproval = async (type) => {
  323. let res = {}, t = type === 'ok' ? '审批' : '废除';
  324. uni.showLoading({title: '提交审批中...', mask: true});
  325. if (type === 'ok') {
  326. res = await batchCompleteApprovalTaskApi({
  327. flag: 'OK',
  328. comment: 'OK',
  329. })
  330. } else {
  331. res = await batchCompleteApprovalTaskApi({
  332. flag: 'NO',
  333. comment: argument.value,
  334. })
  335. }
  336. //处理数据
  337. uni.hideLoading();
  338. const {error, code, msg} = res
  339. if (!error && code === 200) {
  340. successToast(`${t}成功`)
  341. cancelApproval()
  342. eventChannel.emit('finish');
  343. setTimeout(() => {
  344. uni.navigateBack()
  345. }, 3000)
  346. } else {
  347. errorToast(`${t}失败:${msg}`)
  348. }
  349. }
  350. //批量审批
  351. const batchCompleteApprovalTaskApi = async (obj = {}) => {
  352. const rows = taskList.value
  353. let taskIds = arrToKey(rows, 'taskId', ',')
  354. let approvalType = arrToKey(rows, 'approvalType', ',')
  355. let formDataId = arrToKey(rows, 'formDataId', ',')
  356. let parallelProcessInstanceIds = arrToKey(rows, 'parallelProcessInstanceId', ',')
  357. return await mainApi.batchCompleteApprovalTask({
  358. ...obj,
  359. taskIds,
  360. approvalType,
  361. formDataId,
  362. parallelProcessInstanceIds
  363. })
  364. }
  365. //废除任务并输入理由
  366. const argument = ref('')
  367. const cancelTaskClick = () => {
  368. argument.value = ''
  369. popupType.value = 3
  370. }
  371. //确认废除
  372. const confirmRepeal = () => {
  373. if (!argument.value) {
  374. errorToast('请先填写废除理由')
  375. return false
  376. }
  377. batchTaskApproval('no')
  378. }
  379. //取消审批
  380. const cancelApproval = () => {
  381. popupType.value = 1
  382. popupRef.value?.close()
  383. }
  384. //取消操作
  385. const cancelClick = () => {
  386. popupType.value = 1
  387. smsCode.value = ''
  388. argument.value = ''
  389. }
  390. //查看PDF
  391. const viewPdfClick = () => {
  392. const {fileUrl} = taskFileInfo.value
  393. if (fileUrl) {
  394. // #ifdef H5
  395. window.open(url, '_blank')
  396. // #endif
  397. // #ifdef APP-PLUS
  398. uni.navigateTo({
  399. url: '/pages/index/preview?url=' + encodeURIComponent(fileUrl)
  400. });
  401. // #endif
  402. } else {
  403. errorToast('PDF文件不存在')
  404. }
  405. }
  406. </script>
  407. <style lang="scss">
  408. @import "@/style/task/detail.scss";
  409. </style>