edit.vue 15 KB

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