edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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="receiveDate">
  17. <uni-datetime-picker type="date" v-model="form.receiveDate" />
  18. </uni-forms-item>
  19. <button type="primary" size="mini" @click="addRow">新增</button>
  20. <uni-table ref="table" border stripe>
  21. <uni-tr>
  22. <uni-th align="center">领用物品名称</uni-th>
  23. <uni-th align="center" width="80">领用数量</uni-th>
  24. <uni-th align="center">规格型号</uni-th>
  25. <uni-th align="center" width="90">操作</uni-th>
  26. </uni-tr>
  27. <uni-tr v-for="(item, index) in form.oaReceiveObjs" :key="index">
  28. <uni-td align="center">
  29. <uni-easyinput maxlength="20" v-model="item.name" :clearable="false" />
  30. </uni-td>
  31. <uni-td align="center">
  32. <uni-number-box :min="1" v-model="item.amount" />
  33. </uni-td>
  34. <uni-td align="center">
  35. <uni-easyinput maxlength="20" v-model="item.config" :clearable="false" />
  36. </uni-td>
  37. <uni-td align="center">
  38. <view class="uni-group">
  39. <button :disabled="form.oaReceiveObjs.length > 1 ? false : true" size="mini" type="warn"
  40. @click="handleDeleteRow(index)">删除</button>
  41. </view>
  42. </uni-td>
  43. </uni-tr>
  44. </uni-table>
  45. <uni-forms-item label="领用事由" required name="reason">
  46. <uni-easyinput maxlength="50" type="textarea" v-model="form.reason" placeholder="请输入" />
  47. </uni-forms-item>
  48. <uni-forms-item label="附件">
  49. <view class="upload-wrap">
  50. <button type="primary" size="mini" @click="handleUploadClick">点击上传</button>
  51. <xe-upload ref="XeUpload" :options="uploadOptions" @callback="handleUploadCallback"></xe-upload>
  52. <view class="mgb-16 file-wrap" v-for="(item, index) in fileList" :key="index">
  53. <view class="btn-click file-line" @click="handlePreview(item)">
  54. <view class="file-info">
  55. <image :src="icons.file" mode="aspectFill" class="file-icon" />
  56. <text class="file-name">{{ item.name || title[type] }}</text>
  57. </view>
  58. <image :src="icons.close" mode="aspectFill" class="file-icon"
  59. @click.stop="handleDeleteFile(index)" />
  60. </view>
  61. </view>
  62. </view>
  63. </uni-forms-item>
  64. <uni-forms-item label="备注">
  65. <uni-easyinput maxlength="200" type="textarea" v-model="form.remarks" placeholder="请输入备注" />
  66. </uni-forms-item>
  67. <uni-forms-item label="审批人" required name="peopleList">
  68. <uni-easyinput v-model="form.peopleList" style="display: none;" />
  69. <view style="display: flex;justify-content: flex-start;align-items: center;">
  70. <uni-icons type="folder-add" size="40" @click="gotochooseUser"></uni-icons>
  71. <view style="display: flex;justify-content: flex-start;align-items: center;"
  72. v-for="(tag, index) in nikeNamelist" :key="index">
  73. <uni-icons type="right" size="20"></uni-icons>
  74. <view style="display: flex;flex-direction: column;justify-content: center;align-items: center;"
  75. @click="handleClose(index)">
  76. <span class="user-avatar">{{ tag.substring(0, 1) || 'U' }}</span>
  77. <text style="font-size: 12px;">{{ tag }}</text>
  78. </view>
  79. </view>
  80. </view>
  81. </uni-forms-item>
  82. <uni-forms-item label="流程动态" v-if="tasks.length > 0">
  83. <uni-steps active-icon="medal" :options="tasks" active-color="#007AFF" :active="tasks.length"
  84. direction="column" />
  85. </uni-forms-item>
  86. </uni-forms>
  87. <view class="button-group" v-if="name == '0'">
  88. <button type="primary" size="mini" @click="onReCommit('form')">提交</button>
  89. <button type="default" size="mini" @click="onClose()">关闭</button>
  90. </view>
  91. <view class="button-group" v-else>
  92. <button type="primary" size="mini" @click="submit('form')">提交</button>
  93. <button type="default" size="mini" @click="onSave()">暂存</button>
  94. <button type="warn" size="mini" @click="onDelete()" v-if="form.auditStatus == 0">删除</button>
  95. </view>
  96. <view>
  97. <!-- 普通弹窗 -->
  98. <uni-popup ref="popup" background-color="#fff" border-radius="10px 10px 0 0">
  99. <view class="popup-body">
  100. <view class="popup-close">
  101. <uni-icons type="closeempty" size="20" @click="popupClose"></uni-icons>
  102. </view>
  103. <view class="popup-content">
  104. <pople-Select type="multiple" @submit="submitPeople" ref="popleSelect"></pople-Select>
  105. </view>
  106. </view>
  107. </uni-popup>
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. import {
  113. getDetail,
  114. create,
  115. save,
  116. deleteById,
  117. closeById,
  118. reCommit
  119. } from "@/api/oa/receive.js"
  120. import {
  121. uploadFile
  122. } from "@/api/system/user"
  123. import popleSelect from '../../popleSelect/choose.vue'
  124. export default {
  125. components: {
  126. popleSelect
  127. },
  128. props: {
  129. id: {
  130. type: [String, Number],
  131. default: undefined
  132. },
  133. name: {
  134. type: String,
  135. default: undefined
  136. },
  137. },
  138. data() {
  139. return {
  140. tasks: [],
  141. userInfo: uni.getStorageSync('userInfo'),
  142. alignment: 'top',
  143. uploadOptions: {},
  144. fileList: [],
  145. icons: {
  146. close: '/static/icon_close.png',
  147. file: '/static/icon_file.png',
  148. },
  149. nikeNamelist: [],
  150. // 表单数据
  151. form: {
  152. employeeName: undefined,
  153. deptName: undefined,
  154. position: undefined,
  155. employeePhone: undefined,
  156. receiveDate: undefined,
  157. oaReceiveObjs: [],
  158. reason: undefined,
  159. fileIdList: undefined,
  160. remarks: undefined,
  161. peopleList: '',
  162. },
  163. // 校验规则
  164. rules: {
  165. receiveDate: {
  166. rules: [{
  167. required: true,
  168. errorMessage: '请选择'
  169. },]
  170. },
  171. reason: {
  172. rules: [{
  173. required: true,
  174. errorMessage: '请输入'
  175. },]
  176. },
  177. peopleList: {
  178. rules: [{
  179. required: true,
  180. errorMessage: '请选择审批人'
  181. },]
  182. },
  183. },
  184. }
  185. },
  186. watch: {
  187. id: {
  188. immediate: true,
  189. handler(val) {
  190. if (val) {
  191. this.getDetail(val);
  192. } else {
  193. this.addRow();
  194. }
  195. }
  196. }
  197. },
  198. methods: {
  199. /**
  200. * 新增行
  201. */
  202. addRow() {
  203. this.form.oaReceiveObjs.push({
  204. name: '',
  205. amount: 1,
  206. config: '',
  207. });
  208. },
  209. /**
  210. * 删除行
  211. * @param row
  212. */
  213. handleDeleteRow(index) {
  214. this.form.oaReceiveObjs.splice(index, 1);
  215. },
  216. /** 获得详情信息 */
  217. getDetail(val) {
  218. getDetail(val).then(response => {
  219. this.form = response.data;
  220. console.log(this.form);
  221. this.fileList = response.data.fileList ? response.data.fileList : [];
  222. let auditUserList = response.data.auditUserList;
  223. if (auditUserList) {
  224. let peopleList = [];
  225. let nikeNamelist = [];
  226. auditUserList.map(item => {
  227. peopleList.push(item.id);
  228. nikeNamelist.push(item.nickname)
  229. });
  230. this.$set(this.form, 'peopleList', peopleList.join(','));
  231. this.nikeNamelist = nikeNamelist;
  232. } else {
  233. this.$set(this.form, 'peopleList', '');
  234. this.nikeNamelist = [];
  235. }
  236. let auditRecordList = response.data.auditRecordList;
  237. if (auditRecordList) {
  238. let tasks = [];
  239. auditRecordList.forEach(v => {
  240. tasks.push({
  241. title: '任务:' + v.assigneeUser.nickname + v.name,
  242. desc: this.parseTime(v.endTime),
  243. })
  244. })
  245. this.tasks = tasks;
  246. }
  247. });
  248. },
  249. // 关闭标签
  250. handleClose(index) {
  251. this.nikeNamelist.splice(index, 1);
  252. let peopleList = this.form.peopleList.split(',');
  253. peopleList.splice(index, 1);
  254. this.form.peopleList = peopleList.join(',');
  255. },
  256. submitPeople(userList, nikeNamelist, userIdList) {
  257. console.log(userList);
  258. console.log(userIdList);
  259. this.nikeNamelist = nikeNamelist;
  260. this.form.peopleList = userIdList.join(',');
  261. this.$refs.popup.close();
  262. },
  263. popupClose() {
  264. this.$refs.popup.close();
  265. },
  266. gotochooseUser() {
  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. console.log('submit', this.form);
  333. this.$refs[ref].validate().then(res => {
  334. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  335. this.form.auditPass = true;
  336. let fileIds = [];
  337. this.fileList.forEach(v => {
  338. fileIds.push(v.id)
  339. })
  340. this.form.fileIdList = fileIds;
  341. create(this.form).then(response => {
  342. uni.showToast({
  343. title: `提交成功`
  344. })
  345. if (this.id) {
  346. this.$emit('popupClose');
  347. } else {
  348. setTimeout(() => {
  349. this.$router.go(0)
  350. }, 500)
  351. }
  352. }).catch(() => {
  353. });
  354. }).catch(err => {
  355. console.log('err', err);
  356. })
  357. },
  358. //暂存
  359. onSave() {
  360. if (this.form.peopleList) {
  361. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  362. }
  363. this.form.auditPass = false;
  364. let fileIds = [];
  365. this.fileList.forEach(v => {
  366. fileIds.push(v.id)
  367. })
  368. this.form.fileIdList = fileIds;
  369. save(this.form).then(response => {
  370. uni.showToast({
  371. title: `暂存成功`
  372. })
  373. if (this.id) {
  374. this.$emit('popupClose');
  375. } else {
  376. setTimeout(() => {
  377. this.$router.go(0)
  378. }, 500)
  379. }
  380. }).catch(() => {
  381. });
  382. },
  383. //驳回或撤回后再次提交
  384. onReCommit(ref) {
  385. this.$refs[ref].validate().then(res => {
  386. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  387. this.form.auditPass = true;
  388. reCommit(this.form).then(response => {
  389. uni.showToast({
  390. title: `提交成功`
  391. })
  392. this.$emit('popupClose');
  393. }).catch(() => {
  394. });
  395. }).catch(err => {
  396. console.log('err', err);
  397. })
  398. },
  399. //暂存删除
  400. async onDelete() {
  401. let that = this;
  402. uni.showModal({
  403. title: '提示',
  404. content: '是否确认删除?',
  405. success: function (res) {
  406. if (res.confirm) {
  407. console.log('用户点击确定');
  408. deleteById(that.id).then(response => {
  409. uni.showToast({
  410. title: "删除成功!"
  411. })
  412. that.$emit('popupClose');
  413. })
  414. } else if (res.cancel) {
  415. console.log('用户点击取消');
  416. }
  417. }
  418. });
  419. },
  420. //暂存关闭
  421. async onClose() {
  422. let that = this;
  423. uni.showModal({
  424. title: '提示',
  425. content: '是否确认关闭?',
  426. success: function (res) {
  427. if (res.confirm) {
  428. console.log('用户点击确定');
  429. closeById(that.id).then(response => {
  430. uni.showToast({
  431. title: "流程已关闭!"
  432. })
  433. that.$emit('popupClose');
  434. })
  435. } else if (res.cancel) {
  436. console.log('用户点击取消');
  437. }
  438. }
  439. });
  440. },
  441. }
  442. }
  443. </script>
  444. <style lang="scss">
  445. .table-header {
  446. position: sticky;
  447. left: 0;
  448. top: 0;
  449. z-index: 98;
  450. background-color: #fff;
  451. }
  452. //冻结表头第一列
  453. /deep/ .uni-table-tr .uni-table-td:last-child {
  454. position: sticky;
  455. right: 0;
  456. top: 0;
  457. background-color: #fff;
  458. z-index: 98;
  459. }
  460. /deep/ .uni-table-tr {
  461. overflow: visible;
  462. background-color: #fff;
  463. }
  464. /deep/ .uni-table-tr .uni-table-th:last-child {
  465. position: sticky;
  466. right: 0;
  467. top: 0;
  468. background-color: #fff;
  469. z-index: 98;
  470. }
  471. .container {
  472. padding: 15px;
  473. background-color: #fff;
  474. }
  475. .segmented-control {
  476. margin-bottom: 15px;
  477. }
  478. .button-group {
  479. margin-top: 15px;
  480. display: flex;
  481. }
  482. .form-item {
  483. display: flex;
  484. align-items: center;
  485. flex: 1;
  486. }
  487. .button {
  488. display: flex;
  489. align-items: center;
  490. height: 35px;
  491. line-height: 35px;
  492. margin-left: 10px;
  493. }
  494. </style>
  495. <style lang="scss" scoped>
  496. .user-avatar {
  497. width: 22px;
  498. height: 22px;
  499. line-height: 19px;
  500. font-size: 12px;
  501. background: #46c26f;
  502. border: 1px solid transparent;
  503. border-radius: 5px;
  504. color: #fff;
  505. display: inline-block;
  506. overflow: hidden;
  507. text-align: center;
  508. line-height: 22px;
  509. margin-bottom: 2px;
  510. }
  511. .popup-body {
  512. z-index: 99;
  513. margin-bottom: 30px;
  514. }
  515. .popup-close {
  516. cursor: pointer;
  517. height: 40px;
  518. line-height: 40px;
  519. padding-left: 10px;
  520. border-bottom: 1px solid #eaecef;
  521. }
  522. .popup-content {
  523. height: 450px;
  524. overflow-x: auto;
  525. margin: 20px;
  526. }
  527. .btn-click {
  528. transition: all 0.3s;
  529. opacity: 1;
  530. }
  531. .btn-click:active {
  532. opacity: 0.5;
  533. }
  534. .mgb-16 {
  535. margin-bottom: 16rpx;
  536. &:last-child {
  537. margin-bottom: 0;
  538. }
  539. }
  540. .upload-wrap {
  541. width: 100%;
  542. border-radius: 16rpx;
  543. background: white;
  544. // padding: 32rpx;
  545. .upload-btn {
  546. width: 100%;
  547. height: 176rpx;
  548. border: 2rpx dashed #AAAAAA;
  549. background: #FAFAFA;
  550. border-radius: 16rpx;
  551. display: flex;
  552. align-items: center;
  553. justify-content: center;
  554. flex-direction: column;
  555. .upload-icon {
  556. width: 48rpx;
  557. height: 48rpx;
  558. margin-bottom: 8rpx;
  559. }
  560. .upload-text {
  561. font-size: 26rpx;
  562. color: #9E9E9E;
  563. line-height: 40rpx;
  564. }
  565. }
  566. .file-wrap {
  567. .file-line {
  568. width: 100%;
  569. background: #F5F5F5;
  570. border-radius: 8rpx;
  571. padding: 16rpx;
  572. font-size: 26rpx;
  573. color: #1A1A1A;
  574. line-height: 40rpx;
  575. display: flex;
  576. align-items: center;
  577. justify-content: space-between;
  578. .file-info {
  579. width: 90%;
  580. display: flex;
  581. align-items: center;
  582. .file-name {
  583. max-width: 80%;
  584. padding-left: 16rpx;
  585. overflow: hidden;
  586. text-overflow: ellipsis;
  587. white-space: nowrap;
  588. }
  589. }
  590. .file-icon {
  591. width: 40rpx;
  592. height: 40rpx;
  593. flex-shrink: 0;
  594. }
  595. .file-empty {
  596. color: #999999;
  597. }
  598. }
  599. }
  600. }
  601. </style>