edit.vue 15 KB

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