punchin-detail.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <main-layout :showHome="true" :showBack="true">
  3. <uni-calendar
  4. :start-date="punchInData.calendar.startDate"
  5. :end-date="punchInData.calendar.endDate"
  6. :selected="punchInData.selected"
  7. @change="calendarChange"
  8. @monthSwitch="calendarMonthSwitchChange"/>
  9. <viwe class="info-box">
  10. <view class="left">打卡:{{punchInData.statistics.punchInTimes}}次</view>
  11. <view class="right">全勤率:{{punchInData.statistics.punchInRate}}80%</view>
  12. </viwe>
  13. <view class="log-box">
  14. <uni-section title="打卡记录" type="line">
  15. <uni-list>
  16. <uni-list-item title="2024-12-07 08:30:22 福彩 幸运88 中奖100元" time="2020-02-02 20:20" ></uni-list-item>
  17. <uni-list-item title="2024-12-07 08:30:22 福彩 幸运88 中奖100元" time="2020-02-02 20:20" ></uni-list-item>
  18. <uni-list-item title="2024-12-07 08:30:22 福彩 幸运88 中奖100元" time="2020-02-02 20:20" ></uni-list-item>
  19. </uni-list>
  20. </uni-section>
  21. </view>
  22. <uni-fab ref="fabBtn" :content="fabContent" :pattern="fabPattern" horizontal="right" vertical="bottom" direction="vertical" @trigger="trigger"/>
  23. <!-- 删除确认框 -->
  24. <uni-popup ref="deleteDialog" type="dialog">
  25. <uni-popup-dialog mode="base" :before-close="true"
  26. title="删除提示" content="确认删除当前任务?"
  27. @confirm="deleteDialogConfirm" @close="deleteDialogClose"></uni-popup-dialog>
  28. </uni-popup>
  29. <!-- 归档确认框 -->
  30. <uni-popup ref="archiveDialog" type="dialog">
  31. <uni-popup-dialog mode="base" :before-close="true"
  32. title="归档提示" content="确认归档当前任务?"
  33. @confirm="archiveDialogConfirm" @close="archiveDialogClose"></uni-popup-dialog>
  34. </uni-popup>
  35. <!-- 撤销确认框 -->
  36. <uni-popup ref="revokeDialog" type="dialog">
  37. <uni-popup-dialog mode="base" :before-close="true"
  38. title="撤销提示" content="确认撤销打卡?"
  39. @confirm="revokeDialogConfirm" @close="revokeDialogClose"></uni-popup-dialog>
  40. </uni-popup>
  41. <!-- 补卡弹出框 -->
  42. <uni-popup ref="remakeInputDialog" type="dialog" :is-mask-click="false">
  43. <uni-popup-dialog
  44. mode="input"
  45. :before-close="true"
  46. title="补卡"
  47. @confirm="remakeFormConfirm"
  48. @close="remakeFormClose">
  49. <view style="width: 100%;">
  50. <uni-forms ref="timeTrackForm" :modelValue="remakeFormData" :rules="remakeFormRules" label-position="top" :label-width="150">
  51. <uni-forms-item name="punchInDate">
  52. <picker mode="date" :value="remakeFormData.punchInDate" @change="remakePunchInChange">
  53. <view class="pick-box">{{remakeFormData.punchInDate}}</view>
  54. </picker>
  55. </uni-forms-item>
  56. </uni-forms>
  57. </view>
  58. </uni-popup-dialog>
  59. </uni-popup>
  60. </main-layout>
  61. </template>
  62. <script setup>
  63. import { ref } from 'vue';
  64. import { onLoad } from '@dcloudio/uni-app';
  65. import router from '@/common/constants/router';
  66. import { punchInApi } from '@/service/apis.js';
  67. // 组件
  68. const fabBtn = ref(null);
  69. /**
  70. * 删除弹出框
  71. */
  72. const deleteDialog = ref(null);
  73. /**
  74. * 归档弹出框
  75. */
  76. const archiveDialog = ref(null);
  77. /**
  78. * 补卡弹出框
  79. */
  80. const remakeInputDialog = ref(null);
  81. /**
  82. * 补卡表单
  83. */
  84. const remakeForm = ref(null);
  85. /**
  86. * 撤销弹出框
  87. */
  88. const revokeDialog = ref(null);
  89. // 属性
  90. /**
  91. * 任务ID
  92. */
  93. const punchInId = ref(null);
  94. /**
  95. * 悬浮菜单样式
  96. */
  97. const fabPattern = ref({
  98. icon: 'compose'
  99. });
  100. /**
  101. * 悬浮按钮菜单
  102. */
  103. const fabContent = [{
  104. text: '删除',
  105. active: false,
  106. iconPath: '/static/delete.svg',
  107. selectedIconPath: '/static/delete-active.svg',
  108. func: "delete"
  109. },
  110. {
  111. text: '归档',
  112. active: false,
  113. iconPath: '/static/archive.svg',
  114. selectedIconPath: '/static/archive-active.svg',
  115. func: "archive"
  116. },
  117. {
  118. text: '撤销',
  119. active: false,
  120. iconPath: '/static/revoke.svg',
  121. selectedIconPath: '/static/revoke_active.svg',
  122. func: "revoke"
  123. },
  124. {
  125. text: '补卡',
  126. active: false,
  127. iconPath: '/static/append.svg',
  128. selectedIconPath: '/static/append-active.svg',
  129. func: "remake"
  130. },
  131. {
  132. text: '编辑',
  133. active: false,
  134. iconPath: '/static/edit.svg',
  135. selectedIconPath: '/static/edit-active.svg',
  136. func: "edit"
  137. }
  138. ];
  139. /**
  140. * 补卡表单数据
  141. */
  142. const remakeFormData = ref({
  143. punchIndate: '2024-12-16'
  144. });
  145. /**
  146. * 补卡表单校验规则
  147. */
  148. const remakeFormRules = ref({
  149. punchInDate: {
  150. rules: [{
  151. required: true,
  152. errorMessage: '补卡日期不能为空'
  153. }]
  154. }
  155. });
  156. /**
  157. * 打卡日历数据
  158. */
  159. const punchInData = ref({
  160. calendar: {
  161. startDate: '2024-12-01',
  162. endDate: '2024-12-31',
  163. selectd: []
  164. },
  165. statistics: {
  166. punchInTimes: 0,
  167. punchInRate: 0
  168. },
  169. selected: [{date: '2024-12-13', info: '签到', data: { custom: '自定义信息', name: '自定义消息头', id: 12123 }}]
  170. });
  171. // 方法
  172. /**
  173. * 悬浮按钮点击事件
  174. */
  175. const trigger = (e) => {
  176. if (e.item.func == 'delete') {
  177. deleteDialog.value.open();
  178. }
  179. if (e.item.func == 'archive') {
  180. archiveDialog.value.open();
  181. }
  182. if (e.item.func == 'revoke') {
  183. revokeDialog.value.open();
  184. }
  185. if (e.item.func == 'remake') {
  186. // 将日期减去1天,得到昨天的日期
  187. const yesterday = new Date();
  188. yesterday.setDate(yesterday.getDate() - 1);
  189. // 获取年、月、日
  190. const year = yesterday.getFullYear();
  191. const month = (yesterday.getMonth() + 1).toString().padStart(2, '0'); // 月份是从0开始的,所以加1
  192. const day = yesterday.getDate().toString().padStart(2, '0'); // 日期格式化为两位数
  193. // 初始化上一轮的数据
  194. remakeFormData.value = {
  195. punchInId: punchInId.value,
  196. punchInDate: `${year}-${month}-${day}`
  197. };
  198. remakeInputDialog.value.open();
  199. }
  200. if (e.item.func == 'edit') {
  201. uni.navigateTo({
  202. url: router.PUNCHIN_EDIT_URL + "?id=" + punchInId.value
  203. });
  204. }
  205. fabBtn.value.close();
  206. }
  207. /**
  208. * 删除确认
  209. */
  210. const deleteDialogConfirm = async () => {
  211. punchInApi.deletePunchIn({id: punchInId.value})
  212. .then(ret => {
  213. deleteDialog.value.close();
  214. uni.showToast({
  215. title: '删除成功',
  216. icon: 'success'
  217. });
  218. setTimeout(() => {
  219. uni.navigateBack();
  220. }, 1000);
  221. })
  222. .catch(err => {
  223. uni.showToast({
  224. title: '删除失败',
  225. icon: 'error'
  226. });
  227. });
  228. }
  229. /**
  230. * 删除取消
  231. */
  232. const deleteDialogClose = () => {
  233. deleteDialog.value.close();
  234. }
  235. /**
  236. * 归档确认
  237. */
  238. const archiveDialogConfirm = async () => {
  239. punchInApi.archivePunchIn({id: punchInId.value})
  240. .then(ret => {
  241. archiveDialog.value.close();
  242. uni.showToast({
  243. title: '归档成功',
  244. icon: 'success'
  245. });
  246. setTimeout(() => {
  247. uni.navigateBack();
  248. }, 1000);
  249. })
  250. .catch(err => {
  251. uni.showToast({
  252. title: '归档失败',
  253. icon: 'error'
  254. });
  255. });
  256. }
  257. /**
  258. * 归档取消
  259. */
  260. const archiveDialogClose = () => {
  261. archiveDialog.value.close();
  262. }
  263. /**
  264. *补卡表单提交
  265. */
  266. const remakeFormConfirm = async () => {
  267. remakeForm.value.validate(['punchInId']).then(data => {
  268. return punchInApi.revokePunchIn(data);
  269. }).then(e => {
  270. remakeInputDialog.value.close();
  271. uni.showToast({
  272. title: '补卡成功',
  273. icon: 'success'
  274. });
  275. setTimeout(() => {
  276. // TODO 这里要刷新页面数据
  277. }, 1000);
  278. }).catch(err => {
  279. uni.showToast({
  280. title: '补卡失败',
  281. icon: 'error'
  282. });
  283. })
  284. }
  285. /**
  286. * 补卡表单取消
  287. */
  288. const remakeFormClose = async () => {
  289. remakeInputDialog.value.close();
  290. }
  291. /**
  292. * 撤销确认
  293. */
  294. const revokeDialogConfirm = async () => {
  295. punchInApi.revokePunchIn({id: punchInId.value})
  296. .then(ret => {
  297. revokeDialog.value.close();
  298. uni.showToast({
  299. title: '撤销成功',
  300. icon: 'success'
  301. });
  302. // TODO 这里要重新加载任务
  303. })
  304. .catch(err => {
  305. uni.showToast({
  306. title: '撤销失败',
  307. icon: 'error'
  308. });
  309. });
  310. }
  311. /**
  312. * 撤销取消
  313. */
  314. const revokeDialogClose = () => {
  315. revokeDialog.value.close();
  316. }
  317. const calendarChange = (e) => {
  318. console.log(e);
  319. }
  320. const calendarMonthSwitchChange = (e) => {
  321. console.log(e);
  322. }
  323. onLoad(async (e) => {
  324. if (e.id) {
  325. punchInId.value = e.id;
  326. }
  327. });
  328. </script>
  329. <style lang="scss" scoped>
  330. .info-box, .log-box {
  331. margin-top: 24rpx;
  332. }
  333. .info-box {
  334. display: flex;
  335. background-color: #FFFFFF;
  336. padding: 20rpx 10rpx;
  337. .left, .right {
  338. flex: 1;
  339. display: flex;
  340. align-items: center;
  341. justify-content: center;
  342. }
  343. }
  344. </style>