edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. reCommit(this.form).then(response => {
  390. uni.showToast({
  391. title: `提交成功`
  392. })
  393. this.$emit('popupClose');
  394. }).catch(() => {
  395. });
  396. }).catch(err => {
  397. console.log('err', err);
  398. })
  399. },
  400. //暂存删除
  401. async onDelete() {
  402. let that = this;
  403. uni.showModal({
  404. title: '提示',
  405. content: '是否确认删除?',
  406. success: function (res) {
  407. if (res.confirm) {
  408. console.log('用户点击确定');
  409. deleteById(that.id).then(response => {
  410. uni.showToast({
  411. title: "删除成功!"
  412. })
  413. that.$emit('popupClose');
  414. })
  415. } else if (res.cancel) {
  416. console.log('用户点击取消');
  417. }
  418. }
  419. });
  420. },
  421. //暂存关闭
  422. async onClose() {
  423. let that = this;
  424. uni.showModal({
  425. title: '提示',
  426. content: '是否确认关闭?',
  427. success: function (res) {
  428. if (res.confirm) {
  429. console.log('用户点击确定');
  430. closeById(that.id).then(response => {
  431. uni.showToast({
  432. title: "流程已关闭!"
  433. })
  434. that.$emit('popupClose');
  435. })
  436. } else if (res.cancel) {
  437. console.log('用户点击取消');
  438. }
  439. }
  440. });
  441. },
  442. }
  443. }
  444. </script>
  445. <style lang="scss">
  446. .container {
  447. padding: 15px;
  448. background-color: #fff;
  449. }
  450. .segmented-control {
  451. margin-bottom: 15px;
  452. }
  453. .button-group {
  454. margin-top: 15px;
  455. display: flex;
  456. }
  457. .form-item {
  458. display: flex;
  459. align-items: center;
  460. flex: 1;
  461. }
  462. .button {
  463. display: flex;
  464. align-items: center;
  465. height: 35px;
  466. line-height: 35px;
  467. margin-left: 10px;
  468. }
  469. </style>
  470. <style lang="scss" scoped>
  471. .user-avatar {
  472. width: 22px;
  473. height: 22px;
  474. line-height: 19px;
  475. font-size: 12px;
  476. background: #46c26f;
  477. border: 1px solid transparent;
  478. border-radius: 5px;
  479. color: #fff;
  480. display: inline-block;
  481. overflow: hidden;
  482. text-align: center;
  483. line-height: 22px;
  484. margin-bottom: 2px;
  485. }
  486. .popup-body {
  487. z-index: 99;
  488. margin-bottom: 30px;
  489. }
  490. .popup-close {
  491. cursor: pointer;
  492. height: 40px;
  493. line-height: 40px;
  494. padding-left: 10px;
  495. border-bottom: 1px solid #eaecef;
  496. }
  497. .popup-content {
  498. height: 450px;
  499. overflow-x: auto;
  500. margin: 20px;
  501. }
  502. .btn-click {
  503. transition: all 0.3s;
  504. opacity: 1;
  505. }
  506. .btn-click:active {
  507. opacity: 0.5;
  508. }
  509. .mgb-16 {
  510. margin-bottom: 16rpx;
  511. &:last-child {
  512. margin-bottom: 0;
  513. }
  514. }
  515. .upload-wrap {
  516. width: 100%;
  517. border-radius: 16rpx;
  518. background: white;
  519. // padding: 32rpx;
  520. .upload-btn {
  521. width: 100%;
  522. height: 176rpx;
  523. border: 2rpx dashed #AAAAAA;
  524. background: #FAFAFA;
  525. border-radius: 16rpx;
  526. display: flex;
  527. align-items: center;
  528. justify-content: center;
  529. flex-direction: column;
  530. .upload-icon {
  531. width: 48rpx;
  532. height: 48rpx;
  533. margin-bottom: 8rpx;
  534. }
  535. .upload-text {
  536. font-size: 26rpx;
  537. color: #9E9E9E;
  538. line-height: 40rpx;
  539. }
  540. }
  541. .file-wrap {
  542. .file-line {
  543. width: 100%;
  544. background: #F5F5F5;
  545. border-radius: 8rpx;
  546. padding: 16rpx;
  547. font-size: 26rpx;
  548. color: #1A1A1A;
  549. line-height: 40rpx;
  550. display: flex;
  551. align-items: center;
  552. justify-content: space-between;
  553. .file-info {
  554. width: 90%;
  555. display: flex;
  556. align-items: center;
  557. .file-name {
  558. max-width: 80%;
  559. padding-left: 16rpx;
  560. overflow: hidden;
  561. text-overflow: ellipsis;
  562. white-space: nowrap;
  563. }
  564. }
  565. .file-icon {
  566. width: 40rpx;
  567. height: 40rpx;
  568. flex-shrink: 0;
  569. }
  570. .file-empty {
  571. color: #999999;
  572. }
  573. }
  574. }
  575. }
  576. </style>