detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <div class="ele-body">
  3. <el-form ref="form" :model="form" :rules="rules">
  4. <el-card shadow="never">
  5. <template v-slot:header>
  6. <div class="top-search-group">
  7. <el-input
  8. placeholder="搜索班次"
  9. v-model="form.bc"
  10. clearable
  11. @input="search"
  12. />
  13. <el-button type="primary">搜索</el-button>
  14. </div>
  15. </template>
  16. <el-form-item label="可选班次:" prop="code" style="margin-bottom: 22px">
  17. <div class="bc-warp">
  18. <div
  19. class="item"
  20. @click="handlselected(item)"
  21. :style="`background-color:${classesColor[item.id]}`"
  22. v-for="item in showClassesList"
  23. :key="item.id"
  24. >{{ item.name }}</div
  25. >
  26. <div
  27. class="item"
  28. @click="handlselected(item)"
  29. :style="`background-color:${classesColor[item.id]}`"
  30. v-for="item in defaultbtn"
  31. :key="item.id"
  32. >{{ item.name }}</div
  33. >
  34. </div>
  35. </el-form-item>
  36. <el-form-item label="已选班次:" prop="code" style="margin-bottom: 22px">
  37. <div class="bc-warp">
  38. <el-tag
  39. v-for="tag in selectedClasses"
  40. class="tag"
  41. :style="`background-color:${classesColor[tag.id]}`"
  42. :key="tag.name"
  43. closable
  44. :type="tag.id"
  45. @close="handleClose(tag)"
  46. >
  47. {{ tag.name }}
  48. </el-tag>
  49. </div>
  50. </el-form-item>
  51. </el-card>
  52. <el-card shadow="never">
  53. <ManagementTable
  54. ref="ManagementTable"
  55. :classesColor="classesColor"
  56. :selectedClasses="selectedClasses"
  57. @save="save"
  58. @rest="rest"
  59. ></ManagementTable>
  60. </el-card>
  61. </el-form>
  62. </div>
  63. </template>
  64. <script>
  65. import {
  66. getpullDown,
  67. teamqueuedetailSave,
  68. getByIdteamqueue,
  69. teamqueuedetailupdate
  70. } from '@/api/workforceManagement/schedule';
  71. import ManagementTable from './components/ManagementTable.vue';
  72. import { finishPageTab } from '@/utils/page-tab-util';
  73. import { debounce } from 'throttle-debounce';
  74. export default {
  75. components: {
  76. ManagementTable
  77. },
  78. data() {
  79. const defaultForm = {
  80. bc: '',
  81. checked_bc: ''
  82. };
  83. return {
  84. defaultForm,
  85. // 表单数据
  86. form: { ...defaultForm },
  87. // 表单验证规则
  88. rules: {},
  89. type: '', // add/edit
  90. loading: false,
  91. colorList: [],
  92. showClassesList: [],
  93. classesList: [],
  94. defaultbtn: [
  95. {
  96. name: '休息',
  97. id: '1'
  98. },
  99. {
  100. name: '清除单元格',
  101. id: 'clear'
  102. }
  103. ],
  104. selectedClasses: [],
  105. classesColor: {
  106. 1: '#979d9d',
  107. clear: '#979d9d'
  108. },
  109. addInfo: ''
  110. };
  111. },
  112. computed: {
  113. title() {
  114. switch (this.type) {
  115. case 'add':
  116. return '排班';
  117. break;
  118. case 'edit':
  119. return '排班';
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. },
  126. async created() {
  127. this.search = debounce(500, this.search);
  128. this.init();
  129. await this.getBc();
  130. this.configColor();
  131. },
  132. methods: {
  133. // 初始化数据
  134. init() {
  135. if (this.$route.query.type) {
  136. this.type = this.$route.query.type;
  137. if (this.type == 'add') {
  138. this.addInfo = this.$store.state.team.addInfo;
  139. this.setAddinfo();
  140. } else if (this.type == 'edit') {
  141. // 按班排班
  142. let isSchedule = this.$route.query.isSchedule;
  143. if (isSchedule == '1') {
  144. this.$nextTick(() => {
  145. this.$refs.ManagementTable.changanbp();
  146. });
  147. }
  148. this.getByIdteamqueue(this.$route.query.id);
  149. }
  150. }
  151. },
  152. /* 保存 */
  153. save() {
  154. switch (this.type) {
  155. case 'add':
  156. this.add();
  157. break;
  158. case 'edit':
  159. this.update();
  160. break;
  161. default:
  162. break;
  163. }
  164. },
  165. // 修改
  166. update() {
  167. // 源数据
  168. let personData = this.$refs.ManagementTable.personData;
  169. let teamData = this.$refs.ManagementTable.teamData;
  170. let personDetails = [];
  171. let teamDetails = [];
  172. // 处理人员数据
  173. personData.forEach((n) => {
  174. // 时间数据
  175. let teamQueueTime = [];
  176. for (const [key, value] of Object.entries(n)) {
  177. if (key !== 'item') {
  178. teamQueueTime.push({
  179. date: key,
  180. teamTimeSimple: value.map((el) => {
  181. return {
  182. id: el.id
  183. };
  184. })
  185. });
  186. }
  187. }
  188. personDetails.push({
  189. id: n.item.id,
  190. userId: n.item.userId,
  191. type: n.item.type,
  192. teamId: n.item.teamId,
  193. teamQueueTime
  194. });
  195. });
  196. // 处理班组数据
  197. teamData.forEach((n) => {
  198. let teamQueueTime = [];
  199. for (const [key, value] of Object.entries(n)) {
  200. if (key !== 'item') {
  201. teamQueueTime.push({
  202. date: key,
  203. teamTimeSimple: value.map((el) => {
  204. return {
  205. id: el.id
  206. };
  207. })
  208. });
  209. }
  210. }
  211. teamDetails.push({
  212. id: n.item.id,
  213. type: n.item.type,
  214. teamId: n.item.teamId,
  215. teamQueueTime
  216. });
  217. });
  218. let par = {
  219. id: this.$route.query.id,
  220. personDetails,
  221. teamDetails
  222. };
  223. const loading = this.$messageLoading('正在请求中..');
  224. teamqueuedetailupdate(par).then((msg) => {
  225. this.$message.success(msg);
  226. this.rest();
  227. }).finally(() => {
  228. loading.close();
  229. })
  230. },
  231. // 处理新增信息
  232. setAddinfo() {
  233. if (this.addInfo) {
  234. let addInfo = this.addInfo;
  235. // 人员数据
  236. let personDetails = addInfo.personDetails.map((n) => {
  237. return {
  238. item: {
  239. name: n.userName,
  240. ...n
  241. }
  242. };
  243. });
  244. // 班组数据
  245. let teamDetails = addInfo.teamDetails.map((n) => {
  246. return {
  247. item: {
  248. name: n.teamName,
  249. ...n
  250. }
  251. };
  252. });
  253. this.$nextTick(() => {
  254. this.$refs.ManagementTable.setData(personDetails, teamDetails);
  255. });
  256. }
  257. },
  258. // 新增
  259. add() {
  260. let addInfo = this.$store.state.team.addInfo;
  261. // 源数据
  262. let personData = this.$refs.ManagementTable.personData;
  263. let teamData = this.$refs.ManagementTable.teamData;
  264. let personDetails = [];
  265. let teamDetails = [];
  266. // 处理人员数据
  267. personData.forEach((n) => {
  268. // 时间数据
  269. let teamQueueTime = [];
  270. for (const [key, value] of Object.entries(n)) {
  271. if (key !== 'item') {
  272. teamQueueTime.push({
  273. date: key,
  274. teamTimeSimple: value.map((el) => {
  275. return {
  276. id: el.id
  277. };
  278. })
  279. });
  280. }
  281. }
  282. personDetails.push({
  283. userId: n.item.userId,
  284. type: n.item.type,
  285. teamId: n.item.teamId,
  286. teamQueueTime
  287. });
  288. });
  289. // 处理班组数据
  290. teamData.forEach((n) => {
  291. let teamQueueTime = [];
  292. for (const [key, value] of Object.entries(n)) {
  293. if (key !== 'item') {
  294. teamQueueTime.push({
  295. date: key,
  296. teamTimeSimple: value.map((el) => {
  297. return {
  298. id: el.id
  299. };
  300. })
  301. });
  302. }
  303. }
  304. teamDetails.push({
  305. type: n.item.type,
  306. teamId: n.item.teamId,
  307. });
  308. });
  309. let par = {
  310. name: addInfo.name,
  311. totalPersonNumber: addInfo.totalPersonNumber,
  312. personDetails,
  313. teamDetails
  314. };
  315. const loading = this.$messageLoading('正在请求中..');
  316. teamqueuedetailSave(par).then((msg) => {
  317. this.$message.success(msg);
  318. finishPageTab();
  319. }).finally(() => {
  320. loading.close();
  321. })
  322. },
  323. // 重置
  324. rest() {
  325. if (this.type == 'add') {
  326. this.setAddinfo();
  327. } else if (this.type == 'edit') {
  328. this.getByIdteamqueue(this.$route.query.id);
  329. }
  330. },
  331. // 配置颜色
  332. configColor() {
  333. this.classesList.forEach((element, index) => {
  334. this.$set(this.classesColor, element.id, this.colorList[index]);
  335. });
  336. },
  337. handleClose() {
  338. this.visible = false;
  339. },
  340. handlselected(val) {
  341. if (val.id == '1' || val.id == 'clear') {
  342. this.selectedClasses = [val];
  343. } else {
  344. let result = this.selectedClasses.find((n) => {
  345. return ['1', 'clear'].includes(n.id);
  346. });
  347. if (result) {
  348. this.selectedClasses = [];
  349. }
  350. this.selectedClasses.push(val);
  351. }
  352. // 去重
  353. this.selectedClasses = Array.from(new Set(this.selectedClasses));
  354. },
  355. // 删除标签
  356. handleClose(tag) {
  357. this.selectedClasses.splice(this.selectedClasses.indexOf(tag), 1);
  358. },
  359. // 获取班次
  360. getBc() {
  361. return getpullDown().then((res) => {
  362. this.classesList = res.map((n) => {
  363. return {
  364. id: n.id,
  365. name: `${n.name}(${n.startTime.slice(0, 5)}-${n.endTime.slice(
  366. 0,
  367. 5
  368. )})`
  369. };
  370. });
  371. const len = Math.round(this.classesList.length/5)
  372. const color = [
  373. '#fb6f7b',
  374. '#f59a23',
  375. '#4672ca',
  376. '#2196f3',
  377. '#00bcd4',
  378. '#009688',
  379. ]
  380. for(var i = 0;i<len;i++){
  381. this.colorList = this.colorList.concat(color)
  382. }
  383. this.showClassesList = this.classesList;
  384. });
  385. },
  386. // 搜索
  387. search(val) {
  388. if (val !== '') {
  389. this.showClassesList = this.classesList.filter((n) => {
  390. return n.name.toLowerCase().indexOf(val.toLowerCase()) > -1;
  391. });
  392. } else {
  393. this.showClassesList = this.classesList;
  394. }
  395. },
  396. // 获取排班详情
  397. getByIdteamqueue(id) {
  398. getByIdteamqueue(id).then((res) => {
  399. // 回显数据
  400. //人员数据
  401. let personDetails = res.personDetails.map((n) => {
  402. let item = {
  403. name: n.userName,
  404. ...n
  405. };
  406. delete item.teamQueueTime;
  407. let teamQueueTime = {};
  408. if (n.teamQueueTime) {
  409. n.teamQueueTime.forEach((el) => {
  410. teamQueueTime[el.date] = el.teamTimeSimple;
  411. });
  412. }
  413. return {
  414. item,
  415. ...teamQueueTime
  416. };
  417. });
  418. // 班组数据
  419. let teamDetails = res.teamDetails.map((n) => {
  420. let item = {
  421. name: n.teamName,
  422. ...n
  423. };
  424. delete item.teamQueueTime;
  425. let teamQueueTime = {};
  426. if (n.teamQueueTime) {
  427. n.teamQueueTime.forEach((el) => {
  428. teamQueueTime[el.date] = el.teamTimeSimple;
  429. });
  430. }
  431. return {
  432. item,
  433. ...teamQueueTime
  434. };
  435. });
  436. this.$nextTick(() => {
  437. this.$refs.ManagementTable.setData(personDetails, teamDetails);
  438. });
  439. });
  440. }
  441. }
  442. };
  443. </script>
  444. <style lang="scss" scoped>
  445. .location-warp {
  446. display: flex;
  447. .detail {
  448. margin-left: 10px;
  449. }
  450. }
  451. .top-search-group {
  452. max-width: 400px;
  453. display: flex;
  454. :deep(.el-input input) {
  455. border-top-right-radius: 0;
  456. border-bottom-right-radius: 0;
  457. border-right-width: 0;
  458. }
  459. .el-button {
  460. border-top-left-radius: 0;
  461. border-bottom-left-radius: 0;
  462. }
  463. }
  464. .bc-warp {
  465. display: flex;
  466. flex-wrap:wrap;
  467. .item {
  468. height: 34px;
  469. padding: 0 10px;
  470. color: #fff;
  471. border-radius: 4px;
  472. cursor: pointer;
  473. margin-right: 10px;
  474. margin-bottom:10px;
  475. }
  476. .item + .item {
  477. margin-right: 10px;
  478. margin-bottom:10px;
  479. }
  480. .tag {
  481. color: #fff;
  482. height: 34px;
  483. border: none;
  484. line-height: 34px;
  485. margin:0 10px 10px 0;
  486. :deep(.el-tag__close) {
  487. color: #fff;
  488. }
  489. }
  490. }
  491. </style>