edit.vue 15 KB

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