edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. let reason = v.reason?v.reason:'';
  336. let time = v.endTime?v.endTime:v.createTime;
  337. tasks.push({
  338. title:'任务:' + v.assigneeUser.nickname + v.name,
  339. desc: reason + " " + this.parseTime(time),
  340. })
  341. })
  342. this.tasks = tasks;
  343. }
  344. });
  345. },
  346. // 关闭标签
  347. handleClose(index) {
  348. this.nikeNamelist.splice(index, 1);
  349. let peopleList = this.form.peopleList.split(',');
  350. peopleList.splice(index, 1);
  351. this.form.peopleList = peopleList.join(',');
  352. },
  353. submitPeople(userList, nikeNamelist, userIdList) {
  354. console.log(userList);
  355. console.log(userIdList);
  356. this.nikeNamelist = nikeNamelist;
  357. this.form.peopleList = userIdList.join(',');
  358. this.$refs.popup.close();
  359. },
  360. popupClose() {
  361. this.$refs.popup.close();
  362. },
  363. gotochooseUser() {
  364. this.$refs.popup.open('bottom');
  365. setTimeout(() => {
  366. this.$refs.popleSelect.getInfoData();
  367. })
  368. },
  369. handleUploadClick() {
  370. this.$refs.XeUpload.upload('file');
  371. },
  372. handleUploadCallback(e) {
  373. console.log('UploadCallback', e);
  374. let data = {
  375. filePath: e.data[0].tempFilePath
  376. }
  377. uploadFile(data).then(response => {
  378. const tmpFiles = ([response.data] || []).map(({
  379. id,
  380. url,
  381. name,
  382. type
  383. }) => {
  384. return {
  385. id,
  386. url,
  387. name,
  388. type,
  389. };
  390. });
  391. this.fileList.push(...tmpFiles);
  392. })
  393. },
  394. // 预览
  395. handlePreview(val) {
  396. console.log('PreviewFile', val);
  397. const fileType = this.getFileType(val.name);
  398. if (fileType === 'image') {
  399. uni.previewImage({
  400. current: 0,
  401. urls: [val.url],
  402. });
  403. } else if (fileType === 'office') {
  404. return uni.downloadFile({
  405. url: val.url,
  406. success: function (res) {
  407. let filePath = res.filePath || res.tempFilePath;
  408. uni.openDocument({
  409. filePath: filePath,
  410. showMenu: true,
  411. success: function (res) {
  412. console.log('打开文档成功');
  413. }
  414. });
  415. }
  416. });
  417. } else {
  418. uni.showModal({
  419. title: '该类型文件无法预览',
  420. content: val.name,
  421. showCancel: false,
  422. });
  423. }
  424. },
  425. handleDeleteFile(index) {
  426. this.fileList.splice(index, 1);
  427. },
  428. submit(ref) {
  429. console.log('submit', this.form);
  430. this.$refs[ref].validate().then(res => {
  431. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  432. this.form.auditPass = true;
  433. let fileIds = [];
  434. this.fileList.forEach(v => {
  435. fileIds.push(v.id)
  436. })
  437. this.form.fileIdList = fileIds;
  438. create(this.form).then(response => {
  439. uni.showToast({
  440. title: `提交成功`
  441. })
  442. if (this.id) {
  443. this.$emit('popupClose');
  444. } else {
  445. setTimeout(() => {
  446. this.$router.go(0)
  447. }, 500)
  448. }
  449. }).catch(() => {
  450. });
  451. }).catch(err => {
  452. console.log('err', err);
  453. })
  454. },
  455. //暂存
  456. onSave() {
  457. if (this.form.peopleList) {
  458. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  459. }
  460. this.form.auditPass = false;
  461. let fileIds = [];
  462. this.fileList.forEach(v => {
  463. fileIds.push(v.id)
  464. })
  465. this.form.fileIdList = fileIds;
  466. save(this.form).then(response => {
  467. uni.showToast({
  468. title: `暂存成功`
  469. })
  470. if (this.id) {
  471. this.$emit('popupClose');
  472. } else {
  473. setTimeout(() => {
  474. this.$router.go(0)
  475. }, 500)
  476. }
  477. }).catch(() => {
  478. });
  479. },
  480. //驳回或撤回后再次提交
  481. onReCommit(ref) {
  482. this.$refs[ref].validate().then(res => {
  483. this.form.startUserSelectAssignees = this.form.peopleList.split(',');
  484. this.form.auditPass = true;
  485. reCommit(this.form).then(response => {
  486. uni.showToast({
  487. title: `提交成功`
  488. })
  489. this.$emit('popupClose');
  490. }).catch(() => {
  491. });
  492. }).catch(err => {
  493. console.log('err', err);
  494. })
  495. },
  496. //暂存删除
  497. async onDelete() {
  498. let that = this;
  499. uni.showModal({
  500. title: '提示',
  501. content: '是否确认删除?',
  502. success: function (res) {
  503. if (res.confirm) {
  504. console.log('用户点击确定');
  505. deleteById(that.id).then(response => {
  506. uni.showToast({
  507. title: "删除成功!"
  508. })
  509. that.$emit('popupClose');
  510. })
  511. } else if (res.cancel) {
  512. console.log('用户点击取消');
  513. }
  514. }
  515. });
  516. },
  517. //暂存关闭
  518. async onClose() {
  519. let that = this;
  520. uni.showModal({
  521. title: '提示',
  522. content: '是否确认关闭?',
  523. success: function (res) {
  524. if (res.confirm) {
  525. console.log('用户点击确定');
  526. closeById(that.id).then(response => {
  527. uni.showToast({
  528. title: "流程已关闭!"
  529. })
  530. that.$emit('popupClose');
  531. })
  532. } else if (res.cancel) {
  533. console.log('用户点击取消');
  534. }
  535. }
  536. });
  537. },
  538. }
  539. }
  540. </script>
  541. <style lang="scss">
  542. .table-header {
  543. position: sticky;
  544. left: 0;
  545. top: 0;
  546. z-index: 98;
  547. background-color: #fff;
  548. }
  549. //冻结表头第一列
  550. /deep/ .uni-table-tr .uni-table-td:last-child {
  551. position: sticky;
  552. right: 0;
  553. top: 0;
  554. background-color: #fff;
  555. z-index: 98;
  556. }
  557. /deep/ .uni-table-tr {
  558. overflow: visible;
  559. background-color: #fff;
  560. }
  561. /deep/ .uni-table-tr .uni-table-th:last-child {
  562. position: sticky;
  563. right: 0;
  564. top: 0;
  565. background-color: #fff;
  566. z-index: 98;
  567. }
  568. .container {
  569. padding: 15px;
  570. background-color: #fff;
  571. }
  572. .segmented-control {
  573. margin-bottom: 15px;
  574. }
  575. .button-group {
  576. margin-top: 15px;
  577. display: flex;
  578. }
  579. .form-item {
  580. display: flex;
  581. align-items: center;
  582. flex: 1;
  583. }
  584. .button {
  585. display: flex;
  586. align-items: center;
  587. height: 35px;
  588. line-height: 35px;
  589. margin-left: 10px;
  590. }
  591. </style>
  592. <style lang="scss" scoped>
  593. .user-avatar {
  594. width: 22px;
  595. height: 22px;
  596. line-height: 19px;
  597. font-size: 12px;
  598. background: #46c26f;
  599. border: 1px solid transparent;
  600. border-radius: 5px;
  601. color: #fff;
  602. display: inline-block;
  603. overflow: hidden;
  604. text-align: center;
  605. line-height: 22px;
  606. margin-bottom: 2px;
  607. }
  608. .popup-body {
  609. z-index: 99;
  610. margin-bottom: 30px;
  611. }
  612. .popup-close {
  613. cursor: pointer;
  614. height: 40px;
  615. line-height: 40px;
  616. padding-left: 10px;
  617. border-bottom: 1px solid #eaecef;
  618. }
  619. .popup-content {
  620. height: 450px;
  621. overflow-x: auto;
  622. margin: 20px;
  623. }
  624. .btn-click {
  625. transition: all 0.3s;
  626. opacity: 1;
  627. }
  628. .btn-click:active {
  629. opacity: 0.5;
  630. }
  631. .mgb-16 {
  632. margin-bottom: 16rpx;
  633. &:last-child {
  634. margin-bottom: 0;
  635. }
  636. }
  637. .upload-wrap {
  638. width: 100%;
  639. border-radius: 16rpx;
  640. background: white;
  641. // padding: 32rpx;
  642. .upload-btn {
  643. width: 100%;
  644. height: 176rpx;
  645. border: 2rpx dashed #AAAAAA;
  646. background: #FAFAFA;
  647. border-radius: 16rpx;
  648. display: flex;
  649. align-items: center;
  650. justify-content: center;
  651. flex-direction: column;
  652. .upload-icon {
  653. width: 48rpx;
  654. height: 48rpx;
  655. margin-bottom: 8rpx;
  656. }
  657. .upload-text {
  658. font-size: 26rpx;
  659. color: #9E9E9E;
  660. line-height: 40rpx;
  661. }
  662. }
  663. .file-wrap {
  664. .file-line {
  665. width: 100%;
  666. background: #F5F5F5;
  667. border-radius: 8rpx;
  668. padding: 16rpx;
  669. font-size: 26rpx;
  670. color: #1A1A1A;
  671. line-height: 40rpx;
  672. display: flex;
  673. align-items: center;
  674. justify-content: space-between;
  675. .file-info {
  676. width: 90%;
  677. display: flex;
  678. align-items: center;
  679. .file-name {
  680. max-width: 80%;
  681. padding-left: 16rpx;
  682. overflow: hidden;
  683. text-overflow: ellipsis;
  684. white-space: nowrap;
  685. }
  686. }
  687. .file-icon {
  688. width: 40rpx;
  689. height: 40rpx;
  690. flex-shrink: 0;
  691. }
  692. .file-empty {
  693. color: #999999;
  694. }
  695. }
  696. }
  697. }
  698. </style>