edit.vue 18 KB

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