applyOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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('spare.applyDate')" borderBottom prop="setDate" @click="showSetDateCalendar = true">
  20. <u-input readonly v-model="form.setDate" border="none" :placeholder="$t('base.common.placeholderS')+$t('spare.applyDate')" />
  21. </u-form-item>
  22. <!-- 订单编号 -->
  23. <u-form-item :label="$t('spare.orderCode')" borderBottom prop="code">
  24. <u-input readonly v-model="form.code" border="none" :placeholder="$t('base.common.placeholderS')+$t('spare.orderCode')" />
  25. </u-form-item>
  26. <!-- 供应商 -->
  27. <u-form-item :label="$t('order.purveyId')" borderBottom prop="purveyId" @click="showPopup('purveyId')">
  28. <u-input readonly v-model="textForm.purveyId" border="none" :placeholder="$t('base.common.placeholderS')+$t('order.purveyId')" />
  29. </u-form-item>
  30. <!-- 申请人员 -->
  31. <u-form-item :label="$t('spare.buyer')" borderBottom prop="buyer" @click="showPopup('buyer')">
  32. <u-input readonly v-model="textForm.buyer" border="none" :placeholder="$t('base.common.placeholderS')+$t('spare.buyer')" />
  33. </u-form-item>
  34. <!-- 采购明细 -->
  35. <u-form-item :label="$t('spare.buyDetail')" borderBottom prop="dtoList" @click="toPage" v-if="!isCheckView">
  36. <u-input readonly border="none" :placeholder="$t('spare.buyDetail')" />
  37. <u-icon
  38. slot="right"
  39. name="arrow-right"
  40. ></u-icon>
  41. </u-form-item>
  42. <!-- 备注 -->
  43. <u-form-item label="备注" borderBottom prop="remark">
  44. <u-input :readonly="isCheckView" type="textarea" v-model="form.remark" border="none" placeholder="备注信息" />
  45. </u-form-item>
  46. </u-form>
  47. </view>
  48. <view class="title">{{$t('spare.buyDetail')}}</view>
  49. <template v-if="form.dtoList.length">
  50. <view class="order-card" v-for="(item, index) in form.dtoList" :key="index">
  51. <view class="order-info">
  52. <p class="info-line">
  53. <text class="label">{{$t('spare.spareName')}}:</text>
  54. <text class="info">
  55. <template >
  56. {{`${item.materialCode}_${item.materialName}_${item.materialSpec}`}}
  57. </template>
  58. </text>
  59. </p>
  60. <p class="info-line">
  61. <text class="label">{{$t('spare.orderNum')}}:</text>
  62. <text class="info">{{item.number}}</text>
  63. </p>
  64. </view>
  65. </view>
  66. </template>
  67. <template v-else>
  68. <u-empty mode="list" :text="$t('spare.setBuyDetail')" icon="https://cdn.uviewui.com/uview/empty/list.png">
  69. </u-empty>
  70. </template>
  71. <view class="title">{{$t('approval.approvalInfo')}}</view>
  72. <view class="flow-wrap">
  73. <u-steps direction="column" :current="currentIndex">
  74. <u-steps-item
  75. v-for="item,index in flowList"
  76. :key="index"
  77. :title="item.title"
  78. :desc="item.content+(item.handleOpinion?` (${item.handleOpinion})`:'')">
  79. <span slot="time" class="time">{{item.time}}</span>
  80. </u-steps-item>
  81. </u-steps>
  82. </view>
  83. <view class="btn-wrap" v-if="!isCheckView">
  84. <button type="primary" color='#4680F9' @click="submit('form1')">{{$t('base.common.submit')}}</button>
  85. </view>
  86. <!-- 紧急程度 -->
  87. <PopupSelect ref="flowUrgent" kind="flowUrgent" :option="flowUrgentOptions" @onConfirm="onConfirm"/>
  88. <!-- 供应商 -->
  89. <PopupSelect ref="purveyId" kind="purveyId" :option="purveyIdOptions" @onConfirm="onConfirm"/>
  90. <!-- 申请人员 -->
  91. <PopupSelect ref="buyer" kind="buyer" :option="buyerOptions" @onConfirm="onConfirm"/>
  92. <!-- 申请日期 -->
  93. <u-calendar
  94. color="#4680F9"
  95. round='25'
  96. :show="showSetDateCalendar"
  97. @confirm="onSetDateConfirm"
  98. @close="showSetDateCalendar=false">
  99. </u-calendar>
  100. <u-toast ref="loadingToast" />
  101. </view>
  102. </template>
  103. <script>
  104. import PopupSelect from '../../components/popup-select/index'
  105. import dayjs from 'dayjs'
  106. import { getLabel,getTreeList } from '../../utils/util'
  107. import {request} from '../../utils/request'
  108. import {
  109. getApprovalFlow,
  110. BillNumber,
  111. getApprovalInfo,
  112. createApproval,
  113. getApprovalFlowInfo
  114. } from "../../api/approval"
  115. import {
  116. getCode,
  117. getClientList,
  118. getUserListByType
  119. } from "../../api/receivable"
  120. export default {
  121. components:{
  122. PopupSelect
  123. },
  124. data(){
  125. return {
  126. id:'',
  127. getLabel,
  128. showSetDateCalendar:false,
  129. isCheckView:false,
  130. enCode:'applyOrder',
  131. currentIndex:0,
  132. flowList:[],
  133. flow:{},
  134. form:{
  135. flowId: '',
  136. id: '',
  137. wfCode: '',
  138. billNo: '',
  139. flowTitle: '',
  140. flowUrgent: 1,
  141. setDate:dayjs().format('YYYY-MM-DD'), //登记日期
  142. code:'',
  143. purveyId:'',
  144. buyer:'',
  145. remark:undefined, //备注
  146. dtoList:[],
  147. fileList:[],
  148. },
  149. textForm:{
  150. flowUrgent:this.$t('approval.ordinary'),//紧急程度
  151. purveyId: '',
  152. buyer:'',
  153. },
  154. rules: {
  155. setDate:[{ required: true, message: this.$t('base.common.placeholderS')+this.$t('spare.applyDate'), trigger: "change" }],
  156. purveyId:[{ required: true, message: this.$t('base.common.placeholderS')+this.$t('order.purveyId'), trigger: "change" }],
  157. code:[{ required: true, message:this.$t('base.common.placeholderS')+this.$t('spare.orderCode'), trigger: "change" }],
  158. dtoList:[{
  159. required: true,
  160. message: "采购明细不能为空",
  161. validator:(rule,value,callback)=>{
  162. if(this.form.detailList.length){
  163. callback()
  164. }else{
  165. callback(new Error("采购明细不能为空"))
  166. }
  167. }
  168. }],
  169. flowTitle: [
  170. { required: true, message: this.$t('base.common.placeholderI')+this.$t('approval.approvalTitle')},
  171. ],
  172. flowUrgent: [
  173. { required: true, message: this.$t('base.common.placeholderS')+this.$t('approval.urgency')},
  174. ],
  175. },
  176. formcondition:{
  177. flowUrgent: false, //紧急程度
  178. },
  179. flowUrgentOptions:[
  180. {text:this.$t('approval.ordinary'),value:1},
  181. {text:this.$t('approval.urgent'),value:2},
  182. {text:this.$t('approval.important'),value:3},
  183. ],
  184. purveyIdOptions:[
  185. {text:this.$t('order.noData'),value:null}
  186. ],
  187. buyerOptions:[
  188. {text:this.$t('order.noData'),value:null}
  189. ],
  190. unitList:[],
  191. }
  192. },
  193. onLoad(options) {
  194. this.form.flowId = options.flowId
  195. if(options.id){
  196. this.isCheckView = true
  197. this.id = options.id
  198. this.getOptions()
  199. this.getApprovalFlowInfo()
  200. }else{
  201. this.userInfo = uni.getStorageSync("userInfo");
  202. this.getOptions()
  203. this.getApprovalFlow()
  204. }
  205. },
  206. methods:{
  207. //提交审批
  208. submit(ref){
  209. let _this=this
  210. this.$refs[ref].validate().then(() => {
  211. let key = this.enCode[0].toUpperCase()+this.enCode.slice(1)
  212. this.$refs.loadingToast.show({
  213. type:"loading",
  214. message: _this.$t('base.common.loading'),
  215. duration:'100000',
  216. })
  217. createApproval(key,this.form).then(res=>{
  218. if(res.data.code == 0){
  219. this.$refs.loadingToast.hide()
  220. uni.showModal({
  221. title: _this.$t('settings.tips'),
  222. content: _this.$t('approval.creditApprovalSuccess'),
  223. showCancel: false,
  224. success: ({ confirm, cancel }) => {
  225. if(confirm){
  226. uni.navigateBack({ delta: 1 })
  227. }
  228. }
  229. })
  230. }else{
  231. this.$refs.loadingToast.hide()
  232. uni.showModal({
  233. title: _this.$t('settings.tips'),
  234. content: res.data.msg || _this.$t('approval.creditApprovalFail'),
  235. showCancel: false,
  236. })
  237. }
  238. })
  239. })
  240. },
  241. toPage(){
  242. uni.navigateTo({ url: `/subpages/approval/summary?encode=applyOrder` })
  243. },
  244. //获取详情
  245. async getApprovalFlowInfo(){
  246. let encode = this.enCode[0].toUpperCase()+this.enCode.slice(1)
  247. getApprovalInfo(encode,this.id).then(res=>{
  248. if(res.data.code == 200){
  249. this.form = res.data.data
  250. let data = res.data.data
  251. this.textForm.flowUrgent=data.flowUrgent==1?this.$t('approval.ordinary'):(data.flowUrgent == 2?this.$t('approval.urgent'):this.$t('approval.important')) //紧急程度
  252. this.purveyIdOptions.forEach(item=>{
  253. if(item.value == data.purveyId){
  254. this.textForm.purveyId = item.text
  255. }
  256. })
  257. this.buyerOptions.forEach(item=>{
  258. if(item.value == data.buyer){
  259. this.textForm.buyer = item.text
  260. }
  261. })
  262. }
  263. })
  264. getApprovalFlowInfo(this.id).then(res=>{
  265. if(res.data.code == 200){
  266. let flow = JSON.parse(res.data.data.flowTaskInfo.flowTemplateJson)
  267. this.flow = flow
  268. this.forFlowObj(flow)
  269. this.flowList.forEach((item,index)=>{
  270. res.data.data.flowTaskOperatorRecordList.forEach(i=>{
  271. if(i.nodeCode == item.nodeId){
  272. item.time = i.handleTime || ''
  273. item.handleOpinion = i.handleOpinion || ''
  274. this.currentIndex = index
  275. }
  276. })
  277. res.data.data.flowTaskNodeList.forEach(i=>{
  278. if(i.nodeCode == item.nodeId){
  279. item.content = i.userName || item.content
  280. }
  281. })
  282. })
  283. }
  284. })
  285. },
  286. //显示选择
  287. showPopup(refs){
  288. if(this.isCheckView){
  289. return
  290. }
  291. this.$refs[refs].showPicker=true
  292. },
  293. //获取选项
  294. getOptions(){
  295. //流程编码
  296. if(this.id){
  297. }else{
  298. BillNumber(this.enCode,dayjs().format('YYYY-MM-DD')).then(res => {
  299. if(res.data.code==0){
  300. this.form.wfCode = res.data.msg
  301. }
  302. })
  303. //订单编码
  304. getCode(dayjs().format('YYYY-MM-DD')).then(res=>{
  305. if(res.data.code == 0){
  306. this.form.code = res.data.data
  307. }
  308. })
  309. }
  310. //获取单位
  311. request({
  312. url:'/admin/dict/type/spare_unit',
  313. method:'get',
  314. })
  315. .then(res=>{
  316. if(res.data.code == 0){
  317. this.unitList = res.data.data
  318. }
  319. })
  320. //获取供应商
  321. getClientList( {type:'103'}).then(res=>{
  322. let arr=[]
  323. res.data.data.forEach(item=>{
  324. arr.push({
  325. text:item.name,
  326. value:item.id
  327. })
  328. })
  329. if(arr.length){
  330. arr.unshift({text:this.$t('order.notSelected'),value:null})
  331. }else{
  332. arr.unshift({text:this.$t('order.noData'),value:null})
  333. }
  334. this.purveyIdOptions = arr
  335. })
  336. //获取采购员
  337. getUserListByType('101').then(res=>{
  338. let arr=[]
  339. res.data.data.forEach(item=>{
  340. arr.push({
  341. text:item.name,
  342. value:item.userId
  343. })
  344. })
  345. if(arr.length){
  346. arr.unshift({text:this.$t('order.notSelected'),value:null})
  347. }else{
  348. arr.unshift({text:this.$t('order.noData'),value:null})
  349. }
  350. this.buyerOptions = arr
  351. })
  352. },
  353. //确定选择
  354. onConfirm(value,kind){
  355. if(value.value){
  356. this.form[kind]=value.value
  357. this.textForm[kind]=value.text
  358. }else{
  359. this.form[kind]=''
  360. this.textForm[kind]=''
  361. }
  362. },
  363. //根据条件重新设置流程
  364. resetFlow(value){
  365. if(this.isCheckView){
  366. return
  367. }
  368. if(this.formcondition[value]){
  369. this.flowList=[]
  370. if(this.form[value]){
  371. this.forFlowObj(this.flow)
  372. }
  373. }
  374. },
  375. //获取审批流程
  376. getApprovalFlow(){
  377. getApprovalFlow(this.form.flowId).then(res=>{
  378. if(res.data.code == 200){
  379. this.form.flowTitle=this.userInfo.username+'的'+res.data.data.fullName
  380. let flow = JSON.parse(res.data.data.flowTemplateJson)
  381. this.flow = flow
  382. console.log(this.flow);
  383. this.forFlowObj(flow)
  384. }
  385. })
  386. },
  387. //选择申请日期
  388. onSetDateConfirm(date){
  389. this.form.setDate = dayjs(date).format('YYYY-MM-DD');
  390. this.showSetDateCalendar = false;
  391. },
  392. //循环对象
  393. forFlowObj(flow){
  394. this.flowList.push(
  395. {
  396. title:flow.properties.title,
  397. content:flow.content,
  398. nodeId:flow.nodeId,
  399. time:'',
  400. handleOpinion:"",
  401. }
  402. )
  403. if(flow.conditionNodes && flow.conditionNodes.length){
  404. flow.conditionNodes.forEach(item=>{
  405. let math = item.properties.conditions
  406. if(this.eval(math)){
  407. this.flowList.push(
  408. {
  409. title:item.properties.title,
  410. content:item.content,
  411. nodeId:item.nodeId,
  412. time:'',
  413. handleOpinion:"",
  414. }
  415. )
  416. this.forFlowObj(item.childNode)
  417. }
  418. })
  419. }
  420. if(flow.childNode){
  421. this.forFlowObj(flow.childNode)
  422. }
  423. },
  424. //计算方法
  425. eval(conditions){
  426. let boo=false
  427. let booList = []
  428. conditions.forEach((item,index)=>{
  429. switch (item.symbol) {
  430. case '>=':
  431. booList.push( this.form[item.field] >= Number(item.filedValue))
  432. if(index != conditions.length-1){
  433. booList.push(item.logic)
  434. }
  435. break;
  436. case '>':
  437. booList.push(this.form[item.field] > Number(item.filedValue))
  438. if(index != conditions.length-1){
  439. booList.push(item.logic)
  440. }
  441. break;
  442. case '==':
  443. booList.push(this.form[item.field] == Number(item.filedValue))
  444. if(index != conditions.length-1){
  445. booList.push(item.logic)
  446. }
  447. break;
  448. case '<=':
  449. booList.push(this.form[item.field] <= Number(item.filedValue))
  450. if(index != conditions.length-1){
  451. booList.push(item.logic)
  452. }
  453. break;
  454. case '<':
  455. booList.push(this.form[item.field] < Number(item.filedValue))
  456. if(index != conditions.length-1){
  457. booList.push(item.logic)
  458. }
  459. break;
  460. case '<>':
  461. booList.push(this.form[item.field] != Number(item.filedValue))
  462. if(index != conditions.length-1){
  463. booList.push(item.logic)
  464. }
  465. break;
  466. }
  467. this.formcondition[item.field] = true
  468. })
  469. let booList2=[]
  470. if(booList.length>1){
  471. booList.forEach((item,index)=>{
  472. if(index%2 != 0){
  473. switch (item) {
  474. case "&&":
  475. booList2.push(booList[index-1] && booList[index+1])
  476. break;
  477. }
  478. }else{
  479. if(booList[index+1] !="&&" && booList[index-1] !="&&"){
  480. booList2.push(item)
  481. }
  482. }
  483. })
  484. }else{
  485. boo=booList[0]
  486. }
  487. if(booList2.length>1){
  488. booList2.forEach(item=>{
  489. if(item){
  490. boo = true
  491. }
  492. })
  493. }else if(booList2.length==1){
  494. boo = booList2[0]
  495. }
  496. return boo
  497. },
  498. }
  499. }
  500. </script>
  501. <style lang="scss" scoped>
  502. @import '../../common/css/apply.scss';
  503. @import '../../common/css/approval.scss';
  504. /deep/ .u-form-item__body__right__content__slot{
  505. display: block !important;
  506. // flex-direction: column !important;
  507. // align-items: baseline;
  508. }
  509. /deep/ .input-value-border{
  510. border: none !important;
  511. }
  512. /deep/ .input-arrow{
  513. border:none !important;
  514. }
  515. /deep/ .input-value{
  516. line-height: 24px !important;
  517. }
  518. </style>