applyPurchase.vue 17 KB

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