Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

539 lignes
17 KiB

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