edit.vue 14 KB

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