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.
 
 
 
 
 
 

518 lines
16 KiB

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