edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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="primary" size="mini" @click="onReCommit('form')">提交</button>
  75. <button type="default" 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 type="multiple" @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?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. let reason = v.reason?v.reason:'';
  344. let time = v.endTime?v.endTime:v.createTime;
  345. tasks.push({
  346. title:'任务:' + v.assigneeUser.nickname + v.name,
  347. desc: reason + " " + this.parseTime(time),
  348. })
  349. })
  350. this.tasks = tasks;
  351. }
  352. });
  353. },
  354. // 关闭标签
  355. handleClose(index) {
  356. this.nikeNamelist.splice(index, 1);
  357. let peopleList = this.form.peopleList.split(',');
  358. peopleList.splice(index, 1);
  359. this.form.peopleList = peopleList.join(',');
  360. },
  361. submitPeople(userList, nikeNamelist, userIdList) {
  362. console.log(userList);
  363. console.log(userIdList);
  364. this.nikeNamelist = nikeNamelist;
  365. this.form.peopleList = userIdList.join(',');
  366. this.$refs.popup.close();
  367. },
  368. popupClose() {
  369. this.$refs.popup.close();
  370. },
  371. gotochooseUser() {
  372. this.$refs.popup.open('bottom');
  373. setTimeout(() => {
  374. this.$refs.popleSelect.getInfoData();
  375. })
  376. },
  377. handleUploadClick() {
  378. this.$refs.XeUpload.upload('file');
  379. },
  380. handleUploadCallback(e) {
  381. console.log('UploadCallback', e);
  382. let data = {
  383. filePath: e.data[0].tempFilePath
  384. }
  385. uploadFile(data).then(response => {
  386. const tmpFiles = ([response.data] || []).map(({
  387. id,
  388. url,
  389. name,
  390. type
  391. }) => {
  392. return {
  393. id,
  394. url,
  395. name,
  396. type,
  397. };
  398. });
  399. this.fileList.push(...tmpFiles);
  400. })
  401. },
  402. // 预览
  403. handlePreview(val) {
  404. console.log('PreviewFile', val);
  405. const fileType = this.getFileType(val.name);
  406. if (fileType === 'image') {
  407. uni.previewImage({
  408. current: 0,
  409. urls: [val.url],
  410. });
  411. } else if (fileType === 'office') {
  412. return uni.downloadFile({
  413. url: val.url,
  414. success: function (res) {
  415. let filePath = res.filePath || res.tempFilePath;
  416. uni.openDocument({
  417. filePath: filePath,
  418. showMenu: true,
  419. success: function (res) {
  420. console.log('打开文档成功');
  421. }
  422. });
  423. }
  424. });
  425. } else {
  426. uni.showModal({
  427. title: '该类型文件无法预览',
  428. content: val.name,
  429. showCancel: false,
  430. });
  431. }
  432. },
  433. handleDeleteFile(index) {
  434. this.fileList.splice(index, 1);
  435. },
  436. submit(ref) {
  437. this.$refs[ref].validate().then(res => {
  438. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  439. this.form.auditPass = true;
  440. let fileIds = [];
  441. this.fileList.forEach(v => {
  442. fileIds.push(v.id)
  443. })
  444. this.form.fileIdList = fileIds;
  445. create(this.form).then(response => {
  446. uni.showToast({
  447. title: `提交成功`
  448. })
  449. if (this.id) {
  450. this.$emit('popupClose');
  451. } else {
  452. setTimeout(() => {
  453. this.$router.go(0)
  454. }, 500)
  455. }
  456. }).catch(() => {
  457. });
  458. }).catch(err => {
  459. console.log('err', err);
  460. })
  461. },
  462. //暂存
  463. onSave() {
  464. if (this.form.peopleList) {
  465. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  466. }
  467. this.form.auditPass = false;
  468. let fileIds = [];
  469. this.fileList.forEach(v => {
  470. fileIds.push(v.id)
  471. })
  472. this.form.fileIdList = fileIds;
  473. save(this.form).then(response => {
  474. uni.showToast({
  475. title: `暂存成功`
  476. })
  477. if (this.id) {
  478. this.$emit('popupClose');
  479. } else {
  480. setTimeout(() => {
  481. this.$router.go(0)
  482. }, 500)
  483. }
  484. }).catch(() => {
  485. });
  486. },
  487. //驳回或撤回后再次提交
  488. onReCommit(ref) {
  489. this.$refs[ref].validate().then(res => {
  490. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  491. this.form.auditPass = true;
  492. reCommit(this.form).then(response => {
  493. uni.showToast({
  494. title: `提交成功`
  495. })
  496. this.$emit('popupClose');
  497. }).catch(() => {
  498. });
  499. }).catch(err => {
  500. console.log('err', err);
  501. })
  502. },
  503. //暂存删除
  504. async onDelete() {
  505. let that = this;
  506. uni.showModal({
  507. title: '提示',
  508. content: '是否确认删除?',
  509. success: function (res) {
  510. if (res.confirm) {
  511. console.log('用户点击确定');
  512. deleteById(that.id).then(response => {
  513. uni.showToast({
  514. title: "删除成功!"
  515. })
  516. that.$emit('popupClose');
  517. })
  518. } else if (res.cancel) {
  519. console.log('用户点击取消');
  520. }
  521. }
  522. });
  523. },
  524. //暂存关闭
  525. async onClose() {
  526. let that = this;
  527. uni.showModal({
  528. title: '提示',
  529. content: '是否确认关闭?',
  530. success: function (res) {
  531. if (res.confirm) {
  532. console.log('用户点击确定');
  533. closeById(that.id).then(response => {
  534. uni.showToast({
  535. title: "流程已关闭!"
  536. })
  537. that.$emit('popupClose');
  538. })
  539. } else if (res.cancel) {
  540. console.log('用户点击取消');
  541. }
  542. }
  543. });
  544. },
  545. }
  546. }
  547. </script>
  548. <style lang="scss">
  549. .container {
  550. padding: 15px;
  551. background-color: #fff;
  552. }
  553. .segmented-control {
  554. margin-bottom: 15px;
  555. }
  556. .button-group {
  557. margin-top: 15px;
  558. display: flex;
  559. }
  560. .form-item {
  561. display: flex;
  562. align-items: center;
  563. flex: 1;
  564. }
  565. .button {
  566. display: flex;
  567. align-items: center;
  568. height: 35px;
  569. line-height: 35px;
  570. margin-left: 10px;
  571. }
  572. </style>
  573. <style lang="scss" scoped>
  574. .user-avatar {
  575. width: 22px;
  576. height: 22px;
  577. line-height: 19px;
  578. font-size: 12px;
  579. background: #46c26f;
  580. border: 1px solid transparent;
  581. border-radius: 5px;
  582. color: #fff;
  583. display: inline-block;
  584. overflow: hidden;
  585. text-align: center;
  586. line-height: 22px;
  587. margin-bottom: 2px;
  588. }
  589. .popup-body {
  590. z-index: 99;
  591. margin-bottom: 30px;
  592. }
  593. .popup-close {
  594. cursor: pointer;
  595. height: 40px;
  596. line-height: 40px;
  597. padding-left: 10px;
  598. border-bottom: 1px solid #eaecef;
  599. }
  600. .popup-content {
  601. height: 450px;
  602. overflow-x: auto;
  603. margin: 20px;
  604. }
  605. .btn-click {
  606. transition: all 0.3s;
  607. opacity: 1;
  608. }
  609. .btn-click:active {
  610. opacity: 0.5;
  611. }
  612. .mgb-16 {
  613. margin-bottom: 16rpx;
  614. &:last-child {
  615. margin-bottom: 0;
  616. }
  617. }
  618. .upload-wrap {
  619. width: 100%;
  620. border-radius: 16rpx;
  621. background: white;
  622. // padding: 32rpx;
  623. .upload-btn {
  624. width: 100%;
  625. height: 176rpx;
  626. border: 2rpx dashed #AAAAAA;
  627. background: #FAFAFA;
  628. border-radius: 16rpx;
  629. display: flex;
  630. align-items: center;
  631. justify-content: center;
  632. flex-direction: column;
  633. .upload-icon {
  634. width: 48rpx;
  635. height: 48rpx;
  636. margin-bottom: 8rpx;
  637. }
  638. .upload-text {
  639. font-size: 26rpx;
  640. color: #9E9E9E;
  641. line-height: 40rpx;
  642. }
  643. }
  644. .file-wrap {
  645. .file-line {
  646. width: 100%;
  647. background: #F5F5F5;
  648. border-radius: 8rpx;
  649. padding: 16rpx;
  650. font-size: 26rpx;
  651. color: #1A1A1A;
  652. line-height: 40rpx;
  653. display: flex;
  654. align-items: center;
  655. justify-content: space-between;
  656. .file-info {
  657. width: 90%;
  658. display: flex;
  659. align-items: center;
  660. .file-name {
  661. max-width: 80%;
  662. padding-left: 16rpx;
  663. overflow: hidden;
  664. text-overflow: ellipsis;
  665. white-space: nowrap;
  666. }
  667. }
  668. .file-icon {
  669. width: 40rpx;
  670. height: 40rpx;
  671. flex-shrink: 0;
  672. }
  673. .file-empty {
  674. color: #999999;
  675. }
  676. }
  677. }
  678. }
  679. </style>