index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. <!-- 采购订单修订—— 列表 -->
  2. <script>
  3. import { TableColumns, SearchColumns, TabColumns, SelectColumns } from "./column";
  4. import orderApi from "@/api/business/purchase/purchase-order";
  5. import {saveAs} from "file-saver";
  6. import { blobValidate } from "@/utils/ruoyi";
  7. import {
  8. initPage,
  9. initParams,
  10. // initDicts,
  11. } from "@/utils/init/index.js";
  12. import { initDicts } from "@/utils/init.js";
  13. const allColumns = [...TableColumns, ...SearchColumns];
  14. TabColumns.forEach(column =>{
  15. allColumns.push(...column.tableColumns)
  16. })
  17. export default {
  18. name: "PuchaseOrder",
  19. // dicts: initDicts(SelectColumns),
  20. dicts: [...initDicts(allColumns)],
  21. components: {
  22. AddDrawer: () => import('./add/index.vue'),
  23. SeeDrawer: () => import('./see/index.vue'),
  24. EditDrawer: () => import('./edit/index.vue'),
  25. PurchaseReturnDrawer: () => import('./purchaseReturn/index.vue'),
  26. ElSuperTable: () => import("@/components/super-table/index.vue"),
  27. ElSuperSearch: () => import("@/components/super-search/index.vue"),
  28. },
  29. data() {
  30. const initTabColumns = () => TabColumns;
  31. return {
  32. loading: false,
  33. tabLoading:false,
  34. page: { pageNum: 1, pageSize: 10, total: 0 },
  35. searchColumns: SearchColumns,
  36. params: initParams(SearchColumns),
  37. tableColumns: TableColumns,
  38. tableData: [],
  39. tabColumns: initTabColumns(),
  40. tabName: "puOrderItemList",
  41. tabTableDatas: {
  42. puOrderItemList: [],
  43. puOrderExecuteList: [],
  44. },
  45. checkedList: [],
  46. // 子表Select
  47. checkedTabList: [],
  48. // 主表点击信息
  49. primaryResource:{},
  50. timer:300,
  51. timeOut:null,
  52. };
  53. },
  54. computed: {
  55. $dicts: {
  56. get: function () {
  57. return this.dict.type;
  58. },
  59. },
  60. },
  61. created() {
  62. if(this.$route.query.billCode) this.params.orderCode = this.$route.query.billCode
  63. this.fetchList(this.params, this.page);
  64. // this.handleRefreshList();
  65. },
  66. methods: {
  67. async fetchList(data, params) {
  68. try {
  69. this.loading = true;
  70. params['isAsc'] = 'desc';
  71. params['orderByColumn'] = 'updateTime';
  72. const { code, msg, rows, total } = await orderApi.list(data, params);
  73. if (code === 200) {
  74. this.page.total = total;
  75. this.tableData = rows;
  76. }
  77. } catch (err) {
  78. //
  79. } finally {
  80. this.loading = false;
  81. for (const key in this.tabTableDatas) {
  82. this.tabTableDatas[key] = [];
  83. }
  84. }
  85. },
  86. async handleDownload(){
  87. console.log(this.params,'条件');
  88. this.download('/pu/order/export', {...this.params}, `采购订单维护${new Date().getTime()}.xlsx`);
  89. // try {
  90. // this.loading = true;
  91. // orderApi.orderExport({...this.params}).then(res=>{
  92. // const isBlob = blobValidate(res);
  93. // if (isBlob) {
  94. // const blob = new Blob([res]);
  95. // saveAs(blob, `采购订单维护${new Date().getTime()}.xlsx`);
  96. // }
  97. // })
  98. // } catch (error) {
  99. // }finally{
  100. // this.loading = false;
  101. // }
  102. },
  103. async jumpFlow(row){
  104. const {name} = this.$store.state.user;
  105. try {
  106. let {code,msg,oaUrl} = await orderApi.toOA(name,row.flowId);
  107. if(code == 200){
  108. window.open(oaUrl)
  109. }
  110. } catch (error) {
  111. }finally{
  112. }
  113. },
  114. setSelectable(){
  115. return true
  116. },
  117. setTabSelectable(){
  118. if(this.tabName === 'puOrderItemList'){
  119. return true
  120. }
  121. return false
  122. },
  123. // 刷新操作
  124. handleRefreshList() {
  125. this.page.pageNum = 1;
  126. this.page.pageSize = 10;
  127. this.$refs.purchaseTable.$refs.superTable.clearSelection();
  128. for (const key in this.tabTableDatas) {
  129. this.tabTableDatas[key] = []
  130. }
  131. this.$refs.puOrderItemList[0].$refs.superTable.clearSelection();
  132. // this.checkedList = [];
  133. // this.checkedTabList = [];
  134. this.primaryResource = {};
  135. this.fetchList(this.params, this.page);
  136. },
  137. // 查询操作
  138. handleQueryList() {
  139. let {date} = this.params;
  140. this.params.startDate = date ? date[0] :'';
  141. this.params.endDate = date ? date[1] : '';
  142. this.fetchList(this.params, this.page);
  143. },
  144. // 重置操作
  145. handleResetList() {
  146. this.page.pageNum = 1;
  147. this.page.pageSize = 10;
  148. this.params = initParams(SearchColumns);
  149. this.fetchList(this.params, this.page);
  150. },
  151. handleTabClick() { },
  152. // 新增
  153. handleOpenAddDrawer(copyVal) {
  154. const { setVisible, setCopyParams } = this.$refs.addDrawerFef;
  155. setVisible(true,(copyVal.id && copyVal.id != '') ? true :false);
  156. copyVal.id && copyVal.id != '' && setCopyParams(copyVal.id);
  157. },
  158. // 复制
  159. handleCopy() {
  160. this.handleOpenAddDrawer(this.checkedList[0]);
  161. },
  162. // 查看
  163. async handleOpenSeeDrawer(row) {
  164. window.clearInterval(this.timeOut);
  165. const { id } = row;
  166. const { setVisible, fetchItem } = this.$refs.seeDrawerRef;
  167. await setVisible(true);
  168. await fetchItem(id);
  169. },
  170. // 编辑、修订
  171. async handleOpenEditDrawer(row) {
  172. const { id } = row;
  173. const { setVisible, fetchItem } = this.$refs.editDrawerRef;
  174. await setVisible(true);
  175. await fetchItem(id);
  176. },
  177. // 获取子表信息
  178. handleDetailsData(row) {
  179. window.clearTimeout(this.timeOut);
  180. this.timeOut = setTimeout(async () =>{
  181. try {
  182. this.tabLoading = true;
  183. this.primaryResource = row;
  184. this.checkedTabList = [];
  185. const { code, msg, data } = await orderApi.details(row.id);
  186. if (code === 200) {
  187. // 物料信息:puOrderItemList 执行结果:puOrderExecuteList
  188. for (const key in this.tabTableDatas) {
  189. this.tabTableDatas[key] = data[key];
  190. }
  191. }
  192. } catch (err) {}
  193. finally{
  194. this.tabLoading = false;
  195. }
  196. },this.timer)
  197. },
  198. // 操作提示弹窗
  199. handleConfirmTips(success){
  200. this.$confirm('是否继续此操作?', '提示', {
  201. confirmButtonText: '确定',
  202. cancelButtonText: '取消',
  203. type: 'warning'
  204. }).then(() => {
  205. success();
  206. }).catch(() => {
  207. });
  208. },
  209. // 删除操作
  210. handleDeleteList(row) {
  211. try {
  212. this.loading = true;
  213. this.handleConfirmTips(async()=>{
  214. const { id } = row;
  215. const { code } = await orderApi.remove(id);
  216. if (code === 200) {
  217. this.handleRefreshList();
  218. }
  219. })
  220. } catch (err) {
  221. //
  222. } finally {
  223. this.loading = false;
  224. }
  225. },
  226. // 批量提交
  227. handleBatchSubmit(){
  228. let inconformity = this.checkedList.filter(row => !((row.status == '0' || row.status == '3') && row.isEnd === 'N'));
  229. if(!inconformity.length && this.checkedList.length){
  230. let puOrderIds = this.checkedList.map( item => Number(item.id));
  231. this.fetchSubmit(puOrderIds);
  232. }else{
  233. this.$notify({
  234. title: '警告',
  235. message: '当前选中存在不满足提交条件的数据!',
  236. type: 'warning'
  237. });
  238. }
  239. },
  240. // 提交
  241. handleSubmit(row) {
  242. let puOrderIds = [Number(row.id)];
  243. this.fetchSubmit(puOrderIds);
  244. },
  245. fetchSubmit(puOrderIds){
  246. let _this = this;
  247. this.handleConfirmTips(async()=>{
  248. try {
  249. _this.loading = true;
  250. let { code,msg } = await orderApi.submit({ puOrderIds,checkAmount:true});
  251. console.log(code,'code');
  252. if (code == 200) {
  253. _this.handleRefreshList();
  254. }else if(code == 10000){
  255. _this.$alert(msg, '提示', {
  256. showCancelButton: true,
  257. confirmButtonText: '置为0并提交',
  258. cancelButtonText: '取消',
  259. beforeClose: async(action, instance, done) => {
  260. if (action === 'confirm') {
  261. instance.confirmButtonLoading = true;
  262. instance.confirmButtonText = '执行中...';
  263. try {
  264. let { code,msg } = await orderApi.submit({ puOrderIds,checkAmount:false});
  265. if(code == 200){
  266. done();
  267. _this.handleRefreshList();
  268. }
  269. } catch (error) {
  270. instance.confirmButtonText = "确认";
  271. }finally{
  272. instance.confirmButtonLoading = false;
  273. }
  274. } else {
  275. done();
  276. }
  277. }
  278. });
  279. }
  280. } catch (error) {}
  281. finally{
  282. this.loading = false;
  283. }
  284. })
  285. },
  286. // 判断“整单退回”按钮
  287. judgeIsAllReturn() {
  288. if (this.checkedList.length == 1) {
  289. // 非手工、状态:自由/驳回
  290. if (this.judgeIsOption('return',this.checkedList[0])) {
  291. // if (this.checkedList[0].source != 3 &&
  292. // (this.checkedList[0].status == 0 || this.checkedList[0].status == 3)
  293. // ) {
  294. return false
  295. }
  296. }
  297. return true;
  298. },
  299. // 整单退回
  300. handleAllReturn() {
  301. this.handleReturn(this.checkedList[0].id,[]);
  302. },
  303. // 判断“行退回”按钮
  304. judgeIsLineReturn() {
  305. if (this.checkedTabList.length == 1) {
  306. // 主信息:非手工、状态:自由/驳回
  307. if(this.judgeIsOption('return',this.primaryResource)){
  308. // if(this.primaryResource.source != 3 &&
  309. // (this.primaryResource.status == 0 || this.primaryResource.status == 3) ){
  310. return false
  311. }
  312. }
  313. return true;
  314. },
  315. // 行退回
  316. handleLineReturn(){
  317. let ids = this.checkedTabList.map(checked => checked.id);
  318. console.log(ids,'行退回ids');
  319. this.handleReturn(this.primaryResource.id,ids);
  320. },
  321. // 退回接口
  322. handleReturn(id,documentIds){
  323. this.$prompt('请输入退回原因', '提示', {
  324. confirmButtonText: '确定',
  325. cancelButtonText: '取消',
  326. inputPattern: /\s*\S+?/,
  327. inputErrorMessage: '退回原因不能为空'
  328. }).then(async ({ value }) => {
  329. let data = {
  330. id:Number(id),
  331. documentIds:documentIds.map(ids =>Number(ids)),
  332. baskCause: value,
  333. };
  334. console.log(data);
  335. try {
  336. let { code, msg } = await orderApi.documentsReturn(data);
  337. if (code === 200) {
  338. this.handleRefreshList();
  339. }
  340. } catch (error) {
  341. console.log(error,'error------------');
  342. }
  343. }).catch(() => { });
  344. },
  345. // 判断是否满足整单关闭
  346. judgeIsAllClose() {
  347. if (this.checkedList.length == 1) {
  348. // if (this.checkedList[0].status == 0) {
  349. if (this.judgeIsOption('allClose',this.checkedList[0])) {
  350. // 未审批状态下整单关闭
  351. return false
  352. }
  353. }
  354. return true;
  355. },
  356. // 整单关闭
  357. handleAllClose() {
  358. // 未审批状态下整单关闭
  359. try {
  360. this.handleConfirmTips(async() =>{
  361. let puOrderIds = this.checkedList.map(order => Number(order.id));
  362. let { code } = await orderApi.close({ puOrderIds });
  363. if (code === 200) {
  364. this.handleRefreshList();
  365. }
  366. })
  367. } catch (error) { }
  368. },
  369. // 付款协议
  370. async handlePaymentRequest(){
  371. // name:工号
  372. try {
  373. let {code,msg} = await orderApi.payRequest();
  374. if(code == 200){
  375. msg.replace(/\/n/g,'');
  376. let url = `uclient://start/http://172.16.100.2:8081?ssoKey=${msg}&uiloader=nc.uap.lfw.applet.PortalUILoader&nodeId=40040407`
  377. window.location.href = url;
  378. }
  379. } catch (error) {}
  380. },
  381. // 退货
  382. async handlePurchaseReturn(){
  383. const { id } = this.checkedList[0];
  384. const { setVisible, fetchStorage } = this.$refs.PurchaseReturnDrawerRef;
  385. await setVisible(true);
  386. await fetchStorage(id);
  387. },
  388. // 主表Select框
  389. handleSelect(selection, row) {
  390. this.checkedList = selection;
  391. console.log(this.checkedList, 'this.checkedList');
  392. },
  393. handleSelectionChange(selection){
  394. this.checkedList = selection;
  395. },
  396. // 子表Select框
  397. handleTabSelect(selection, row){
  398. this.checkedTabList = selection;
  399. console.log(this.checkedTabList, 'this.checkedTabList');
  400. },
  401. handleTabSelectionChange(selection){
  402. this.checkedTabList = selection;
  403. },
  404. // 保留两位小数,补位
  405. keepTwoDecimalStr(num) {
  406. if(num){
  407. const result = Number(num.toString().match(/^\d+(?:\.\d{0,2})?/));
  408. let s = result.toString();
  409. let rs = s.indexOf('.');
  410. if (rs < 0) {
  411. rs = s.length;
  412. s += '.';
  413. }
  414. while (s.length <= rs + 2) {
  415. s += '0';
  416. }
  417. return s;
  418. }else{
  419. return '';
  420. }
  421. },
  422. judgeIsOption(type,source){
  423. // status: 0=自由态,1=审批中,2=已审核,3=已驳回 4=提交中
  424. // source: 1=自动协议直采,2=协议直采,3=手工
  425. // isEnd:整单关闭标识
  426. switch(type){
  427. case 'edit':
  428. return (source.status == '0' || source.status == '3') && source.isEnd === 'N';
  429. case 'revise':
  430. return source.status == '2' && source.isEnd === 'N';
  431. case 'del':
  432. return (source.status == '0' || source.status == '3') && source.source == '3' && source.isEnd === 'N';
  433. case 'submit':
  434. return (source.status == '0' || source.status == '3') && source.isEnd === 'N';
  435. case 'allClose':
  436. return source.status == 0 && source.isEnd === 'N';
  437. case 'return':
  438. return source.source != 3 && source.isEnd === 'N' &&
  439. (source.status == 0 || source.status == 3);
  440. default:
  441. return false;
  442. }
  443. }
  444. }
  445. };
  446. </script>
  447. <template>
  448. <el-card
  449. v-loading="loading"
  450. style="width: calc(100% - 24px); height: 100%; margin: 10px;padding: 10px;"
  451. :body-style="{ padding: 0 }"
  452. >
  453. <SeeDrawer ref="seeDrawerRef"></SeeDrawer>
  454. <AddDrawer ref="addDrawerFef" @close="handleRefreshList"></AddDrawer>
  455. <EditDrawer ref="editDrawerRef" @close="handleRefreshList"></EditDrawer>
  456. <PurchaseReturnDrawer ref="PurchaseReturnDrawerRef" @close="handleRefreshList"></PurchaseReturnDrawer>
  457. <el-super-search
  458. v-model="params"
  459. :size="'mini'"
  460. :dict="dict"
  461. :columns="searchColumns"
  462. @reset="handleResetList"
  463. @submit="handleQueryList"
  464. ></el-super-search>
  465. <!-- 操作 -->
  466. <el-row :gutter="24" type="flex" justify="end" style="margin: 20px 0;">
  467. <el-col :span="24" style="text-align: right;">
  468. <el-button size="mini" type="primary" @click="handleOpenAddDrawer"
  469. v-hasPermi="['material:order:add']">新增</el-button>
  470. <el-button-group style="margin-left: 10px">
  471. <el-button type="primary" size="mini" :disabled="checkedList.length != 1" @click="handleCopy">复制</el-button>
  472. <el-button type="primary" size="mini" @click="handleBatchSubmit">批量提交</el-button>
  473. </el-button-group>
  474. <el-button-group style="margin-left: 10px" :key="checkedList.length + 1">
  475. <el-button type="primary" size="mini" @click="handleAllReturn" :disabled="judgeIsAllReturn()">整单退回</el-button>
  476. <el-button type="primary" size="mini" @click="handleAllClose" :disabled="judgeIsAllClose()">整单关闭</el-button>
  477. </el-button-group>
  478. <el-button-group style="margin:0 10px">
  479. <!-- <el-button size="mini"
  480. :disabled="!(checkedList.length == 1 && checkedList[0].deliveryStatus == '0')"
  481. :key="checkedList.length"
  482. @click="handlePurchaseReturn"
  483. >采购退货</el-button> -->
  484. <el-button type="primary" size="mini" @click="handlePaymentRequest">付款申请</el-button>
  485. <el-button
  486. type="primary"
  487. size="mini"
  488. @click="handleDownload"
  489. >批量导出</el-button>
  490. </el-button-group>
  491. </el-col>
  492. </el-row>
  493. <div style="display: flex;height:420px;">
  494. <el-super-table
  495. class="purchaseTable"
  496. v-model="tableData"
  497. ref="purchaseTable"
  498. :dict="dict"
  499. :columns="tableColumns"
  500. :selectable="setSelectable"
  501. index
  502. checkbox
  503. pagination
  504. :page="page"
  505. convenitentOperation
  506. @pagination="fetchList(params, page)"
  507. @row-dblclick="handleOpenSeeDrawer"
  508. @row-click="handleDetailsData"
  509. @selection-change="handleSelectionChange"
  510. @select="handleSelect"
  511. >
  512. <el-table-column fixed="right" label="操作" width="120">
  513. <template slot-scope="scope">
  514. <el-button
  515. v-if="judgeIsOption('revise',scope.row)"
  516. type="text"
  517. size="small"
  518. @click.stop="handleOpenEditDrawer(scope.row)"
  519. v-hasPermi="['material:order:edit']">
  520. 修订
  521. </el-button>
  522. <el-button
  523. v-if="judgeIsOption('edit',scope.row)"
  524. type="text"
  525. size="small"
  526. @click.stop="handleOpenEditDrawer(scope.row)"
  527. v-hasPermi="['material:order:edit']">
  528. 编辑
  529. </el-button>
  530. <!-- 0=自由态,1=审批中,2=已审核,3=已驳回 4=提交中-->
  531. <el-button
  532. v-if="judgeIsOption('del',scope.row)"
  533. type="text"
  534. size="small"
  535. @click.stop="handleDeleteList(scope.row)"
  536. v-hasPermi="['material:order:remove']"
  537. >删除</el-button>
  538. <el-button
  539. v-if="judgeIsOption('submit',scope.row)"
  540. type="text"
  541. size="mini"
  542. v-hasPermi="['material:order:toOa']"
  543. @click.stop="handleSubmit(scope.row)"
  544. >提交</el-button>
  545. <el-button
  546. v-if="scope.row.flowId && scope.row.flowId !== ''"
  547. type="text"
  548. size="mini"
  549. @click.stop="jumpFlow(scope.row)"
  550. >流程跳转</el-button>
  551. </template>
  552. </el-table-column>
  553. </el-super-table>
  554. </div>
  555. <div style="position: relative; padding-top: 10px;" v-loading="tabLoading">
  556. <el-row style="position: absolute; top: 30px; right: 20px;z-index: 10;">
  557. <el-button
  558. size="mini"
  559. @click="handleLineReturn"
  560. :disabled="judgeIsLineReturn()"
  561. >行退回</el-button>
  562. </el-row>
  563. <el-tabs
  564. v-model="tabName"
  565. @tab-click="handleTabClick"
  566. style="width: 100%;padding: 20px 10px;">
  567. <el-tab-pane
  568. v-for="(column, index) in tabColumns"
  569. :key="index"
  570. :label="column.title"
  571. :name="column.key"
  572. >
  573. <div style="height:580px;display:flex">
  574. <el-super-table
  575. v-model="tabTableDatas[column.key]"
  576. :ref="column.key"
  577. :dict="dict"
  578. :columns="column.tableColumns"
  579. :selectable="setTabSelectable"
  580. :checkbox="setTabSelectable()"
  581. convenitentOperation
  582. @select="handleTabSelect"
  583. @selection-change="handleTabSelectionChange"
  584. >
  585. </el-super-table>
  586. </div>
  587. </el-tab-pane>
  588. </el-tabs>
  589. </div>
  590. </el-card>
  591. </template>
  592. <style lang="scss">
  593. </style>