edit.vue 17 KB

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