edit.vue 13 KB

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