edit.vue 13 KB

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