edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. create(this.form).then(response => {
  296. uni.showToast({
  297. title: `提交成功`
  298. })
  299. if(this.id){
  300. this.$emit('popupClose');
  301. }else{
  302. setTimeout(() => {
  303. this.$router.go(0)
  304. }, 500)
  305. }
  306. }).catch(() => {
  307. });
  308. }).catch(err => {
  309. console.log('err', err);
  310. })
  311. },
  312. //暂存
  313. onSave() {
  314. if (this.form.peopleList) {
  315. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  316. }
  317. this.form.auditPass = false;
  318. let fileIds = [];
  319. this.fileList.forEach(v => {
  320. fileIds.push(v.id)
  321. })
  322. this.form.fileIdList = fileIds;
  323. save(this.form).then(response => {
  324. uni.showToast({
  325. title: `暂存成功`
  326. })
  327. if(this.id){
  328. this.$emit('popupClose');
  329. }else{
  330. setTimeout(() => {
  331. this.$router.go(0)
  332. }, 500)
  333. }
  334. }).catch(() => {
  335. });
  336. },
  337. //驳回或撤回后再次提交
  338. onReCommit(ref) {
  339. this.$refs[ref].validate().then(res => {
  340. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  341. this.form.auditPass = true;
  342. reCommit(this.form).then(response => {
  343. uni.showToast({
  344. title: `提交成功`
  345. })
  346. this.$emit('popupClose');
  347. }).catch(() => {
  348. });
  349. }).catch(err => {
  350. console.log('err', err);
  351. })
  352. },
  353. //暂存删除
  354. async onDelete() {
  355. let that = this;
  356. uni.showModal({
  357. title: '提示',
  358. content: '是否确认删除?',
  359. success: function(res) {
  360. if (res.confirm) {
  361. console.log('用户点击确定');
  362. deleteById(that.id).then(response => {
  363. uni.showToast({
  364. title: "删除成功!"
  365. })
  366. that.$emit('popupClose');
  367. })
  368. } else if (res.cancel) {
  369. console.log('用户点击取消');
  370. }
  371. }
  372. });
  373. },
  374. //暂存关闭
  375. async onClose() {
  376. let that = this;
  377. uni.showModal({
  378. title: '提示',
  379. content: '是否确认关闭?',
  380. success: function(res) {
  381. if (res.confirm) {
  382. console.log('用户点击确定');
  383. closeById(that.id).then(response => {
  384. uni.showToast({
  385. title: "流程已关闭!"
  386. })
  387. that.$emit('popupClose');
  388. })
  389. } else if (res.cancel) {
  390. console.log('用户点击取消');
  391. }
  392. }
  393. });
  394. },
  395. }
  396. }
  397. </script>
  398. <style lang="scss">
  399. .container {
  400. padding: 15px;
  401. background-color: #fff;
  402. }
  403. .segmented-control {
  404. margin-bottom: 15px;
  405. }
  406. .button-group {
  407. margin-top: 15px;
  408. display: flex;
  409. }
  410. .form-item {
  411. display: flex;
  412. align-items: center;
  413. flex: 1;
  414. }
  415. .button {
  416. display: flex;
  417. align-items: center;
  418. height: 35px;
  419. line-height: 35px;
  420. margin-left: 10px;
  421. }
  422. </style>
  423. <style lang="scss" scoped>
  424. .user-avatar {
  425. width: 22px;
  426. height: 22px;
  427. line-height: 19px;
  428. font-size: 12px;
  429. background: #46c26f;
  430. border: 1px solid transparent;
  431. border-radius: 5px;
  432. color: #fff;
  433. display: inline-block;
  434. overflow: hidden;
  435. text-align: center;
  436. line-height: 22px;
  437. margin-bottom: 2px;
  438. }
  439. .popup-body {
  440. z-index: 99;
  441. margin-bottom: 30px;
  442. }
  443. .popup-close {
  444. cursor: pointer;
  445. height: 40px;
  446. line-height: 40px;
  447. padding-left: 10px;
  448. border-bottom: 1px solid #eaecef;
  449. }
  450. .popup-content {
  451. height: 450px;
  452. overflow-x: auto;
  453. margin: 20px;
  454. }
  455. .btn-click {
  456. transition: all 0.3s;
  457. opacity: 1;
  458. }
  459. .btn-click:active {
  460. opacity: 0.5;
  461. }
  462. .mgb-16 {
  463. margin-bottom: 16rpx;
  464. &:last-child {
  465. margin-bottom: 0;
  466. }
  467. }
  468. .upload-wrap {
  469. width: 100%;
  470. border-radius: 16rpx;
  471. background: white;
  472. // padding: 32rpx;
  473. .upload-btn {
  474. width: 100%;
  475. height: 176rpx;
  476. border: 2rpx dashed #AAAAAA;
  477. background: #FAFAFA;
  478. border-radius: 16rpx;
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. flex-direction: column;
  483. .upload-icon {
  484. width: 48rpx;
  485. height: 48rpx;
  486. margin-bottom: 8rpx;
  487. }
  488. .upload-text {
  489. font-size: 26rpx;
  490. color: #9E9E9E;
  491. line-height: 40rpx;
  492. }
  493. }
  494. .file-wrap {
  495. .file-line {
  496. width: 100%;
  497. background: #F5F5F5;
  498. border-radius: 8rpx;
  499. padding: 16rpx;
  500. font-size: 26rpx;
  501. color: #1A1A1A;
  502. line-height: 40rpx;
  503. display: flex;
  504. align-items: center;
  505. justify-content: space-between;
  506. .file-info {
  507. width: 90%;
  508. display: flex;
  509. align-items: center;
  510. .file-name {
  511. max-width: 80%;
  512. padding-left: 16rpx;
  513. overflow: hidden;
  514. text-overflow: ellipsis;
  515. white-space: nowrap;
  516. }
  517. }
  518. .file-icon {
  519. width: 40rpx;
  520. height: 40rpx;
  521. flex-shrink: 0;
  522. }
  523. .file-empty {
  524. color: #999999;
  525. }
  526. }
  527. }
  528. }
  529. </style>