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.
 
 
 
 
 
 

514 line
16 KiB

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