You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

661 lines
20 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="ready">
  4. <l-select @input="setValue('Purchase_Print.DepartmentId', $event)"
  5. :value="getValue('Purchase_Print.DepartmentId')" :disabled="!edit"
  6. :range="dataSource.Purchase_Print.DepartmentId" title="填报部门" required disabled />
  7. <l-organize-picker @input="setValue('Purchase_Print.Creator', $event)"
  8. :value="getValue('Purchase_Print.Creator')" :readonly="!edit" type="user" title="填报人" required readonly />
  9. <l-datetime-picker
  10. @input="setValue('Purchase_Print.Createtime', $event)"
  11. :value="getValue('Purchase_Print.Createtime')"
  12. disabled
  13. title="填报时间"
  14. />
  15. <l-input @input="setValue('Purchase_Print.Payee', $event)" :value="getValue('Purchase_Print.Payee')" title="收款人" required :disabled="!edit"/>
  16. <l-input @input="setValue('Purchase_Print.Attachcount', $event)" :value="getValue('Purchase_Print.Attachcount')" title="附件张数" :disabled="!edit"/>
  17. <l-upload-file @input="setValue('Purchase_Print.FilePath', $event)" :value="getValue('Purchase_Print.FilePath')"
  18. tableName="Purchase_Print" fieldName="FilePath" title="附件" :number="9" :readonly="!edit" />
  19. <l-input @input="setValue('Purchase_Print.Totalamount', $event)" :value="getValue('Purchase_Print.Totalamount')" title="申请报账金额" required :disabled="!edit"/>
  20. <!-- <l-textarea @input="setValue('Purchase_Print.Remark', $event)" :value="getValue('Purchase_Print.Remark')"
  21. :readonly="!edit" title="备注" /> -->
  22. <!-- <l-select
  23. @input="setValue('Purchase_Print.Status', $event)"
  24. :value="getValue('Purchase_Print.Status')"
  25. :disabled="!edit"
  26. :range="dataSource.Purchase_Print.Status"
  27. title="是否提交"
  28. />
  29. <l-datetime-picker
  30. @input="setValue('Purchase_Print.SubmitTime', $event)"
  31. :value="getValue('Purchase_Print.SubmitTime')"
  32. :disabled="!edit"
  33. title="提交时间"
  34. /> -->
  35. <!-- <l-select
  36. @input="setValue('Purchase_Print.CheckStatus', $event)"
  37. :value="getValue('Purchase_Print.CheckStatus')"
  38. :disabled="!edit"
  39. :range="dataSource.Purchase_Print.CheckStatus"
  40. title="审核状态"
  41. />
  42. <l-datetime-picker
  43. @input="setValue('Purchase_Print.CheckTime', $event)"
  44. :value="getValue('Purchase_Print.CheckTime')"
  45. :disabled="!edit"
  46. title="审核时间"
  47. />
  48. <l-organize-picker
  49. @input="setValue('Purchase_Print.CheckUserId', $event)"
  50. :value="getValue('Purchase_Print.CheckUserId')"
  51. :readonly="!edit"
  52. type="user"
  53. title="审核人"
  54. /> -->
  55. <l-input @input="setValue('Purchase_Print.Approvalamount', $event)" :value="getValue('Purchase_Print.Approvalamount')"
  56. :disabled="!edit||!isEdit('Approvalamount')" title="核准金额" />
  57. <view style="background-color: #fff;">
  58. <view style="line-height: 40px;font-size: 14px;padding-left: 12px;">
  59. 报账明细:
  60. </view>
  61. <view v-if="edit" class="customlist-banner-action" style="display: flex;">
  62. <view
  63. @click="detailAdd"
  64. class="customlist-banner-action-btn line-blue text-sm"
  65. style="border: currentColor 1px solid;border-radius: 4px;margin: 8px;padding: 2px 4px;">
  66. <l-icon type="add" />
  67. 新增
  68. </view>
  69. <view
  70. @click="detailDelete"
  71. class="customlist-banner-action-btn line-red text-sm"
  72. style="border: currentColor 1px solid;border-radius: 4px;margin: 8px;padding: 2px 4px;">
  73. <l-icon type="delete" />
  74. 删除
  75. </view>
  76. </view>
  77. <next-table ref="table" :show-header="true" :columns="column" :stripe="true" :fit="false" :border="true" :data="data"
  78. :highlight="true" @currentChange="currentChange">
  79. </next-table>
  80. <l-customform-table
  81. :value="currentRowDetail" :item="Purchase_Print_Details"
  82. :edit="false" />
  83. </view>
  84. </view>
  85. <!-- 指派审核人弹窗 -->
  86. <l-modal v-model="modal" @close="reviewer = ''" title="指派审核人">
  87. <l-checkbox-picker @input="(e)=>{reviewer = e}" :value="reviewer" :readonly="false" :range="reviewerList"
  88. required title="审核人" />
  89. <l-button @click="userAssign" color="blue" class="block" block>确定指派</l-button>
  90. <l-button @click="()=>{modal = false;reviewer = ''}" line="blue" class="block margin-top-sm" block>取消</l-button>
  91. </l-modal>
  92. <view v-if="ready && current.Purchase_Print && current.Purchase_Print.status != '1'" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;">
  93. <l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block>
  94. 保存
  95. </l-button>
  96. <l-button v-if="edit" @click="action('save',true)" size="lg" color="orange" class="block margin-top" block>
  97. 保存并提交
  98. </l-button>
  99. <!-- <l-button v-if="!edit && mode !== 'create'" @click="action('edit')" size="lg" line="orange" class="block margin-top" block>
  100. 编辑本页
  101. </l-button>
  102. <l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block>
  103. 取消编辑
  104. </l-button>
  105. <l-button v-if="!edit && mode !== 'create'" @click="action('delete')" size="lg" line="red" class="block margin-top" block>
  106. 删除
  107. </l-button> -->
  108. </view>
  109. </view>
  110. </template>
  111. <script>
  112. /*
  113. * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  114. * Copyright (c) 2013-2020 上海力软信息技术有限公司
  115. * 创建人:超级管理员
  116. * 日 期:2020-10-20 09:25
  117. * 描 述:活动安排
  118. */
  119. /**
  120. * 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
  121. * 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
  122. * { "path": "pages/PersonnelManagement/BookBorrow/single", "style": { "navigationBarTitleText": "表单详情页" } }
  123. *
  124. * (navigationBarTitleText 字段为本页面的标题文本,可以修改)
  125. * (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
  126. */
  127. import get from 'lodash/get'
  128. import set from 'lodash/set'
  129. import moment from 'moment'
  130. import customPageMixins from '@/common/custompage.js'
  131. import workflowFormMixins from '@/pages/nworkflow/workflow.js'
  132. export default {
  133. mixins: [workflowFormMixins,customPageMixins,],
  134. data() {
  135. return {
  136. // 页面相关参数
  137. id: null,
  138. mode: null,
  139. edit: null,
  140. ready: false,
  141. // 表单数据
  142. current: {},
  143. origin: {},
  144. // 表单项数据结构
  145. scheme: {
  146. Purchase_Print: {
  147. DepartmentId: {
  148. type: 'select',
  149. title: '填报部门'
  150. },
  151. Creator: {
  152. type: 'organize',
  153. title: '填报人',
  154. },
  155. Createtime: { type: 'datetime', title: '填报时间', dateformat: '1' },
  156. Payee: {
  157. title: '收款人',
  158. verify:'NotNull'
  159. },
  160. Attachcount: {
  161. title: '附件张数'
  162. },
  163. Totalamount: {
  164. type: 'text',
  165. title: '申请报账金额',
  166. verify:'Price'
  167. },
  168. // Remark: {
  169. // type: 'textarea',
  170. // title: '备注'
  171. // },
  172. FilePath: {
  173. type: 'upload',
  174. title: '附件'
  175. },
  176. Approvalamount:{title:'核准金额',verify:'PriceOrNull'},
  177. // Status: { type: 'select', title: '是否提交' },
  178. // SubmitTime:{ type: 'datetime', title: '提交时间', dateformat: '1' },
  179. // CheckTime:{ type: 'datetime', title: '审核时间', dateformat: '1' },
  180. // CheckUserId:{ type: 'organize', title: '审核人' },
  181. // CheckStatus:{ type: 'select', title: '审核状态', },
  182. },
  183. },
  184. Purchase_Print_Details: {
  185. type: 'girdtable',
  186. title: '采购列表',
  187. __defaultItem__: {},
  188. fieldsData: [{
  189. field: 'Name',
  190. type: 'input',
  191. name: '采购物品名称'
  192. },
  193. {
  194. field: 'Price',
  195. type: 'input',
  196. name: '价格'
  197. },
  198. {
  199. field: 'Quantity',
  200. type: 'input',
  201. name: '采购数量'
  202. },
  203. {
  204. field: 'Unit',
  205. type: 'input',
  206. name: '单位'
  207. },
  208. {
  209. field: 'UseTo',
  210. type: 'input',
  211. name: '用途'
  212. },
  213. { field:'Spec', type:'input', name:'规格' },
  214. ]
  215. },
  216. // 数据源
  217. dataSource: {
  218. Purchase_Print: {
  219. DepartmentId: [],
  220. Status: [{
  221. text: '已提交',
  222. value: '1'
  223. }, {
  224. text: '未提交',
  225. value: '2'
  226. }],
  227. CheckStatus: [{
  228. text: '审核中',
  229. value: '1'
  230. }, {
  231. text: '审核通过',
  232. value: '2'
  233. }, {
  234. text: '',
  235. value: '草稿'
  236. }]
  237. },
  238. },
  239. // 采购数据
  240. column:[
  241. // { type:'selection', fixed:true,width:60 },
  242. // { name: 'CreatorName', label: '申请人',width:80,emptyString:'--' },
  243. { name: 'TotalAmount', label: '金额',fixed:false,width:86,emptyString:'--' },
  244. // { name: 'DepartmentName', label: '部门',fixed:false,width:200,emptyString:'--' },
  245. { name: 'Remark', label: '备注',fixed:false,width:126,emptyString:'--' },
  246. { name: 'CreateTime', label: '申请时间',width:80,emptyString:'--' },
  247. // { name: 'SubmitTime', label: '提交时间',fixed:false,width:146,emptyString:'--' },
  248. // { name: 'CheckTime', label: '审核时间',fixed:false,width:146,emptyString:'--' },
  249. ],
  250. data:[],
  251. page: 1,
  252. total: 1,
  253. rows:8,
  254. list: [],
  255. currentRow:null,
  256. currentRowDetail:[],
  257. type:null,
  258. code:null,
  259. level: '1',
  260. processId:null,
  261. // 指派审核人数据
  262. modal: false,
  263. userAssignData:{},//收集数据用来判断是否需要审核人
  264. reviewerListId:'',
  265. reviewerList:[],
  266. submitPostData:{},
  267. reviewer: [],
  268. authorize:{},
  269. }
  270. },
  271. async onLoad({
  272. type,
  273. id
  274. }) {
  275. await this.init(type, id)
  276. },
  277. onUnload() {
  278. this.OFF('details-change')
  279. },
  280. methods: {
  281. // 页面初始化
  282. async init(type, id) {
  283. this.LOADING('加载数据中...')
  284. this.ON('details-change',this.dataChange)
  285. this.id = id
  286. this.mode = type
  287. this.edit = ['create', 'edit'].includes(this.mode)
  288. this.type = type
  289. this.code = '1-6'
  290. const currentTask = this.GET_PARAM()
  291. // 新建表单则生成
  292. this.processId = this.GUID('-')
  293. const processInfo = await this.fetchProcessInfo({ code:this.code })
  294. const currentNode = this.getCurrentNode(processInfo)
  295. this.userAssignData.currentTask = currentTask
  296. this.userAssignData.currentNode = currentNode
  297. // wfForms 的数组成员 t,表示表单数据项(TAB页),t.type 表示类别,注意它是字符串型,用 Number(t.type) 转换
  298. // 为 1 则使用工作流表单,依据它的 .formId
  299. // 不为 1 则使用系统表单,依据它的 .appurl
  300. const { wfForms } = currentNode
  301. // 处理没有有效表单的情况,停止加载
  302. if (!wfForms || wfForms.length <= 0) {
  303. this.HIDE_LOADING()
  304. this.TOAST('移动表单数据(wfForms)中无有效表单')
  305. return
  306. }
  307. // 权限
  308. if(currentNode.wfForms && currentNode.wfForms[0].authorize){
  309. let arr = Object.values(currentNode.wfForms[0].authorize)
  310. for (let item of arr) {
  311. this.authorize[item.fieldId] = item
  312. }
  313. }
  314. // 拉取表单数据,同时拉取所有来自数据源的选单数据
  315. await Promise.all([
  316. this.FETCH_DATASOURCE('classdata').then(data => {
  317. this.dataSource.Purchase_Print.DepartmentId = data.data.map(t => ({
  318. text: t.name,
  319. value: t.id
  320. }));
  321. }),
  322. () => {}
  323. ])
  324. await this.fetchForm()
  325. this.ready = true
  326. this.HIDE_LOADING()
  327. },
  328. isEdit(field){
  329. return this.authorize[field] && this.authorize[field].isEdit !== 0
  330. },
  331. // 加载表单数据
  332. async fetchForm() {
  333. if (this.mode === 'create') {
  334. this.origin = await this.getDefaultForm()
  335. let userInfo = this.GET_GLOBAL('loginUser');
  336. this.origin.Purchase_Print.DepartmentId = userInfo.departmentId
  337. this.origin.Purchase_Print.Creator = userInfo.userId
  338. } else {
  339. const result = await this.HTTP_GET('learun/adms/purchaseprintapply/form', this.id)
  340. this.origin = await this.formatFormData({
  341. Purchase_Print: result.Purchase_Print,
  342. })
  343. this.data = result.Purchase_Print_Details
  344. }
  345. this.current = this.COPY(this.origin)
  346. },
  347. // 计算报账金额
  348. getamount(){
  349. let getamount = 0
  350. this.data.forEach(e=>{
  351. getamount = this.accAdd(e.TotalAmount,getamount)
  352. })
  353. this.setValue('Purchase_Print.Totalamount', getamount)
  354. },
  355. // 点击某一行
  356. async currentChange(row){
  357. this.currentRow = row
  358. this.currentRowDetail = []
  359. const result = await this.HTTP_GET('learun/adms/purchaseprint/formdetail',row.purchaseid)
  360. if(!result)return
  361. this.currentRowDetail = result
  362. },
  363. // 新增明细数据
  364. dataChange(data){
  365. data.forEach(e=>{
  366. if(!this.data.find(e1=>e.Id == e1.purchaseid)){
  367. e.purchaseid = e.Id
  368. this.data.push(e)
  369. }
  370. })
  371. this.getamount()
  372. },
  373. async detailDelete(){
  374. if(!this.currentRow){
  375. this.TOAST('请选中某一项')
  376. return
  377. }
  378. if (!(await this.CONFIRM('删除项目', '确定要删除选中项吗?', true))) {
  379. return
  380. }
  381. let index;
  382. this.data.find((e,i)=>{
  383. if(e.Id == this.currentRow.Id){
  384. index = i
  385. return true
  386. }
  387. })
  388. this.data.splice(index,1)
  389. this.$refs.table.resetHighlight()
  390. this.currentRow = null
  391. this.currentRowDetail = []
  392. this.getamount()
  393. },
  394. // 新增明细
  395. detailAdd(){
  396. // this.NAV_TO('./details',this.data,true)
  397. this.NAV_TO('./details')
  398. },
  399. // 乘法函数
  400. accMul(arg1, arg2) {
  401. let m = 0,
  402. s1 = arg1.toString(),
  403. s2 = arg2.toString()
  404. try {
  405. m += s1.split('.')[1].length
  406. } catch (e) {}
  407. try {
  408. m += s2.split('.')[1].length
  409. } catch (e) {}
  410. return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
  411. },
  412. // 加法函数
  413. accAdd(arg1, arg2) {
  414. let r1, r2, m
  415. try {
  416. r1 = arg1.toString().split('.')[1].length
  417. } catch (e) {
  418. r1 = 0
  419. }
  420. try {
  421. r2 = arg2.toString().split('.')[1].length
  422. } catch (e) {
  423. r2 = 0
  424. }
  425. m = Math.pow(10, Math.max(r1, r2))
  426. return (arg1 * m + arg2 * m) / m
  427. },
  428. // 指派审核人
  429. async userAssign() {
  430. this.modal = false
  431. if(!this.reviewer.length){
  432. this.TOAST('请选择审核人')
  433. return
  434. }
  435. this.LOADING('正在提交…')
  436. let postData = {
  437. auditors :JSON.stringify({[this.reviewerListId]:this.reviewer.toString()}),
  438. level : this.level,
  439. code: this.code,
  440. processId: this.processId,
  441. }
  442. const url = 'learun/adms/newwf/createnoform'
  443. const tips = `流程发起失败`
  444. this.HTTP_POST(url, postData, tips).then(success => {
  445. this.HIDE_LOADING()
  446. if (!success) {
  447. return
  448. }
  449. this.submit1()
  450. })
  451. },
  452. // 发起流程
  453. async submit() {
  454. // 判断是否指派审核人
  455. let isNext = this.userAssignData.currentNode.isNext
  456. Object.assign(this.userAssignData,{ code: 'agree' })
  457. if (this.userAssignData.next == '2') {
  458. isNext = '1';
  459. }
  460. if (isNext == '1') {
  461. let params = {
  462. code: this.code,
  463. processId: this.processId,
  464. taskId: '',
  465. nodeId: this.userAssignData.currentNode.id,
  466. operationCode: this.userAssignData.code,
  467. }
  468. this.LOADING('正在获取审核人…')
  469. const userList = await this.HTTP_GET('learun/adms/newwf/auditer', params, `获取审核人时发生错误`)
  470. this.HIDE_LOADING()
  471. if (!userList) {
  472. return
  473. }
  474. let arr = Object.entries(userList)
  475. this.reviewerListId = arr[0][0]
  476. this.reviewerList = arr[0][1].map(item => {
  477. return {
  478. text: item.Name,
  479. value: item.Id
  480. }
  481. })
  482. if(this.reviewerList.length>1){
  483. this.modal = true
  484. return
  485. }
  486. }
  487. this.LOADING('正在提交…')
  488. let postData = {
  489. auditors :JSON.stringify({}),
  490. level : this.level,
  491. code: this.code,
  492. processId: this.processId,
  493. }
  494. const url = 'learun/adms/newwf/createnoform'
  495. const tips = `流程发起失败`
  496. this.HTTP_POST(url, postData, tips).then(success => {
  497. this.HIDE_LOADING()
  498. if (!success) {
  499. return
  500. }
  501. this.submit1()
  502. })
  503. },
  504. // 提交
  505. async submit1(){
  506. // if (!(await this.CONFIRM('提交项目', '是否确认提交该项?', true))) {
  507. // return
  508. // }
  509. this.LOADING('正在提交...')
  510. this.HTTP_POST('learun/adms/purchaseprintapply/submit', {Id:this.id, ProcessId:this.processId} , '提交失败').then(
  511. success => {
  512. this.HIDE_LOADING()
  513. if (!success) {
  514. return
  515. }
  516. this.TOAST('提交成功', 'success')
  517. this.EMIT('LogisticsapplyManagement-Purchase_Print-list-change')
  518. this.NAV_BACK()
  519. })
  520. return
  521. },
  522. // 点击 「编辑」、「重置」、「保存」、「删除」 按钮
  523. async action(type,isSubmit=false) {
  524. switch (type) {
  525. case 'edit':
  526. this.edit = true
  527. break
  528. case 'reset':
  529. this.current = this.COPY(this.origin)
  530. this.edit = false
  531. break
  532. case 'save':
  533. const verifyResult = this.verifyForm()
  534. if (verifyResult.length > 0) {
  535. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  536. return
  537. }
  538. if(this.getValue('Purchase_Print.Totalamount')=='0'&& this.data.length == 0){
  539. this.CONFIRM('表单验证失败', '报账金额为0且报账明细为空')
  540. return
  541. }
  542. if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  543. return
  544. }
  545. this.LOADING('正在提交...')
  546. const postData = await this.getPostData(this.id)
  547. // // 处理列表数据
  548. let strEntity = JSON.parse(postData.strEntity)
  549. for (let s of this.data) {
  550. s.TotalAmount = Number(s.TotalAmount);
  551. s.TotalAmount = Number(s.TotalAmount)
  552. }
  553. let DetailList = this.data.map(e=>{
  554. return {
  555. purchaseid:e.purchaseid
  556. }
  557. })
  558. postData.DetailList = JSON.stringify(DetailList)
  559. // 赋值部门和人员数据
  560. let userInfo = this.GET_GLOBAL('loginUser');
  561. let obj = this.dataSource.Purchase_Print.DepartmentId.find(e => e.value == this.origin
  562. .Purchase_Print.DepartmentId)
  563. strEntity.deptname = obj ? obj.text : ''
  564. strEntity.creatorname = userInfo.realName
  565. // 格式化数据
  566. strEntity.Approvalamount = Number(strEntity.Approvalamount)
  567. strEntity.Totalamount = Number(strEntity.Totalamount)
  568. postData.strEntity = JSON.stringify(strEntity)
  569. // console.log(postData,JSON.parse(postData.strEntity))
  570. this.HTTP_POST('learun/adms/purchaseprintapply/save', postData, '表单提交保存失败').then(success => {
  571. this.HIDE_LOADING()
  572. if (!success) {
  573. return
  574. }
  575. this.id = success.Id
  576. if(isSubmit){
  577. this.submit()
  578. return
  579. }
  580. this.EMIT('LogisticsapplyManagement-Purchase_Print-list-change')
  581. setTimeout(()=>this.NAV_BACK(),500)
  582. this.TOAST('提交保存成功')
  583. })
  584. break
  585. case 'delete':
  586. if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?', true))) {
  587. return
  588. }
  589. this.LOADING('提交删除中...')
  590. this.HTTP_POST('learun/adms/purchaseprintapply/delete', this.id, '删除失败').then(success => {
  591. this.HIDE_LOADING()
  592. if (!success) {
  593. return
  594. }
  595. this.EMIT('LogisticsapplyManagement-Purchase_Print-list-change')
  596. this.NAV_BACK()
  597. this.this.TOAST('删除成功', 'success')
  598. })
  599. break
  600. default:
  601. break
  602. }
  603. },
  604. // 获取表单值
  605. getValue(path) {
  606. return get(this.current, path)
  607. },
  608. // 设置表单值
  609. setValue(path, val) {
  610. set(this.current, path, val)
  611. },
  612. }
  613. }
  614. </script>