edit.vue 14 KB

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