applyCredit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <view class="apply-credit">
  3. <view class="title">{{$t('approval.formInfo')}}</view>
  4. <view class="form-wrap">
  5. <u-form labelPosition="left" :model="form" :rules="rules" ref="form1" labelWidth='90'>
  6. <!-- 流程编码 -->
  7. <u-form-item :label="$t('approval.approvalCode')" borderBottom prop="wfCode">
  8. <u-input readonly v-model="form.wfCode" border="none" />
  9. </u-form-item>
  10. <!-- 流程标题 -->
  11. <u-form-item :label="$t('approval.approvalTitle')" borderBottom prop="flowTitle">
  12. <u-input :readonly="isCheckView" v-model="form.flowTitle" border="none" :placeholder="$t('base.common.placeholderI')+$t('approval.approvalTitle')" />
  13. </u-form-item>
  14. <!-- 紧急程度 -->
  15. <u-form-item :label="$t('approval.urgency')" borderBottom prop="flowUrgent" @click="showPopup('flowUrgent')">
  16. <u-input readonly @change="resetFlow('flowUrgent')" v-model="textForm.flowUrgent" border="none" :placeholder="$t('base.common.placeholderS')+$t('approval.urgency')" />
  17. </u-form-item>
  18. <!-- 申请人员 -->
  19. <u-form-item :label="$t('approval.applicant')" borderBottom prop="applicant" @click="showPopup('applicant')">
  20. <u-input readonly @change="resetFlow('applicant')" v-model="textForm.applicant" border="none" :placeholder="$t('base.common.placeholderS')+$t('approval.applicant')" />
  21. </u-form-item>
  22. <!-- 授信客户 -->
  23. <u-form-item :label="$t('approval.creditCustom')" borderBottom prop="companyId" @click="showPopup('companyId')">
  24. <u-input readonly @change="resetFlow('companyId')" v-model="textForm.companyId" border="none" :placeholder="$t('base.common.placeholderS')+$t('approval.creditCustom')" />
  25. </u-form-item>
  26. <!-- 授信金额 -->
  27. <u-form-item :label="$t('approval.creditMoney')" borderBottom prop="amount">
  28. <u-input :readonly="isCheckView" type="number" @change="resetFlow('amount')" v-model="form.amount" border="none" :placeholder="$t('base.common.placeholderI')+$t('approval.creditMoney')" />
  29. </u-form-item>
  30. <!-- 授信类型 -->
  31. <u-form-item :label="$t('approval.creditType')" borderBottom prop="type" @click="showPopup('type')">
  32. <u-input readonly @change="resetFlow('type')" v-model="textForm.type" border="none" :placeholder="$t('base.common.placeholderS')+$t('approval.creditType')" />
  33. </u-form-item>
  34. <!-- 授信日期 -->
  35. <u-form-item :label="$t('approval.creditDate')" borderBottom prop="setDate" @click="isCheckView?'':showSetDateCalendar = true">
  36. <u-input readonly @change="resetFlow('setDate')" v-model="form.setDate" border="none" :placeholder="$t('base.common.placeholderS')+$t('approval.creditDate')" />
  37. </u-form-item>
  38. <!-- 授信天数 -->
  39. <u-form-item :label="$t('approval.creditDays')" borderBottom prop="amountDay">
  40. <u-input type="number" @change="resetFlow('amountDay')" @blur="changeCancelDate" v-model="form.amountDay" border="none" :placeholder="$t('base.common.placeholderI')+$t('approval.creditDays')" />
  41. </u-form-item>
  42. <!-- 到期日期 -->
  43. <u-form-item :label="$t('approval.finishDate')" borderBottom prop="cancelDate" @click="isCheckView?'':showCancelDateCalendar = true">
  44. <u-input readonly @change="resetFlow('cancelDate')" v-model="form.cancelDate" border="none" :placeholder="$t('base.common.placeholderS')+$t('approval.finishDate')" />
  45. </u-form-item>
  46. <!-- 备注 -->
  47. <u-form-item :label="$t('approval.remark')" borderBottom prop="remark">
  48. <u-input :readonly="isCheckView" type="textarea" v-model="form.remark" border="none" :placeholder="$t('approval.remark')" />
  49. </u-form-item>
  50. </u-form>
  51. </view>
  52. <view class="title">{{$t('approval.approvalInfo')}}</view>
  53. <view class="flow-wrap">
  54. <u-steps direction="column" :current="currentIndex">
  55. <u-steps-item
  56. v-for="item,index in flowList"
  57. :key="index"
  58. :title="item.title"
  59. :desc="item.content+(item.handleOpinion?` (${item.handleOpinion})`:'')">
  60. <span slot="time" class="time">{{item.time}}</span>
  61. </u-steps-item>
  62. </u-steps>
  63. </view>
  64. <view class="btn-wrap" v-if="!isCheckView">
  65. <button type="primary" color='#4680F9' @click="submit('form1')">{{$t('base.common.submit')}}</button>
  66. </view>
  67. <!-- 紧急程度 -->
  68. <PopupSelect ref="flowUrgent" kind="flowUrgent" :option="flowUrgentOptions" @onConfirm="onConfirm"/>
  69. <!-- 申请人员 -->
  70. <PopupSelect ref="applicant" kind="applicant" :option="applicantOptions" @onConfirm="onConfirm"/>
  71. <!-- 授信客户 -->
  72. <PopupSelect ref="companyId" kind="companyId" :option="clientOptions" @onConfirm="onConfirm"/>
  73. <!-- 授信类型 -->
  74. <PopupSelect ref="type" kind="client" :option="typeOptions" @onConfirm="onConfirm"/>
  75. <!-- 授信日期 -->
  76. <u-calendar
  77. color="#4680F9"
  78. round='25'
  79. :show="showSetDateCalendar"
  80. @confirm="onSetDateConfirm"
  81. @close="showSetDateCalendar=false">
  82. </u-calendar>
  83. <!-- 到期日期 -->
  84. <u-calendar
  85. color="#4680F9"
  86. round='25'
  87. :show="showCancelDateCalendar"
  88. @confirm="onCancelDateConfirm"
  89. @close="showCancelDateCalendar=false">
  90. </u-calendar>
  91. <u-toast ref="loadingToast" />
  92. </view>
  93. </template>
  94. <script>
  95. import PopupSelect from '../../components/popup-select/index'
  96. import {
  97. getUserList,
  98. getApprovalFlow,
  99. BillNumber,
  100. createApproval,
  101. getApprovalInfo,
  102. getApprovalFlowInfo
  103. } from "../../api/approval"
  104. import {
  105. getClientList
  106. } from "../../api/receivable"
  107. import dayjs from 'dayjs'
  108. export default {
  109. components:{
  110. PopupSelect,
  111. },
  112. data() {
  113. return {
  114. id:'',
  115. isCheckView:false,
  116. enCode:'applyCredit',
  117. userInfo: {},
  118. showSetDateCalendar:false,
  119. showCancelDateCalendar:false,
  120. flow:{},
  121. flowList:[],
  122. currentIndex:0,
  123. form:{
  124. flowId: '',
  125. // id: '',
  126. wfCode: '',
  127. flowTitle: '',
  128. flowUrgent: 1, //紧急程度
  129. applicant:'', //申请人
  130. remark: '',
  131. amount:undefined, //授信金额
  132. amountDay:1, //授信天数
  133. companyId:undefined, //授信单位
  134. cancelDate:dayjs().add(1,'day').format('YYYY-MM-DD'), //结束日期
  135. setDate:dayjs().format('YYYY-MM-DD'), //登记日期
  136. type:'101',
  137. },
  138. formcondition:{
  139. flowTitle: false,
  140. flowUrgent: false, //紧急程度
  141. applicant:false, //申请人
  142. amount:false, //授信金额
  143. amountDay:false, //授信天数
  144. companyId:false, //授信单位
  145. cancelDate:false, //结束日期
  146. setDate:false, //登记日期
  147. type:false,
  148. },
  149. textForm:{
  150. flowUrgent: this.$t('approval.ordinary'), //紧急程度
  151. applicant:'', //申请人
  152. companyId:'', //授信单位
  153. type:this.$t('approval.temporaryCredit'),
  154. },
  155. rules:{
  156. flowTitle: [
  157. { required: true, message:this.$t('base.common.placeholderI')+this.$t('approval.approvalTitle') },
  158. ],
  159. flowUrgent: [
  160. { required: true, message: this.$t('base.common.placeholderS')+this.$t('approval.urgency') },
  161. ],
  162. companyId:[{ required: true, message: this.$t('base.common.placeholderS')+this.$t('approval.creditCustom') }],
  163. setDate:[{ required: true, message: this.$t('base.common.placeholderS')+this.$t('approval.creditDate') }],
  164. amount:[{ required: true, message: this.$t('base.common.placeholderI')+this.$t('approval.creditMoney') }],
  165. type:[{ required: true, message: this.$t('base.common.placeholderS')+this.$t('approval.creditType') }],
  166. applicant:[{ required: true, message: this.$t('base.common.placeholderS')+this.$t('approval.applicant') }]
  167. },
  168. flowUrgentOptions:[
  169. {text:this.$t('approval.ordinary'),value:1},
  170. {text:this.$t('approval.urgent'),value:2},
  171. {text:this.$t('approval.important'),value:3},
  172. ],
  173. typeOptions:[
  174. {text:this.$t('approval.temporaryCredit'),value:'1'},
  175. {text:this.$t('approval.fixedCredit'),value:'2'},
  176. ],
  177. applicantOptions:[{text:this.$t('order.noData'),value:null}], //申请人员选项
  178. clientOptions:[{text:this.$t('order.noData'),value:null}], //授信客户选项
  179. };
  180. },
  181. onLoad(options) {
  182. this.form.flowId = options.flowId
  183. if(options.id){
  184. this.id = options.id
  185. this.isCheckView = true
  186. this.getOptions()
  187. }else{
  188. this.getOptions()
  189. this.getApprovalFlow()
  190. this.userInfo = uni.getStorageSync("userInfo");
  191. this.form.applicant = this.userInfo.userId
  192. this.textForm.applicant = this.userInfo.userName
  193. this.textForm.applicant = this.userInfo.name
  194. }
  195. },
  196. methods:{
  197. //获取详情
  198. async getApprovalFlowInfo(){
  199. let encode = this.enCode[0].toUpperCase()+this.enCode.slice(1)
  200. getApprovalInfo(encode,this.id).then(res=>{
  201. if(res.data.code == 200){
  202. this.form = res.data.data
  203. let data = res.data.data
  204. this.textForm.flowUrgent=data.flowUrgent==1?'普通':(data.flowUrgent == 2?'紧急':'重要') //紧急程度
  205. this.applicantOptions.forEach(item=>{
  206. if(item.value == data.applicant){
  207. this.textForm.applicant = item.text
  208. }
  209. })
  210. this.clientOptions.forEach(item=>{
  211. if(item.value == data.companyId){
  212. this.textForm.companyId = item.text
  213. }
  214. })
  215. this.textForm.type=data.type=="101"?this.$t('approval.temporaryCredit'):this.$t('approval.fixedCredit')
  216. }
  217. })
  218. getApprovalFlowInfo(this.id).then(res=>{
  219. if(res.data.code == 200){
  220. let flow = JSON.parse(res.data.data.flowTaskInfo.flowTemplateJson)
  221. this.flow = flow
  222. this.forFlowObj(flow)
  223. this.flowList.forEach((item,index)=>{
  224. res.data.data.flowTaskOperatorRecordList.forEach(i=>{
  225. if(i.nodeCode == item.nodeId){
  226. item.time = i.handleTime || ''
  227. item.handleOpinion = i.handleOpinion || ''
  228. this.currentIndex = index
  229. }
  230. })
  231. res.data.data.flowTaskNodeList.forEach(i=>{
  232. if(i.nodeCode == item.nodeId){
  233. item.content = i.userName || item.content
  234. }
  235. })
  236. })
  237. }
  238. })
  239. },
  240. //提交审批
  241. submit(ref){
  242. let _this = this
  243. this.$refs[ref].validate().then(() => {
  244. let key = this.enCode[0].toUpperCase()+this.enCode.slice(1)
  245. this.$refs.loadingToast.show({
  246. type:"loading",
  247. message: "正在加载",
  248. duration:'100000',
  249. })
  250. createApproval(key,this.form).then(res=>{
  251. if(res.data.code == 200){
  252. this.$refs.loadingToast.hide()
  253. uni.showModal({
  254. title: _this.$t('settings.tips'),
  255. content: _this.$t('approval.creditApprovalSuccess'),
  256. showCancel: false,
  257. success: ({ confirm, cancel }) => {
  258. if(confirm){
  259. uni.navigateBack({ delta: 1 })
  260. }
  261. }
  262. })
  263. }else{
  264. this.$refs.loadingToast.hide()
  265. uni.showModal({
  266. title: _this.$t('settings.tips'),
  267. content: res.data.msg || _this.$t('approval.creditApprovalFail'),
  268. showCancel: false,
  269. })
  270. }
  271. })
  272. })
  273. },
  274. //获取审批流程
  275. getApprovalFlow(){
  276. getApprovalFlow(this.form.flowId).then(res=>{
  277. if(res.data.code == 200){
  278. this.form.flowTitle=this.userInfo.username+'的'+res.data.data.fullName
  279. let flow = JSON.parse(res.data.data.flowTemplateJson)
  280. this.flow = flow
  281. console.log(this.flow);
  282. this.forFlowObj(flow)
  283. }
  284. })
  285. },
  286. //获取选项
  287. async getOptions(){
  288. //获取用户
  289. await getUserList().then(res=>{
  290. if(res.data.code == 0){
  291. this.applicantOptions = this.formatOption(res.data.data)
  292. }
  293. })
  294. //获取授信客户
  295. await getClientList({type:'102'}).then(res=>{
  296. if(res.data.code == 0){
  297. this.clientOptions = this.formatOption(res.data.data)
  298. }
  299. console.log(this.clientOptions,'------------');
  300. })
  301. if(this.isCheckView){
  302. this.getApprovalFlowInfo()
  303. }else{
  304. //流程编码
  305. BillNumber(this.enCode,dayjs().format('YYYY-MM-DD')).then(res => {
  306. if(res.data.code==0){
  307. this.form.wfCode = res.data.msg
  308. }
  309. })
  310. }
  311. },
  312. //确定选择
  313. onConfirm(value,kind){
  314. if(value.value){
  315. this.form[kind]=value.value
  316. this.textForm[kind]=value.text
  317. }else{
  318. this.form[kind]=''
  319. this.textForm[kind]=''
  320. }
  321. },
  322. //根据条件重新设置流程
  323. resetFlow(value){
  324. if(this.isCheckView){
  325. return
  326. }
  327. if(this.formcondition[value]){
  328. this.flowList=[]
  329. if(this.form[value] !=undefined){
  330. this.forFlowObj(this.flow)
  331. }
  332. }
  333. },
  334. //选择授信日期
  335. onSetDateConfirm(date){
  336. this.form.setDate = dayjs(date).format('YYYY-MM-DD');
  337. this.showSetDateCalendar = false;
  338. },
  339. //选择到期日期
  340. onCancelDateConfirm(date){
  341. this.form.cancelDate = dayjs(date).format('YYYY-MM-DD');
  342. this.showCancelDateCalendar = false;
  343. },
  344. //选项格式
  345. formatOption(data){
  346. let arr=[]
  347. data.forEach(item=>{
  348. arr.push(
  349. {
  350. text:item.name || item.label,
  351. value:item.value || item.id || item.userId
  352. }
  353. )
  354. })
  355. if(arr.length){
  356. arr.unshift({text:this.$t('order.notSelected'),value:null})
  357. }else{
  358. arr.unshift({text:this.$t('order.noData'),value:null})
  359. }
  360. return arr
  361. },
  362. changeCancelDate(){
  363. this.form.cancelDate = dayjs(this.form.setDate).add(this.form.amountDay,'day').format('YYYY-MM-DD')
  364. },
  365. //循环对象
  366. forFlowObj(flow){
  367. this.flowList.push(
  368. {
  369. title:flow.properties.title,
  370. content:flow.content,
  371. nodeId:flow.nodeId,
  372. time:'',
  373. handleOpinion:"",
  374. }
  375. )
  376. if(flow.conditionNodes && flow.conditionNodes.length){
  377. flow.conditionNodes.forEach(item=>{
  378. let math = item.properties.conditions
  379. if(this.eval(math)){
  380. this.flowList.push(
  381. {
  382. title:item.properties.title,
  383. content:item.content,
  384. nodeId:item.nodeId,
  385. time:'',
  386. handleOpinion:"",
  387. }
  388. )
  389. this.forFlowObj(item.childNode)
  390. }
  391. })
  392. }
  393. if(flow.childNode){
  394. this.forFlowObj(flow.childNode)
  395. }
  396. },
  397. //显示选择
  398. showPopup(refs){
  399. if(this.isCheckView){
  400. return
  401. }
  402. this.$refs[refs].showPicker=true
  403. },
  404. //计算方法
  405. eval(conditions){
  406. let boo=false
  407. let booList = []
  408. console.log(conditions);
  409. conditions.forEach((item,index)=>{
  410. switch (item.symbol) {
  411. case '>=':
  412. booList.push( this.form[item.field] >= Number(item.filedValue))
  413. if(index != conditions.length-1){
  414. booList.push(item.logic)
  415. }
  416. break;
  417. case '>':
  418. booList.push(this.form[item.field] > Number(item.filedValue))
  419. if(index != conditions.length-1){
  420. booList.push(item.logic)
  421. }
  422. break;
  423. case '==':
  424. booList.push(this.form[item.field] == Number(item.filedValue))
  425. if(index != conditions.length-1){
  426. booList.push(item.logic)
  427. }
  428. break;
  429. case '<=':
  430. booList.push(this.form[item.field] <= Number(item.filedValue))
  431. if(index != conditions.length-1){
  432. booList.push(item.logic)
  433. }
  434. break;
  435. case '<':
  436. booList.push(this.form[item.field] < Number(item.filedValue))
  437. if(index != conditions.length-1){
  438. booList.push(item.logic)
  439. }
  440. break;
  441. case '<>':
  442. booList.push(this.form[item.field] != Number(item.filedValue))
  443. if(index != conditions.length-1){
  444. booList.push(item.logic)
  445. }
  446. break;
  447. }
  448. this.formcondition[item.field] = true
  449. })
  450. let booList2=[]
  451. if(booList.length>1){
  452. booList.forEach((item,index)=>{
  453. if(index%2 != 0){
  454. switch (item) {
  455. case "&&":
  456. booList2.push(booList[index-1] && booList[index+1])
  457. break;
  458. }
  459. }else{
  460. if(booList[index+1] !="&&" && booList[index-1] !="&&"){
  461. booList2.push(item)
  462. }
  463. }
  464. })
  465. }else{
  466. boo=booList[0]
  467. }
  468. if(booList2.length>1){
  469. booList2.forEach(item=>{
  470. if(item){
  471. boo = true
  472. }
  473. })
  474. }else if(booList2.length==1){
  475. boo = booList2[0]
  476. }
  477. return boo
  478. },
  479. }
  480. };
  481. </script>
  482. <style lang="scss" scoped>
  483. @import '../../common/css/apply.scss';
  484. </style>