edit.vue 18 KB

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