edit.vue 14 KB

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