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.
 
 
 
 
 
 

496 lines
14 KiB

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