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.
 
 
 
 
 
 

513 lines
16 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="ready">
  4. <l-select
  5. @input="setValue('Purchase_Service.DepartmentId', $event)"
  6. :value="getValue('Purchase_Service.DepartmentId')"
  7. :disabled="!edit"
  8. :range="dataSource.Purchase_Service.DepartmentId"
  9. title="申请部门"
  10. required
  11. disabled
  12. />
  13. <l-organize-picker
  14. @input="setValue('Purchase_Service.CreatorId', $event)"
  15. :value="getValue('Purchase_Service.CreatorId')"
  16. :readonly="!edit"
  17. type="user"
  18. title="申请人"
  19. required
  20. readonly
  21. />
  22. <!-- <l-datetime-picker
  23. @input="setValue('Purchase_Service.CreateTime', $event)"
  24. :value="getValue('Purchase_Service.CreateTime')"
  25. :disabled="!edit"
  26. title="申请时间"
  27. required
  28. /> -->
  29. <l-textarea
  30. @input="setValue('Purchase_Service.Remark', $event)"
  31. :value="getValue('Purchase_Service.Remark')"
  32. :readonly="!edit"
  33. title="备注"
  34. />
  35. <l-upload-file
  36. @input="setValue('Purchase_Service.FilePath', $event)"
  37. :value="getValue('Purchase_Service.FilePath')"
  38. tableName="Purchase_Service"
  39. fieldName="FilePath"
  40. title="附件"
  41. :number="9"
  42. :readonly="!edit"
  43. />
  44. <!-- <l-select
  45. @input="setValue('Purchase_Service.Status', $event)"
  46. :value="getValue('Purchase_Service.Status')"
  47. :disabled="!edit"
  48. :range="dataSource.Purchase_Service.Status"
  49. title="是否提交"
  50. />
  51. <l-datetime-picker
  52. @input="setValue('Purchase_Service.SubmitTime', $event)"
  53. :value="getValue('Purchase_Service.SubmitTime')"
  54. :disabled="!edit"
  55. title="提交时间"
  56. /> -->
  57. <!-- <l-select
  58. @input="setValue('Purchase_Service.CheckStatus', $event)"
  59. :value="getValue('Purchase_Service.CheckStatus')"
  60. :disabled="!edit"
  61. :range="dataSource.Purchase_Service.CheckStatus"
  62. title="审核状态"
  63. />
  64. <l-datetime-picker
  65. @input="setValue('Purchase_Service.CheckTime', $event)"
  66. :value="getValue('Purchase_Service.CheckTime')"
  67. :disabled="!edit"
  68. title="审核时间"
  69. />
  70. <l-organize-picker
  71. @input="setValue('Purchase_Service.CheckUserId', $event)"
  72. :value="getValue('Purchase_Service.CheckUserId')"
  73. :readonly="!edit"
  74. type="user"
  75. title="审核人"
  76. /> -->
  77. <l-input
  78. @input="setValue('Purchase_Service.TotalAmount', $event)"
  79. :value="getValue('Purchase_Service.TotalAmount')"
  80. disabled
  81. title="总价"
  82. disabled
  83. />
  84. <l-customform-table
  85. @input="DetailsEntityChange($event)"
  86. :value="getValue('Purchase_Service.Purchase_Service_Details')"
  87. :item="scheme.Purchase_Service.Purchase_Service_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_Service && current.Purchase_Service.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. mode: null,
  145. edit: null,
  146. ready: false,
  147. // 表单数据
  148. current: {},
  149. origin: {},
  150. // 表单项数据结构
  151. scheme: {
  152. Purchase_Service: {
  153. DepartmentId: { type:'select', title: '申请部门' },
  154. CreatorId: { type:'organize', title: '申请人' },
  155. // CreateTime: { type: 'datetime', title: '申请时间', dateformat: '1' },
  156. TotalAmount: { type:'text', title: '采购总价' },
  157. Remark: { type: 'textarea', title: '备注' },
  158. FilePath: { type: 'upload', title: '附件' },
  159. // Status: { type: 'select', title: '是否提交' },
  160. // SubmitTime:{ type: 'datetime', title: '提交时间', dateformat: '1' },
  161. // CheckTime:{ type: 'datetime', title: '审核时间', dateformat: '1' },
  162. // CheckUserId:{ type: 'organize', title: '审核人' },
  163. // CheckStatus:{ type: 'select', title: '审核状态', },
  164. Purchase_Service_Details:{ type: 'girdtable', title: '劳务维修详情', __defaultItem__:{}, fieldsData:[
  165. { field:'ServiceContent', type:'input', name:'维修内容' },
  166. { field:'Price', type:'input', name:'价格' },
  167. { field:'Peoplecount', type:'input', name:'人数' },
  168. { field:'Days', type:'input', name:'天数' },
  169. { field:'Standar', type:'input', name:'标准' },
  170. ]},
  171. },
  172. },
  173. // 数据源
  174. dataSource: {
  175. Purchase_Service: {
  176. DepartmentId:[],
  177. Status: [{text:'已提交',value:'1'},{text:'未提交',value:'2'}],
  178. CheckStatus:[{text:'审核中',value:'1'},{text:'审核通过',value:'2'},{text:'',value:'草稿'}]
  179. },
  180. },
  181. type:null,
  182. code:null,
  183. level: '1',
  184. processId:null,
  185. // 指派审核人数据
  186. modal: false,
  187. userAssignData:{},//收集数据用来判断是否需要审核人
  188. reviewerListId:'',
  189. reviewerList:[],
  190. submitPostData:{},
  191. reviewer: [],
  192. }
  193. },
  194. async onLoad({ type, id }) {
  195. await this.init(type, id)
  196. },
  197. methods: {
  198. // 页面初始化
  199. async init(type, id) {
  200. this.LOADING('加载数据中...')
  201. this.id = id
  202. this.mode = type
  203. this.edit = ['create', 'edit'].includes(this.mode)
  204. this.type = type
  205. this.code = '1-14'
  206. const currentTask = this.GET_PARAM()
  207. // 新建表单则生成
  208. this.processId = this.GUID('-')
  209. const processInfo = await this.fetchProcessInfo({ code:this.code })
  210. const currentNode = this.getCurrentNode(processInfo)
  211. this.userAssignData.currentTask = currentTask
  212. this.userAssignData.currentNode = currentNode
  213. // wfForms 的数组成员 t,表示表单数据项(TAB页),t.type 表示类别,注意它是字符串型,用 Number(t.type) 转换
  214. // 为 1 则使用工作流表单,依据它的 .formId
  215. // 不为 1 则使用系统表单,依据它的 .appurl
  216. const { wfForms } = currentNode
  217. // 处理没有有效表单的情况,停止加载
  218. if (!wfForms || wfForms.length <= 0) {
  219. this.HIDE_LOADING()
  220. this.TOAST('移动表单数据(wfForms)中无有效表单')
  221. return
  222. }
  223. // 拉取表单数据,同时拉取所有来自数据源的选单数据
  224. await Promise.all([
  225. this.FETCH_DATASOURCE('classdata').then(data => {
  226. this.dataSource.Purchase_Service.DepartmentId = data.data.map(t => ({
  227. text: t.name,
  228. value: t.id
  229. }));
  230. }),
  231. () => {}
  232. ])
  233. await this.fetchForm()
  234. this.ready = true
  235. this.HIDE_LOADING()
  236. },
  237. // 加载表单数据
  238. async fetchForm() {
  239. if (this.mode === 'create') {
  240. this.origin = await this.getDefaultForm()
  241. let userInfo = this.GET_GLOBAL('loginUser');
  242. this.origin.Purchase_Service.DepartmentId = userInfo.departmentId
  243. this.origin.Purchase_Service.CreatorId = userInfo.userId
  244. } else {
  245. const result = await this.HTTP_GET('learun/adms/purchaseservice/form', this.id)
  246. this.origin = await this.formatFormData({Purchase_Service:{...result.Purchase_Service,Purchase_Service_Details:result.Purchase_Service_Details||[]}})
  247. }
  248. this.current = this.COPY(this.origin)
  249. },
  250. // 计算采购总价
  251. DetailsEntityChange($event){
  252. this.setValue('Purchase_Service.Purchase_Service_Details', $event)
  253. let arr = this.current.Purchase_Service.Purchase_Service_Details
  254. let total = 0
  255. let isRight = true
  256. for (let s of arr) {
  257. let Price = Number(s.Price);
  258. if(/^(\-|\+)?\d+(\.\d+)?$/.test(Price)){
  259. total = this.accAdd(total,Price)
  260. }else{
  261. isRight = false
  262. }
  263. }
  264. this.setValue('Purchase_Service.TotalAmount', isRight?total:'')
  265. },
  266. // 乘法函数
  267. accMul(arg1, arg2){
  268. let m = 0,
  269. s1 = arg1.toString(),
  270. s2 = arg2.toString()
  271. try {
  272. m += s1.split('.')[1].length
  273. } catch (e) {}
  274. try {
  275. m += s2.split('.')[1].length
  276. } catch (e) {}
  277. return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
  278. },
  279. // 加法函数
  280. accAdd(arg1, arg2){
  281. let r1, r2, m
  282. try {
  283. r1 = arg1.toString().split('.')[1].length
  284. } catch (e) {
  285. r1 = 0
  286. }
  287. try {
  288. r2 = arg2.toString().split('.')[1].length
  289. } catch (e) {
  290. r2 = 0
  291. }
  292. m = Math.pow(10, Math.max(r1, r2))
  293. return (arg1 * m + arg2 * m) / m
  294. },
  295. // 指派审核人
  296. async userAssign() {
  297. this.modal = false
  298. if(!this.reviewer.length){
  299. this.TOAST('请选择审核人')
  300. return
  301. }
  302. this.LOADING('正在提交…')
  303. let postData = {
  304. auditors :JSON.stringify({[this.reviewerListId]:this.reviewer.toString()}),
  305. level : this.level,
  306. code: this.code,
  307. processId: this.processId,
  308. }
  309. const url = 'learun/adms/newwf/createnoform'
  310. const tips = `流程发起失败`
  311. this.HTTP_POST(url, postData, tips).then(success => {
  312. this.HIDE_LOADING()
  313. if (!success) {
  314. return
  315. }
  316. this.submit1()
  317. })
  318. },
  319. // 发起流程
  320. async submit() {
  321. // 判断是否指派审核人
  322. let isNext = this.userAssignData.currentNode.isNext
  323. Object.assign(this.userAssignData,{ code: 'agree' })
  324. if (this.userAssignData.next == '2') {
  325. isNext = '1';
  326. }
  327. if (isNext == '1') {
  328. let params = {
  329. code: this.code,
  330. processId: this.processId,
  331. taskId: '',
  332. nodeId: this.userAssignData.currentNode.id,
  333. operationCode: this.userAssignData.code,
  334. }
  335. this.LOADING('正在获取审核人…')
  336. const userList = await this.HTTP_GET('learun/adms/newwf/auditer', params, `获取审核人时发生错误`)
  337. this.HIDE_LOADING()
  338. if (!userList) {
  339. return
  340. }
  341. let arr = Object.entries(userList)
  342. this.reviewerListId = arr[0][0]
  343. this.reviewerList = arr[0][1].map(item => {
  344. return {
  345. text: item.Name,
  346. value: item.Id
  347. }
  348. })
  349. if(this.reviewerList.length>1){
  350. this.modal = true
  351. return
  352. }
  353. }
  354. this.LOADING('正在提交…')
  355. let postData = {
  356. auditors :JSON.stringify({}),
  357. level : this.level,
  358. code: this.code,
  359. processId: this.processId,
  360. }
  361. const url = 'learun/adms/newwf/createnoform'
  362. const tips = `流程发起失败`
  363. this.HTTP_POST(url, postData, tips).then(success => {
  364. this.HIDE_LOADING()
  365. if (!success) {
  366. return
  367. }
  368. this.submit1()
  369. })
  370. },
  371. // 提交
  372. async submit1(){
  373. // if (!(await this.CONFIRM('提交项目', '是否确认提交该项?', true))) {
  374. // return
  375. // }
  376. this.LOADING('正在提交...')
  377. this.HTTP_POST('learun/adms/purchaseservice/submit', {Id:this.id, ProcessId:this.processId} , '提交失败').then(
  378. success => {
  379. this.HIDE_LOADING()
  380. if (!success) {
  381. return
  382. }
  383. this.TOAST('提交成功', 'success')
  384. this.EMIT('LogisticsManagement-Purchase_Service-list-change')
  385. this.NAV_BACK()
  386. })
  387. return
  388. },
  389. // 点击 「编辑」、「重置」、「保存」、「删除」 按钮
  390. async action(type,isSubmit=false) {
  391. switch (type) {
  392. case 'edit':
  393. this.edit = true
  394. break
  395. case 'reset':
  396. this.current = this.COPY(this.origin)
  397. this.edit = false
  398. break
  399. case 'save':
  400. if(!this.current.Purchase_Service.TotalAmount){
  401. this.CONFIRM('表单验证失败', '[劳务维修详情]:价格为空或错误')
  402. return
  403. }
  404. const verifyResult = this.verifyForm()
  405. if (verifyResult.length > 0) {
  406. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  407. return
  408. }
  409. if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  410. return
  411. }
  412. this.LOADING('正在提交...')
  413. const postData = await this.getPostData(this.id)
  414. // 处理采购列表数据
  415. let strEntity = JSON.parse(postData.strEntity)
  416. for (let s of strEntity.Purchase_Service_Details) {
  417. s.Price = Number(s.Price);
  418. // s.Quantity = Number(s.Quantity)
  419. }
  420. postData.DetailList = JSON.stringify(strEntity.Purchase_Service_Details)
  421. delete strEntity.Purchase_Service_Details
  422. // 赋值部门和人员数据
  423. let userInfo = this.GET_GLOBAL('loginUser');
  424. let obj = this.dataSource.Purchase_Service.DepartmentId.find(e=>e.value == this.origin.Purchase_Service.DepartmentId)
  425. strEntity.DepartmentName = obj?obj.text:''
  426. strEntity.CreatorName = userInfo.realName
  427. postData.strEntity = JSON.stringify(strEntity)
  428. // console.log(postData,JSON.parse(postData.strEntity))
  429. this.HTTP_POST('learun/adms/purchaseservice/save', postData, '表单提交保存失败').then(success => {
  430. this.HIDE_LOADING()
  431. if (!success) {
  432. return
  433. }
  434. this.id = success.Id
  435. if(isSubmit){
  436. this.submit()
  437. return
  438. }
  439. this.EMIT('LogisticsManagement-Purchase_Service-list-change')
  440. setTimeout(()=>this.NAV_BACK(),500)
  441. this.TOAST('提交保存成功')
  442. })
  443. break
  444. case 'delete':
  445. if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?', true))) {
  446. return
  447. }
  448. this.LOADING('提交删除中...')
  449. this.HTTP_POST('learun/adms/purchaseservice/delete', this.id, '删除失败').then(success => {
  450. this.HIDE_LOADING()
  451. if (!success) {
  452. return
  453. }
  454. this.EMIT('LogisticsManagement-Purchase_Service-list-change')
  455. this.NAV_BACK()
  456. this.this.TOAST('删除成功', 'success')
  457. })
  458. break
  459. default: break
  460. }
  461. },
  462. // 获取表单值
  463. getValue(path) {
  464. return get(this.current, path)
  465. },
  466. // 设置表单值
  467. setValue(path, val) {
  468. set(this.current, path, val)
  469. },
  470. }
  471. }
  472. </script>