edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <template>
  2. <view class="container">
  3. <uni-forms ref="form" :rules="rules" :model="form" labelWidth="80px" :label-position="alignment">
  4. <uni-forms-item label="请假人">
  5. <uni-easyinput v-model="userInfo.nickname" disabled />
  6. </uni-forms-item>
  7. <uni-forms-item label="部门">
  8. <uni-easyinput v-model="userInfo.deptName" disabled />
  9. </uni-forms-item>
  10. <uni-forms-item label="职位">
  11. <uni-easyinput v-model="userInfo.position" disabled />
  12. </uni-forms-item>
  13. <uni-forms-item label="手机号">
  14. <uni-easyinput v-model="userInfo.mobile" disabled />
  15. </uni-forms-item>
  16. <uni-forms-item label="请假类型" required name="leaveType">
  17. <uni-data-select v-model="form.leaveType" :localdata="leaveTypeList">
  18. </uni-data-select>
  19. </uni-forms-item>
  20. <uni-forms-item label="开始日期" required name="startDate">
  21. <uni-datetime-picker type="date" v-model="form.startDate" @change="upDayStart" />
  22. <uni-data-checkbox v-model="form.startTime" :localdata="timeType" @change="upDay" />
  23. </uni-forms-item>
  24. <uni-forms-item label="结束日期" required name="endDate">
  25. <uni-datetime-picker type="date" v-model="form.endDate" @change="upDayEnd" />
  26. <uni-data-checkbox v-model="form.endTime" :localdata="timeType" @change="upDay" />
  27. </uni-forms-item>
  28. <uni-forms-item label="请假天数" required name="day">
  29. <uni-easyinput v-model="form.day" placeholder="请输入" />
  30. </uni-forms-item>
  31. <uni-forms-item label="请假原因" required name="reason">
  32. <uni-easyinput maxlength="200" type="textarea" v-model="form.reason" placeholder="请输入" />
  33. </uni-forms-item>
  34. <uni-forms-item label="附件">
  35. <view class="upload-wrap">
  36. <button type="primary" size="mini" @click="handleUploadClick">点击上传</button>
  37. <xe-upload ref="XeUpload" :options="uploadOptions" @callback="handleUploadCallback"></xe-upload>
  38. <view class="mgb-16 file-wrap" v-for="(item, index) in fileList" :key="index">
  39. <view class="btn-click file-line" @click="handlePreview(item)">
  40. <view class="file-info">
  41. <image :src="icons.file" mode="aspectFill" class="file-icon" />
  42. <text class="file-name">{{ item.name || title[type] }}</text>
  43. </view>
  44. <image :src="icons.close" mode="aspectFill" class="file-icon"
  45. @click.stop="handleDeleteFile(index)" />
  46. </view>
  47. </view>
  48. </view>
  49. </uni-forms-item>
  50. <uni-forms-item label="备注">
  51. <uni-easyinput maxlength="200" type="textarea" v-model="form.remarks" placeholder="请输入备注" />
  52. </uni-forms-item>
  53. <uni-forms-item label="审批人" required name="peopleList">
  54. <uni-easyinput v-model="form.peopleList" style="display: none;" />
  55. <view style="display: flex;justify-content: flex-start;align-items: center;">
  56. <uni-icons type="folder-add" size="40" @click="gotochooseUser"></uni-icons>
  57. <view style="display: flex;justify-content: flex-start;align-items: center;"
  58. v-for="(tag, index) in nikeNamelist" :key="index">
  59. <uni-icons type="right" size="20"></uni-icons>
  60. <view style="display: flex;flex-direction: column;justify-content: center;align-items: center;"
  61. @click="handleClose(index)">
  62. <span class="user-avatar">{{ tag.substring(0, 1) || 'U' }}</span>
  63. <text style="font-size: 12px;">{{ tag }}</text>
  64. </view>
  65. </view>
  66. </view>
  67. </uni-forms-item>
  68. <uni-forms-item label="流程动态" v-if="tasks.length > 0">
  69. <uni-steps active-icon="medal" :options="tasks" active-color="#007AFF" :active="tasks.length"
  70. direction="column" />
  71. </uni-forms-item>
  72. </uni-forms>
  73. <view class="button-group" v-if="name == '0'">
  74. <button type="default" size="mini" @click="onReCommit('form')">提交</button>
  75. <button type="primary" size="mini" @click="onClose()">关闭</button>
  76. </view>
  77. <view class="button-group" v-else>
  78. <button type="primary" size="mini" @click="submit('form')">提交</button>
  79. <button type="default" size="mini" @click="onSave()">暂存</button>
  80. <button type="warn" size="mini" @click="onDelete()" v-if="form.auditStatus == 0">删除</button>
  81. </view>
  82. <view>
  83. <!-- 普通弹窗 -->
  84. <uni-popup ref="popup" background-color="#fff" border-radius="10px 10px 0 0">
  85. <view class="popup-body">
  86. <view class="popup-close">
  87. <uni-icons type="closeempty" size="20" @click="popupClose"></uni-icons>
  88. </view>
  89. <view class="popup-content">
  90. <pople-Select @submit="submitPeople" ref="popleSelect"></pople-Select>
  91. </view>
  92. </view>
  93. </uni-popup>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import {
  99. getDetail,
  100. create,
  101. save,
  102. deleteById,
  103. closeById,
  104. reCommit
  105. } from "@/api/oa/leave.js"
  106. import { getOpenDicts } from "@/api/system/dict.js";
  107. import {
  108. uploadFile
  109. } from "@/api/system/user"
  110. import popleSelect from '../../popleSelect/choose.vue'
  111. export default {
  112. components: {
  113. popleSelect
  114. },
  115. props: {
  116. id: {
  117. type: [String, Number],
  118. default: undefined
  119. },
  120. name: {
  121. type: String,
  122. default: undefined
  123. },
  124. },
  125. data() {
  126. return {
  127. timeType: [{
  128. text: '上午',
  129. value: 'am'
  130. }, {
  131. text: '下午',
  132. value: 'pm'
  133. }],
  134. leaveTypeList: [],
  135. tasks: [],
  136. userInfo: uni.getStorageSync('userInfo'),
  137. alignment: 'top',
  138. uploadOptions: {},
  139. fileList: [],
  140. icons: {
  141. close: '/static/icon_close.png',
  142. file: '/static/icon_file.png',
  143. },
  144. nikeNamelist: [],
  145. // 表单数据
  146. form: {
  147. employeeName: undefined,
  148. deptName: undefined,
  149. position: undefined,
  150. employeePhone: undefined,
  151. leaveType: undefined,
  152. startDate: undefined,
  153. startTime: 'am',
  154. endDate: undefined,
  155. endTime: 'am',
  156. day: undefined,
  157. reason: undefined,
  158. fileIdList: undefined,
  159. remarks: undefined,
  160. peopleList: '',
  161. },
  162. // 校验规则
  163. rules: {
  164. startDate: {
  165. rules: [{
  166. required: true,
  167. errorMessage: '请选择'
  168. },]
  169. },
  170. endDate: {
  171. rules: [{
  172. required: true,
  173. errorMessage: '请选择'
  174. },]
  175. },
  176. leaveType: {
  177. rules: [{
  178. required: true,
  179. errorMessage: '请选择'
  180. },]
  181. },
  182. day: {
  183. rules: [{
  184. required: true,
  185. errorMessage: '请输入'
  186. }, {
  187. validateFunction: function (rule, value, data, callback) {
  188. // ^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$就表示了小数点后可以保留0位、1位、或2位小数。
  189. let reg = /^(([1-9]{1}\d*)|(0{1}))(\.\d{0,1})?$/ //保留0位、1位
  190. if (!reg.test(value)) {
  191. callback("请输入正确天数")
  192. }
  193. return true
  194. }
  195. }]
  196. },
  197. reason: {
  198. rules: [{
  199. required: true,
  200. errorMessage: '请输入'
  201. },]
  202. },
  203. peopleList: {
  204. rules: [{
  205. required: true,
  206. errorMessage: '请选择'
  207. },]
  208. },
  209. },
  210. }
  211. },
  212. watch: {
  213. id: {
  214. immediate: true,
  215. handler(val) {
  216. this.getInfoDataList();
  217. if (val) {
  218. this.getDetail(val);
  219. }
  220. }
  221. }
  222. },
  223. methods: {
  224. upDayStart(e) {
  225. this.form.startDate = e;
  226. if (this.form.startDate && this.form.endDate) {
  227. let leaveDays = this.calLeaveDays();
  228. if (leaveDays < 0) {
  229. this.form.startDate = "";
  230. this.form.endDate = "";
  231. this.form.day = "";
  232. this.$modal.showToast('起始日期小于结束日期,请重新选择!')
  233. return;
  234. } else if (leaveDays == 0) {
  235. this.form.startDate = "";
  236. this.form.endDate = "";
  237. this.form.day = "";
  238. this.$modal.showToast('工作日天数为0,请重新选择!')
  239. return;
  240. } else {
  241. this.form.day = leaveDays;
  242. }
  243. }
  244. },
  245. upDayEnd(e) {
  246. this.form.endDate = e;
  247. if (this.form.startDate && this.form.endDate) {
  248. let leaveDays = this.calLeaveDays();
  249. if (leaveDays < 0) {
  250. this.form.startDate = "";
  251. this.form.endDate = "";
  252. this.form.day = "";
  253. this.$modal.showToast('起始日期小于结束日期,请重新选择!')
  254. return;
  255. } else if (leaveDays == 0) {
  256. this.form.startDate = "";
  257. this.form.endDate = "";
  258. this.form.day = "";
  259. this.$modal.showToast('工作日天数为0,请重新选择!')
  260. return;
  261. } else {
  262. this.form.day = leaveDays;
  263. }
  264. }
  265. },
  266. upDay() {
  267. if (this.form.startDate && this.form.endDate) {
  268. let leaveDays = this.calLeaveDays();
  269. if (leaveDays < 0) {
  270. this.form.startDate = "";
  271. this.form.endDate = "";
  272. this.form.day = "";
  273. this.$modal.showToast('起始日期小于结束日期,请重新选择!')
  274. return;
  275. } else if (leaveDays == 0) {
  276. this.form.startDate = "";
  277. this.form.endDate = "";
  278. this.form.day = "";
  279. this.$modal.showToast('工作日天数为0,请重新选择!')
  280. return;
  281. } else {
  282. this.form.day = leaveDays;
  283. }
  284. }
  285. },
  286. calLeaveDays() {
  287. var start_date = new Date();
  288. var end_date = new Date();
  289. if (this.form.startTime == 'am') {
  290. start_date = new Date(this.form.startDate + " 00:00:00");
  291. } else {
  292. start_date = new Date(this.form.startDate + " 12:00:00");
  293. }
  294. if (this.form.endTime == 'am') {
  295. end_date = new Date(this.form.endDate + " 12:00:00");
  296. } else {
  297. end_date = new Date(this.form.endDate + " 24:00:00");
  298. }
  299. console.log(start_date);
  300. console.log(end_date);
  301. //转成毫秒数,两个日期相减
  302. var days = end_date.getTime() - start_date.getTime();
  303. //转换成天数
  304. var day = days / (1000 * 60 * 60 * 24);
  305. console.log("day = ", day);
  306. return day;
  307. },
  308. /** 查询部门列表 */
  309. getInfoDataList() {
  310. getOpenDicts('tenant_leave_type').then(response => {
  311. response.data.forEach(v => {
  312. this.leaveTypeList.push({
  313. text: v.label,
  314. value: v.value,
  315. })
  316. })
  317. });
  318. },
  319. /** 获得详情信息 */
  320. getDetail(val) {
  321. getDetail(val).then(response => {
  322. this.form = response.data;
  323. console.log(this.form);
  324. this.fileList = response.data.fileList ? response.data.fileList : [];
  325. let auditUserList = response.data.auditUserList;
  326. if (auditUserList) {
  327. let peopleList = [];
  328. let nikeNamelist = [];
  329. auditUserList.map(item => {
  330. peopleList.push(item.id);
  331. nikeNamelist.push(item.nickname)
  332. });
  333. this.$set(this.form, 'peopleList', peopleList.join(','));
  334. this.nikeNamelist = nikeNamelist;
  335. } else {
  336. this.$set(this.form, 'peopleList', '');
  337. this.nikeNamelist = [];
  338. }
  339. let auditRecordList = response.data.auditRecordList;
  340. if (auditRecordList) {
  341. let tasks = [];
  342. auditRecordList.forEach(v => {
  343. tasks.push({
  344. title: '任务:' + v.assigneeUser.nickname + v.name,
  345. desc: this.parseTime(v.endTime),
  346. })
  347. })
  348. this.tasks = tasks;
  349. }
  350. });
  351. },
  352. // 关闭标签
  353. handleClose(index) {
  354. this.nikeNamelist.splice(index, 1);
  355. let peopleList = this.form.peopleList.split(',');
  356. peopleList.splice(index, 1);
  357. this.form.peopleList = peopleList.join(',');
  358. },
  359. submitPeople(userList, nikeNamelist, userIdList) {
  360. console.log(userList);
  361. console.log(userIdList);
  362. this.nikeNamelist = nikeNamelist;
  363. this.form.peopleList = userIdList.join(',');
  364. this.$refs.popup.close();
  365. },
  366. popupClose() {
  367. this.$refs.popup.close();
  368. },
  369. gotochooseUser() {
  370. this.$refs.popup.open('bottom');
  371. setTimeout(() => {
  372. this.$refs.popleSelect.getInfoData();
  373. })
  374. },
  375. handleUploadClick() {
  376. this.$refs.XeUpload.upload('file');
  377. },
  378. handleUploadCallback(e) {
  379. console.log('UploadCallback', e);
  380. let data = {
  381. filePath: e.data[0].tempFilePath
  382. }
  383. uploadFile(data).then(response => {
  384. const tmpFiles = ([response.data] || []).map(({
  385. id,
  386. url,
  387. name,
  388. type
  389. }) => {
  390. return {
  391. id,
  392. url,
  393. name,
  394. type,
  395. };
  396. });
  397. this.fileList.push(...tmpFiles);
  398. })
  399. },
  400. // 预览
  401. handlePreview(val) {
  402. console.log('PreviewFile', val);
  403. const fileType = this.getFileType(val.name);
  404. if (fileType === 'image') {
  405. uni.previewImage({
  406. current: 0,
  407. urls: [val.url],
  408. });
  409. } else if (fileType === 'office') {
  410. return uni.downloadFile({
  411. url: val.url,
  412. success: function (res) {
  413. let filePath = res.filePath || res.tempFilePath;
  414. uni.openDocument({
  415. filePath: filePath,
  416. showMenu: true,
  417. success: function (res) {
  418. console.log('打开文档成功');
  419. }
  420. });
  421. }
  422. });
  423. } else {
  424. uni.showModal({
  425. title: '该类型文件无法预览',
  426. content: val.name,
  427. showCancel: false,
  428. });
  429. }
  430. },
  431. handleDeleteFile(index) {
  432. this.fileList.splice(index, 1);
  433. },
  434. submit(ref) {
  435. this.$refs[ref].validate().then(res => {
  436. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  437. this.form.auditPass = true;
  438. let fileIds = [];
  439. this.fileList.forEach(v => {
  440. fileIds.push(v.id)
  441. })
  442. this.form.fileIdList = fileIds;
  443. create(this.form).then(response => {
  444. uni.showToast({
  445. title: `提交成功`
  446. })
  447. if (this.id) {
  448. this.$emit('popupClose');
  449. } else {
  450. setTimeout(() => {
  451. this.$router.go(0)
  452. }, 500)
  453. }
  454. }).catch(() => {
  455. });
  456. }).catch(err => {
  457. console.log('err', err);
  458. })
  459. },
  460. //暂存
  461. onSave() {
  462. if (this.form.peopleList) {
  463. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  464. }
  465. this.form.auditPass = false;
  466. let fileIds = [];
  467. this.fileList.forEach(v => {
  468. fileIds.push(v.id)
  469. })
  470. this.form.fileIdList = fileIds;
  471. save(this.form).then(response => {
  472. uni.showToast({
  473. title: `暂存成功`
  474. })
  475. if (this.id) {
  476. this.$emit('popupClose');
  477. } else {
  478. setTimeout(() => {
  479. this.$router.go(0)
  480. }, 500)
  481. }
  482. }).catch(() => {
  483. });
  484. },
  485. //驳回或撤回后再次提交
  486. onReCommit(ref) {
  487. this.$refs[ref].validate().then(res => {
  488. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  489. this.form.auditPass = true;
  490. reCommit(this.form).then(response => {
  491. uni.showToast({
  492. title: `提交成功`
  493. })
  494. this.$emit('popupClose');
  495. }).catch(() => {
  496. });
  497. }).catch(err => {
  498. console.log('err', err);
  499. })
  500. },
  501. //暂存删除
  502. async onDelete() {
  503. let that = this;
  504. uni.showModal({
  505. title: '提示',
  506. content: '是否确认删除?',
  507. success: function (res) {
  508. if (res.confirm) {
  509. console.log('用户点击确定');
  510. deleteById(that.id).then(response => {
  511. uni.showToast({
  512. title: "删除成功!"
  513. })
  514. that.$emit('popupClose');
  515. })
  516. } else if (res.cancel) {
  517. console.log('用户点击取消');
  518. }
  519. }
  520. });
  521. },
  522. //暂存关闭
  523. async onClose() {
  524. let that = this;
  525. uni.showModal({
  526. title: '提示',
  527. content: '是否确认关闭?',
  528. success: function (res) {
  529. if (res.confirm) {
  530. console.log('用户点击确定');
  531. closeById(that.id).then(response => {
  532. uni.showToast({
  533. title: "流程已关闭!"
  534. })
  535. that.$emit('popupClose');
  536. })
  537. } else if (res.cancel) {
  538. console.log('用户点击取消');
  539. }
  540. }
  541. });
  542. },
  543. }
  544. }
  545. </script>
  546. <style lang="scss">
  547. .container {
  548. padding: 15px;
  549. background-color: #fff;
  550. }
  551. .segmented-control {
  552. margin-bottom: 15px;
  553. }
  554. .button-group {
  555. margin-top: 15px;
  556. display: flex;
  557. }
  558. .form-item {
  559. display: flex;
  560. align-items: center;
  561. flex: 1;
  562. }
  563. .button {
  564. display: flex;
  565. align-items: center;
  566. height: 35px;
  567. line-height: 35px;
  568. margin-left: 10px;
  569. }
  570. </style>
  571. <style lang="scss" scoped>
  572. .user-avatar {
  573. width: 22px;
  574. height: 22px;
  575. line-height: 19px;
  576. font-size: 12px;
  577. background: #46c26f;
  578. border: 1px solid transparent;
  579. border-radius: 5px;
  580. color: #fff;
  581. display: inline-block;
  582. overflow: hidden;
  583. text-align: center;
  584. line-height: 22px;
  585. margin-bottom: 2px;
  586. }
  587. .popup-body {
  588. z-index: 99;
  589. margin-bottom: 30px;
  590. }
  591. .popup-close {
  592. cursor: pointer;
  593. height: 40px;
  594. line-height: 40px;
  595. padding-left: 10px;
  596. border-bottom: 1px solid #eaecef;
  597. }
  598. .popup-content {
  599. height: 450px;
  600. overflow-x: auto;
  601. margin: 20px;
  602. }
  603. .btn-click {
  604. transition: all 0.3s;
  605. opacity: 1;
  606. }
  607. .btn-click:active {
  608. opacity: 0.5;
  609. }
  610. .mgb-16 {
  611. margin-bottom: 16rpx;
  612. &:last-child {
  613. margin-bottom: 0;
  614. }
  615. }
  616. .upload-wrap {
  617. width: 100%;
  618. border-radius: 16rpx;
  619. background: white;
  620. // padding: 32rpx;
  621. .upload-btn {
  622. width: 100%;
  623. height: 176rpx;
  624. border: 2rpx dashed #AAAAAA;
  625. background: #FAFAFA;
  626. border-radius: 16rpx;
  627. display: flex;
  628. align-items: center;
  629. justify-content: center;
  630. flex-direction: column;
  631. .upload-icon {
  632. width: 48rpx;
  633. height: 48rpx;
  634. margin-bottom: 8rpx;
  635. }
  636. .upload-text {
  637. font-size: 26rpx;
  638. color: #9E9E9E;
  639. line-height: 40rpx;
  640. }
  641. }
  642. .file-wrap {
  643. .file-line {
  644. width: 100%;
  645. background: #F5F5F5;
  646. border-radius: 8rpx;
  647. padding: 16rpx;
  648. font-size: 26rpx;
  649. color: #1A1A1A;
  650. line-height: 40rpx;
  651. display: flex;
  652. align-items: center;
  653. justify-content: space-between;
  654. .file-info {
  655. width: 90%;
  656. display: flex;
  657. align-items: center;
  658. .file-name {
  659. max-width: 80%;
  660. padding-left: 16rpx;
  661. overflow: hidden;
  662. text-overflow: ellipsis;
  663. white-space: nowrap;
  664. }
  665. }
  666. .file-icon {
  667. width: 40rpx;
  668. height: 40rpx;
  669. flex-shrink: 0;
  670. }
  671. .file-empty {
  672. color: #999999;
  673. }
  674. }
  675. }
  676. }
  677. </style>