index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="content">
  3. <!-- <button class="btn-add" @click="toAdd" type="primary">新增</button> -->
  4. <uni-calendar
  5. class="uni-calendar--hook"
  6. :selected="info.selected"
  7. :showMonth="false"
  8. @change="change"
  9. @monthSwitch="monthSwitch"
  10. >
  11. <text @click="toAdd">新增工时</text>
  12. </uni-calendar>
  13. <!-- <button @click="showModal" type="primary">新增</button> -->
  14. <uni-collapse ref="collapse">
  15. <uni-collapse-item
  16. v-for="collapse in collapseList"
  17. :key="collapse.name"
  18. :title="collapse.name"
  19. >
  20. <view class="content">
  21. <uni-card
  22. v-for="(item, index) in collapse.children"
  23. :key="index"
  24. :title="allType[item.type_id] && allType[item.type_id].name"
  25. >
  26. <view class="uni-body">
  27. <view class="detail-item" v-if="item.project_id != '0'">
  28. <view class="detail-label">所属项目</view>
  29. <view class="detail-value">
  30. {{ getProject(item.project_id) }}
  31. </view>
  32. </view>
  33. <view class="detail-item">
  34. <view class="detail-label">审核状态</view>
  35. <view
  36. class="detail-value"
  37. :style="{ color: stateColor[item.audit_state] }"
  38. >
  39. {{ auditState[item.audit_state] }}
  40. </view>
  41. </view>
  42. <view class="detail-item" v-if="item.audit_state == 3">
  43. <view class="detail-label">拒绝原因</view>
  44. <view class="detail-value">
  45. {{ item.audit_desc }}
  46. </view>
  47. </view>
  48. <view class="detail-item">
  49. <view class="detail-label">工时</view>
  50. <view class="detail-value">
  51. {{ item.workload }}
  52. </view>
  53. </view>
  54. </view>
  55. <view
  56. v-if="item.audit_state == 0 || item.audit_state == 3"
  57. slot="actions"
  58. class="card-actions"
  59. >
  60. <view class="card-actions-item" @click="onHandleSave(item)">
  61. <text class="card-actions-item-text">修改工时</text>
  62. </view>
  63. <view class="card-actions-item" @click="onHandleAudit(item, 0)">
  64. <text class="card-actions-item-text">上报审批</text>
  65. </view>
  66. </view>
  67. </uni-card>
  68. </view>
  69. </uni-collapse-item>
  70. </uni-collapse>
  71. <uni-popup ref="inputDialog" type="dialog">
  72. <uni-popup-dialog
  73. ref="inputClose"
  74. mode="input"
  75. title="填入工时"
  76. :value="currentItem.workload === 0 ? '' : currentItem.workload"
  77. @confirm="dialogInputConfirm"
  78. ></uni-popup-dialog>
  79. </uni-popup>
  80. <uni-popup ref="auditDialog" type="dialog">
  81. <uni-popup-dialog
  82. type="info"
  83. title="提示"
  84. content="是否确认提交审批"
  85. @confirm="auditConfirm"
  86. ></uni-popup-dialog>
  87. </uni-popup>
  88. <!-- <AddModal
  89. ref="addModal"
  90. @submit="onSubmit"
  91. :projectList="projectList"
  92. :typeList="typeList"
  93. /> -->
  94. <view class="group">
  95. <button @click="onHandleAudit({}, 2)" type="primary">上报本月工时</button>
  96. <button
  97. v-show="collapseList.length > 0"
  98. @click="onHandleAudit({}, 1)"
  99. class="button"
  100. >
  101. 上报今日工时
  102. </button>
  103. </view>
  104. </view>
  105. </template>
  106. <script>
  107. import {
  108. queryAllWorkType,
  109. queryWorkHours,
  110. addWorkHours,
  111. addAuthWorkHours,
  112. queryProject,
  113. } from "@/services/workload";
  114. import AddModal from "./AddModal.vue";
  115. import moment from "moment";
  116. import { mapState } from "vuex";
  117. export default {
  118. components: { AddModal },
  119. data() {
  120. return {
  121. info: {
  122. lunar: true,
  123. range: true,
  124. insert: false,
  125. selected: [],
  126. },
  127. currentItem: {},
  128. projectList: [],
  129. currentList: [],
  130. stateColor: {
  131. 1: "#1890ff",
  132. 2: "#a0d911",
  133. 3: "#f5222d",
  134. },
  135. auditState: {
  136. 0: "未提审",
  137. 1: "待审核",
  138. 2: "已通过",
  139. 3: "已拒绝",
  140. },
  141. auditType: 0,
  142. day: moment().format("YYYY-MM-DD"),
  143. monthDate: moment(),
  144. };
  145. },
  146. onNavigationBarButtonTap(e) {
  147. uni.navigateTo({
  148. url: "../audit/index",
  149. });
  150. },
  151. onLoad() {
  152. this.init();
  153. },
  154. onShow() {
  155. this.queryWorkHours();
  156. },
  157. computed: {
  158. ...mapState(["allType", "typeList"]),
  159. collapseList() {
  160. const allType = this.allType;
  161. let data = {};
  162. this.currentList.forEach((item) => {
  163. let pid = allType[item.type_id]?.parent_id;
  164. if (!data[pid]) data[pid] = [];
  165. data[pid].push(item);
  166. });
  167. return Object.keys(data).map((pid) => ({
  168. name: allType[pid]?.name,
  169. children: data[pid],
  170. }));
  171. },
  172. },
  173. methods: {
  174. async init() {
  175. await this.$store.dispatch("getType");
  176. this.projectList = await queryProject();
  177. this.queryWorkHours();
  178. },
  179. change(e) {
  180. console.log(e);
  181. this.day = e.fulldate;
  182. this.currentList = e.extraInfo.list || [];
  183. },
  184. monthSwitch(e) {
  185. console.log(e);
  186. this.monthDate = moment(`${e.year}-${e.month}-01`, "YYYY-MM-DD");
  187. console.log(this.monthDate);
  188. this.queryWorkHours();
  189. // this.day = e.fulldate;
  190. // this.currentList = e.extraInfo.list || [];
  191. },
  192. getProject(id) {
  193. let p = this.projectList.find((p) => p.ID == id);
  194. if (!p) return "";
  195. return p.Name;
  196. },
  197. onHandleSave(item) {
  198. this.currentItem = item;
  199. this.$refs.inputDialog.open();
  200. },
  201. onHandleAudit(item, type) {
  202. this.currentItem = item;
  203. this.auditType = type;
  204. this.$refs.auditDialog.open();
  205. },
  206. async dialogInputConfirm(workload) {
  207. let item = this.currentItem;
  208. if (isNaN(workload)) {
  209. uni.showToast({
  210. title: "工时必须输入数字!",
  211. icon: "none",
  212. });
  213. return;
  214. }
  215. let decimal = workload.split(".")[1];
  216. if (decimal && decimal != 5) {
  217. uni.showToast({
  218. title: "工时最小精确到半小时!",
  219. icon: "none",
  220. });
  221. return;
  222. }
  223. let currentWorkload = this.currentList.reduce((total, temp) => {
  224. if (temp.id == item.id) return total;
  225. return total + temp.workload;
  226. }, 0);
  227. if (currentWorkload + Number(workload) > 8) {
  228. uni.showToast({
  229. title: "每日工时不能超过8小时!",
  230. icon: "none",
  231. });
  232. return;
  233. }
  234. let params = [
  235. {
  236. type_id: Number(item.type_id),
  237. comment: "",
  238. data: [
  239. {
  240. id: item.id,
  241. project_id: Number(item.project_id),
  242. workload: Number(workload),
  243. day: item.time,
  244. },
  245. ],
  246. },
  247. ];
  248. // 保存
  249. await addWorkHours(params);
  250. await this.queryWorkHours();
  251. },
  252. async auditConfirm() {
  253. let type = this.auditType;
  254. let params;
  255. const getData = (item) => {
  256. return {
  257. type_id: Number(item.type_id),
  258. data: [
  259. {
  260. id: item.id,
  261. project_id: item.project_id,
  262. workload: item.workload,
  263. day: item.day,
  264. },
  265. ],
  266. };
  267. };
  268. if (type == 0) {
  269. params = [getData(this.currentItem)];
  270. } else if (type == 1) {
  271. let auditList = this.currentList.filter(
  272. (item) => item.audit_state == 0 || item.audit_state == 3
  273. );
  274. if (auditList.length == 0) {
  275. uni.showToast({
  276. title: "本日没有待上报工时!",
  277. icon: "none",
  278. });
  279. return;
  280. }
  281. params = auditList.map((item) => getData(item));
  282. } else {
  283. let auditList = [];
  284. this.info.selected.forEach((s) => {
  285. if (s.list) {
  286. auditList = auditList.concat(
  287. s.list.filter(
  288. (item) => item.audit_state == 0 || item.audit_state == 3
  289. )
  290. );
  291. }
  292. });
  293. if (auditList.length == 0) {
  294. uni.showToast({
  295. title: "本月没有待上报工时!",
  296. icon: "none",
  297. });
  298. return;
  299. }
  300. params = auditList.map((item) => getData(item));
  301. }
  302. await addAuthWorkHours(params);
  303. this.queryWorkHours();
  304. this.$refs.auditDialog.close();
  305. },
  306. async queryWorkHours() {
  307. let date = this.monthDate;
  308. let s_time = date.format("YYYY-MM-01 00:00:00");
  309. let e_time = moment(s_time)
  310. .add("month", 1)
  311. .add("days", -1)
  312. .format("YYYY-MM-DD 23:59:59");
  313. const user = uni.getStorageSync("user");
  314. const data = await queryWorkHours({ user_id: user.ID, s_time, e_time });
  315. let selected = [];
  316. Object.keys(data).map((day) => {
  317. let list = data[day];
  318. let total = 0;
  319. let canEdit = false;
  320. list.forEach((item) => {
  321. total += item.workload;
  322. if (item.audit_state == 3 || item.audit_state == 0) {
  323. canEdit = true;
  324. }
  325. });
  326. selected.push({
  327. date: day,
  328. info: `${total} 小时`,
  329. list: list,
  330. color: canEdit ? "#e43d33" : "",
  331. });
  332. if (this.day == day) {
  333. this.currentList = list;
  334. }
  335. });
  336. this.info.selected = selected;
  337. },
  338. toAdd() {
  339. uni.navigateTo({
  340. url: `./add?day=${this.day}`,
  341. });
  342. },
  343. // async onSubmit(values) {
  344. // let params = [
  345. // {
  346. // type_id: Number(values.subTypeId),
  347. // comment: "",
  348. // data: [
  349. // {
  350. // project_id: Number(values.projectId),
  351. // workload: 0,
  352. // day: this.day,
  353. // },
  354. // ],
  355. // },
  356. // ];
  357. // // 新增
  358. // await addWorkHours(params);
  359. // this.queryWorkHours();
  360. // },
  361. // showModal() {
  362. // this.$refs.addModal.open();
  363. // },
  364. },
  365. };
  366. </script>
  367. <style lang="scss" scoped>
  368. .content {
  369. padding: 30rpx;
  370. padding-top: 0;
  371. padding-bottom: 60px;
  372. }
  373. // .button {
  374. // margin-right: 20rpx;
  375. // }
  376. .card-actions {
  377. display: flex;
  378. flex-direction: row;
  379. justify-content: space-around;
  380. align-items: center;
  381. height: 45px;
  382. border-top: 1px #eee solid;
  383. }
  384. .detail-item {
  385. margin: 12rpx 0;
  386. display: flex;
  387. justify-content: space-between;
  388. align-items: flex-start;
  389. .detail-value {
  390. max-width: 60%;
  391. text-align: right;
  392. }
  393. }
  394. .group {
  395. width: 100%;
  396. display: flex;
  397. position: fixed;
  398. justify-content: flex-start;
  399. bottom: 0;
  400. left: 0;
  401. button {
  402. width: 50%;
  403. border-radius: 0;
  404. margin: inherit;
  405. }
  406. }
  407. </style>