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.
 
 
 
 
 
 

506 lines
15 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="ready">
  4. <l-select @input="setValue('Purchase_Travel.DepartmentId', $event)"
  5. :value="getValue('Purchase_Travel.DepartmentId')" :disabled="!edit"
  6. :range="dataSource.Purchase_Travel.DepartmentId" title="填报部门" required disabled />
  7. <l-organize-picker @input="setValue('Purchase_Travel.Creator', $event)"
  8. :value="getValue('Purchase_Travel.Creator')" :readonly="!edit" type="user" title="填报人" required readonly />
  9. <l-datetime-picker
  10. @input="setValue('Purchase_Travel.Createtime', $event)"
  11. :value="getValue('Purchase_Travel.Createtime')"
  12. disabled
  13. title="填报时间"
  14. />
  15. <l-input @input="setValue('Purchase_Travel.Follows', $event)" :value="getValue('Purchase_Travel.Follows')" title="随行人员" required :disabled="!edit"/>
  16. <l-textarea @input="setValue('Purchase_Travel.Reason', $event)" :value="getValue('Purchase_Travel.Reason')"
  17. :readonly="!edit" title="原因" />
  18. <l-date-picker
  19. @input="setValue('Purchase_Travel.Starttime', $event)"
  20. :value="getValue('Purchase_Travel.Starttime')"
  21. disabled
  22. title="开始时间"
  23. />
  24. <l-date-picker
  25. @input="setValue('Purchase_Travel.Endtime', $event)"
  26. :value="getValue('Purchase_Travel.Endtime')"
  27. disabled
  28. title="结束时间"
  29. />
  30. <l-upload-file @input="setValue('Purchase_Travel.FilePath', $event)" :value="getValue('Purchase_Travel.FilePath')"
  31. tableName="Purchase_Travel" fieldName="FilePath" title="附件" :number="9" :readonly="!edit" />
  32. <l-input @input="setValue('Purchase_Travel.Totalamount', $event)" :value="getValue('Purchase_Travel.Totalamount')" title="申请报账金额" required :disabled="!edit"/>
  33. <!-- <l-textarea @input="setValue('Purchase_Travel.Remark', $event)" :value="getValue('Purchase_Travel.Remark')"
  34. :readonly="!edit" title="备注" /> -->
  35. <!-- <l-select
  36. @input="setValue('Purchase_Travel.Status', $event)"
  37. :value="getValue('Purchase_Travel.Status')"
  38. :disabled="!edit"
  39. :range="dataSource.Purchase_Travel.Status"
  40. title="是否提交"
  41. />
  42. <l-datetime-picker
  43. @input="setValue('Purchase_Travel.SubmitTime', $event)"
  44. :value="getValue('Purchase_Travel.SubmitTime')"
  45. :disabled="!edit"
  46. title="提交时间"
  47. /> -->
  48. <!-- <l-select
  49. @input="setValue('Purchase_Travel.CheckStatus', $event)"
  50. :value="getValue('Purchase_Travel.CheckStatus')"
  51. :disabled="!edit"
  52. :range="dataSource.Purchase_Travel.CheckStatus"
  53. title="审核状态"
  54. />
  55. <l-datetime-picker
  56. @input="setValue('Purchase_Travel.CheckTime', $event)"
  57. :value="getValue('Purchase_Travel.CheckTime')"
  58. :disabled="!edit"
  59. title="审核时间"
  60. />
  61. <l-organize-picker
  62. @input="setValue('Purchase_Travel.CheckUserId', $event)"
  63. :value="getValue('Purchase_Travel.CheckUserId')"
  64. :readonly="!edit"
  65. type="user"
  66. title="审核人"
  67. /> -->
  68. <l-input @input="setValue('Purchase_Travel.Approvalamount', $event)" :value="getValue('Purchase_Travel.Approvalamount')"
  69. :disabled="!edit" title="核准金额" />
  70. <view style="background-color: #fff;">
  71. <view style="line-height: 40px;font-size: 14px;padding-left: 12px;">
  72. 报账明细:
  73. </view>
  74. <view v-if="edit" class="customlist-banner-action" style="display: flex;">
  75. <view
  76. @click="detailAdd"
  77. class="customlist-banner-action-btn line-blue text-sm"
  78. style="border: currentColor 1px solid;border-radius: 4px;margin: 8px;padding: 2px 4px;">
  79. <l-icon type="add" />
  80. 新增
  81. </view>
  82. <view
  83. @click="detailDelete"
  84. class="customlist-banner-action-btn line-red text-sm"
  85. style="border: currentColor 1px solid;border-radius: 4px;margin: 8px;padding: 2px 4px;">
  86. <l-icon type="delete" />
  87. 删除
  88. </view>
  89. </view>
  90. <next-table ref="table" :show-header="true" :columns="column" :stripe="true" :fit="false" :border="true" :data="data"
  91. :highlight="true" @currentChange="currentChange">
  92. </next-table>
  93. <l-customform-table
  94. :value="currentRowDetail" :item="Purchase_Travel_Details"
  95. :edit="false" />
  96. </view>
  97. </view>
  98. <view v-if="ready && current.Purchase_Travel && current.Purchase_Travel.status != '1'"
  99. class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;">
  100. <l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block>
  101. 提交保存
  102. </l-button>
  103. <!-- <l-button v-if="!edit && mode !== 'create'" @click="action('edit')" size="lg" line="orange" class="block margin-top" block>
  104. 编辑本页
  105. </l-button>
  106. <l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block>
  107. 取消编辑
  108. </l-button>
  109. <l-button v-if="!edit && mode !== 'create'" @click="action('delete')" size="lg" line="red" class="block margin-top" block>
  110. 删除
  111. </l-button> -->
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. /*
  117. * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  118. * Copyright (c) 2013-2020 上海力软信息技术有限公司
  119. * 创建人:超级管理员
  120. * 日 期:2020-10-20 09:25
  121. * 描 述:活动安排
  122. */
  123. /**
  124. * 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
  125. * 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
  126. * { "path": "pages/PersonnelManagement/BookBorrow/single", "style": { "navigationBarTitleText": "表单详情页" } }
  127. *
  128. * (navigationBarTitleText 字段为本页面的标题文本,可以修改)
  129. * (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
  130. */
  131. import get from 'lodash/get'
  132. import set from 'lodash/set'
  133. import moment from 'moment'
  134. import customPageMixins from '@/common/custompage.js'
  135. export default {
  136. mixins: [customPageMixins],
  137. data() {
  138. return {
  139. // 页面相关参数
  140. id: null,
  141. mode: null,
  142. edit: null,
  143. ready: false,
  144. // 表单数据
  145. current: {},
  146. origin: {},
  147. // 表单项数据结构
  148. scheme: {
  149. Purchase_Travel: {
  150. DepartmentId: {
  151. type: 'select',
  152. title: '填报部门'
  153. },
  154. Creator: {
  155. type: 'organize',
  156. title: '填报人',
  157. },
  158. Createtime: { type: 'datetime', title: '填报时间', dateformat: '1' },
  159. Follows:{ type:'text', title: '随行人员',verify:'NotNull' },
  160. Reason:{ type:'text', title: '出差原因'},
  161. Starttime: { type: 'datetime', title: '开始时间', dateformat: '0' },
  162. Endtime: { type: 'datetime', title: '结束时间', dateformat: '0' },
  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_Travel_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. ]
  214. },
  215. // 数据源
  216. dataSource: {
  217. Purchase_Travel: {
  218. DepartmentId: [],
  219. Status: [{
  220. text: '已提交',
  221. value: '1'
  222. }, {
  223. text: '未提交',
  224. value: '2'
  225. }],
  226. CheckStatus: [{
  227. text: '审核中',
  228. value: '1'
  229. }, {
  230. text: '审核通过',
  231. value: '2'
  232. }, {
  233. text: '',
  234. value: '草稿'
  235. }]
  236. },
  237. },
  238. // 采购数据
  239. column:[
  240. // { type:'selection', fixed:true,width:60 },
  241. // { name: 'CreatorName', label: '申请人',width:80,emptyString:'--' },
  242. { name: 'TotalAmount', label: '金额',fixed:false,width:86,emptyString:'--' },
  243. // { name: 'DepartmentName', label: '部门',fixed:false,width:200,emptyString:'--' },
  244. { name: 'Remark', label: '备注',fixed:false,width:126,emptyString:'--' },
  245. { name: 'CreateTime', label: '申请时间',width:80,emptyString:'--' },
  246. // { name: 'SubmitTime', label: '提交时间',fixed:false,width:146,emptyString:'--' },
  247. // { name: 'CheckTime', label: '审核时间',fixed:false,width:146,emptyString:'--' },
  248. ],
  249. data:[],
  250. page: 1,
  251. total: 1,
  252. rows:8,
  253. list: [],
  254. currentRow:null,
  255. currentRowDetail:[],
  256. }
  257. },
  258. async onLoad({
  259. type,
  260. id
  261. }) {
  262. await this.init(type, id)
  263. },
  264. onUnload() {
  265. this.OFF('details-change')
  266. },
  267. methods: {
  268. // 页面初始化
  269. async init(type, id) {
  270. this.LOADING('加载数据中...')
  271. this.ON('details-change',this.dataChange)
  272. this.id = id
  273. this.mode = type
  274. this.edit = ['create', 'edit'].includes(this.mode)
  275. // 拉取表单数据,同时拉取所有来自数据源的选单数据
  276. await Promise.all([
  277. this.FETCH_DATASOURCE('classdata').then(data => {
  278. this.dataSource.Purchase_Travel.DepartmentId = data.data.map(t => ({
  279. text: t.name,
  280. value: t.id
  281. }));
  282. }),
  283. () => {}
  284. ])
  285. await this.fetchForm()
  286. this.ready = true
  287. this.HIDE_LOADING()
  288. },
  289. // 加载表单数据
  290. async fetchForm() {
  291. if (this.mode === 'create') {
  292. this.origin = await this.getDefaultForm()
  293. let userInfo = this.GET_GLOBAL('loginUser');
  294. this.origin.Purchase_Travel.DepartmentId = userInfo.departmentId
  295. this.origin.Purchase_Travel.Creator = userInfo.userId
  296. } else {
  297. const result = await this.HTTP_GET('learun/adms/purchasetravelapply/form', this.id)
  298. this.origin = await this.formatFormData({
  299. Purchase_Travel: result.Purchase_Travel,
  300. })
  301. this.data = result.Purchase_Travel_Details
  302. }
  303. this.current = this.COPY(this.origin)
  304. },
  305. // 计算报账金额
  306. getamount(){
  307. let getamount = 0
  308. this.data.forEach(e=>{
  309. getamount = this.accAdd(e.TotalAmount,getamount)
  310. })
  311. this.setValue('Purchase_Travel.Totalamount', getamount)
  312. },
  313. // 点击某一行
  314. async currentChange(row){
  315. this.currentRow = row
  316. // this.currentRowDetail = []
  317. // const result = await this.HTTP_GET('learun/adms/purchasetravel/formdetail',row.purchaseid)
  318. // if(!result)return
  319. // this.currentRowDetail = result
  320. },
  321. // 新增明细数据
  322. dataChange(data){
  323. data.forEach(e=>{
  324. if(!this.data.find(e1=>e.Id == e1.purchaseid)){
  325. e.purchaseid = e.Id
  326. this.data.push(e)
  327. }
  328. })
  329. this.getamount()
  330. },
  331. async detailDelete(){
  332. if(!this.currentRow){
  333. this.TOAST('请选中某一项')
  334. return
  335. }
  336. if (!(await this.CONFIRM('删除项目', '确定要删除选中项吗?', true))) {
  337. return
  338. }
  339. let index;
  340. this.data.find((e,i)=>{
  341. if(e.Id == this.currentRow.Id){
  342. index = i
  343. return true
  344. }
  345. })
  346. this.data.splice(index,1)
  347. this.$refs.table.resetHighlight()
  348. this.currentRow = null
  349. this.currentRowDetail = []
  350. this.getamount()
  351. },
  352. // 新增明细
  353. detailAdd(){
  354. // this.NAV_TO('./details',this.data,true)
  355. this.NAV_TO('./details')
  356. },
  357. // 乘法函数
  358. accMul(arg1, arg2) {
  359. let m = 0,
  360. s1 = arg1.toString(),
  361. s2 = arg2.toString()
  362. try {
  363. m += s1.split('.')[1].length
  364. } catch (e) {}
  365. try {
  366. m += s2.split('.')[1].length
  367. } catch (e) {}
  368. return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
  369. },
  370. // 加法函数
  371. accAdd(arg1, arg2) {
  372. let r1, r2, m
  373. try {
  374. r1 = arg1.toString().split('.')[1].length
  375. } catch (e) {
  376. r1 = 0
  377. }
  378. try {
  379. r2 = arg2.toString().split('.')[1].length
  380. } catch (e) {
  381. r2 = 0
  382. }
  383. m = Math.pow(10, Math.max(r1, r2))
  384. return (arg1 * m + arg2 * m) / m
  385. },
  386. // 点击 「编辑」、「重置」、「保存」、「删除」 按钮
  387. async action(type) {
  388. switch (type) {
  389. case 'edit':
  390. this.edit = true
  391. break
  392. case 'reset':
  393. this.current = this.COPY(this.origin)
  394. this.edit = false
  395. break
  396. case 'save':
  397. const verifyResult = this.verifyForm()
  398. if (verifyResult.length > 0) {
  399. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  400. return
  401. }
  402. if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  403. return
  404. }
  405. this.LOADING('正在提交...')
  406. const postData = await this.getPostData(this.id)
  407. // // 处理列表数据
  408. let strEntity = JSON.parse(postData.strEntity)
  409. for (let s of this.data) {
  410. s.TotalAmount = Number(s.TotalAmount);
  411. s.TotalAmount = Number(s.TotalAmount)
  412. }
  413. let DetailList = this.data.map(e=>{
  414. return {
  415. purchaseid:e.purchaseid
  416. }
  417. })
  418. postData.DetailList = JSON.stringify(DetailList)
  419. // 赋值部门和人员数据
  420. let userInfo = this.GET_GLOBAL('loginUser');
  421. let obj = this.dataSource.Purchase_Travel.DepartmentId.find(e => e.value == this.origin
  422. .Purchase_Travel.DepartmentId)
  423. strEntity.deptname = obj ? obj.text : ''
  424. strEntity.creatorname = userInfo.realName
  425. // 格式化数据
  426. strEntity.Approvalamount = Number(strEntity.Approvalamount)
  427. strEntity.Totalamount = Number(strEntity.Totalamount)
  428. postData.strEntity = JSON.stringify(strEntity)
  429. // console.log(postData,JSON.parse(postData.strEntity))
  430. this.HTTP_POST('learun/adms/purchasetravelapply/save', postData, '表单提交保存失败').then(success => {
  431. this.HIDE_LOADING()
  432. if (!success) {
  433. return
  434. }
  435. this.EMIT('LogisticsapplyManagement-Purchase_Travel-list-change')
  436. this.NAV_BACK()
  437. this.TOAST('提交保存成功')
  438. })
  439. break
  440. case 'delete':
  441. if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?', true))) {
  442. return
  443. }
  444. this.LOADING('提交删除中...')
  445. this.HTTP_POST('learun/adms/purchasetravelapply/delete', this.id, '删除失败').then(success => {
  446. this.HIDE_LOADING()
  447. if (!success) {
  448. return
  449. }
  450. this.EMIT('LogisticsapplyManagement-Purchase_Travel-list-change')
  451. this.NAV_BACK()
  452. this.this.TOAST('删除成功', 'success')
  453. })
  454. break
  455. default:
  456. break
  457. }
  458. },
  459. // 获取表单值
  460. getValue(path) {
  461. return get(this.current, path)
  462. },
  463. // 设置表单值
  464. setValue(path, val) {
  465. set(this.current, path, val)
  466. },
  467. }
  468. }
  469. </script>