edit.vue 13 KB

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