index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <div class="requisition" v-loading="failLoad">
  3. <div class="applyList" v-if="isList">
  4. <el-card>
  5. <el-super-search
  6. v-model="params"
  7. :size="size"
  8. :dict="dict"
  9. :columns="SearchColumns"
  10. @reset="reset"
  11. @submit="getList"
  12. ></el-super-search>
  13. <el-row :gutter="10" class="mb10" type="flex" justify="end" style="margin-top: 15px;">
  14. <el-col :span="1.5">
  15. <el-button type="primary" :size="size" plain @click="newAdd">新增</el-button>
  16. </el-col>
  17. <el-col :span="1.5">
  18. <el-button :size="size" :disabled="checkedList.length != 1" @click="handleCopy">复制</el-button>
  19. </el-col>
  20. <el-col :span="1.5">
  21. <el-button type="primary" :size="size" plain
  22. @click="download('/system/apply/material/download',{},'申请单模板.xlsx')">模板下载
  23. </el-button>
  24. </el-col>
  25. <el-col :span="1.5">
  26. <el-button :size="size" @click="handleImport">批量导入</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button :size="size" @click="handleBatchSubmit">批量提交</el-button>
  30. </el-col>
  31. <!-- 导入弹窗 -->
  32. <el-dialog
  33. title="批量导入"
  34. :visible.sync="importData.show"
  35. width="35%"
  36. center
  37. :before-close="handlefileDialogColse"
  38. >
  39. <div class="mb-import">
  40. <el-upload
  41. accept=".xls, .xlsx"
  42. ref="upload"
  43. action="#"
  44. :on-remove="handleFileRemove"
  45. :file-list="importData.list"
  46. :auto-upload="false"
  47. :on-change="handleChangeFile"
  48. :limit="1"
  49. style="text-align: center;"
  50. >
  51. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  52. <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
  53. </el-upload>
  54. </div>
  55. <span slot="footer">
  56. <el-button @click="handleImportData('cancal')">取 消</el-button>
  57. <el-button type="primary" @click="handleImportData('confirm')">确 定</el-button>
  58. </span>
  59. </el-dialog>
  60. </el-row>
  61. <div style="height: 600px;display: flex;">
  62. <el-super-table
  63. v-model="tableList"
  64. :dict="dict"
  65. :columns="TableColumns"
  66. :size="size"
  67. pagination
  68. index
  69. checkbox
  70. convenitentOperation
  71. :page="pageStatus"
  72. @pagination="getList"
  73. @row-dblclick="check"
  74. @selection-change="handleSelectionChange"
  75. @select="handleSelect"
  76. >
  77. <el-table-column
  78. fixed="right"
  79. label="操作"
  80. align="center"
  81. width="120"
  82. >
  83. <template slot-scope="scope">
  84. <el-button type="text" :size="size" @click="check(scope.row)">查看</el-button>
  85. <el-button @click="edit(scope.row)" v-if="scope.row.status == 0 || scope.row.status == 3" type="text"
  86. :size="size">编辑
  87. </el-button>
  88. <el-button type="text" :size="size" @click="deleteRow(scope.row)"
  89. v-if="scope.row.status == 0 || scope.row.status == 3">删除
  90. </el-button>
  91. </template>
  92. </el-table-column>
  93. </el-super-table>
  94. </div>
  95. </el-card>
  96. </div>
  97. <component
  98. :is="isComponent"
  99. v-model="isList"
  100. :pageStu="page"
  101. :disable="disable"
  102. :row="rowDetail"
  103. @refresh="getList"
  104. v-if="!isList
  105. "/>
  106. </div>
  107. </template>
  108. <script>
  109. import addReq from './add.vue';
  110. import {getReqList, delReq, importData, fileImport,betchSubmit} from '@/api/requisition/basic';
  111. import {saveAs} from "file-saver";
  112. import { blobValidate } from "@/utils/ruoyi";
  113. import { SearchColumns, TableColumns } from './columns';
  114. import { initDicts } from "@/utils/init.js";
  115. export default {
  116. name: 'requisition',
  117. dicts:[...initDicts([...SearchColumns,...TableColumns])],
  118. components: {
  119. addReq,
  120. ElSuperTable: () => import("@/components/super-table/index.vue"),
  121. ElSuperSearch: () => import("@/components/super-search/index.vue"),
  122. },
  123. data() {
  124. const params = this.$init.params(SearchColumns);
  125. return {
  126. failLoad: false,
  127. tableList: [],
  128. size:'mini',
  129. params:params,
  130. SearchColumns:SearchColumns,
  131. TableColumns:TableColumns,
  132. pageStatus: { pageNum: 1, pageSize: 10, total: 0 },
  133. queryParams: {
  134. billCode: '',
  135. name: '',
  136. status: '',
  137. pageNum: 1,
  138. pageSize: 10
  139. },
  140. options: [{
  141. value: 0, label: '未提交'
  142. }, {
  143. value: 1, label: '审批中'
  144. }, {
  145. value: 2, label: '已完成'
  146. }, {
  147. value: 3, label: '已驳回'
  148. },],
  149. total: 0,
  150. // isComponent
  151. isComponent: 'addReq',
  152. isList: true,
  153. // 页面状态
  154. page: '',
  155. rowDetail: {},
  156. disable: false,
  157. checkedList: [],
  158. importData: {
  159. show: false,
  160. list: []
  161. },
  162. }
  163. },
  164. created() {
  165. },
  166. mounted() {
  167. this.getList(this.queryParams)
  168. },
  169. methods: {
  170. // 批量提交
  171. async handleBatchSubmit(){
  172. let filterList = this.checkedList.filter(item => !(item.status == '0' || item.status == '3') )
  173. if(!filterList.length && this.checkedList.length){
  174. try {
  175. this.failLoad = true;
  176. let ids = this.checkedList.map( item => Number(item.id));
  177. let {code,msg} = await betchSubmit(ids);
  178. if(code == 200){
  179. this.reset();
  180. }
  181. this.$notify({
  182. title: code == 200 ? msg : 'error',
  183. type: code == 200 ? 'success' :'error',
  184. message: code == 200 ?'' :msg,
  185. });
  186. // if(code == 200){
  187. // this.$notify.success({
  188. // title: msg,
  189. // });
  190. // }else{
  191. // this.$notify.error({
  192. // title: '错误',
  193. // message: msg,
  194. // });
  195. // }
  196. } catch (error) {
  197. }finally{
  198. this.failLoad = false;
  199. }
  200. }else{
  201. this.$notify.warning({
  202. title: '警告',
  203. message: '存在不符合提交条件数据或未选择数据!',
  204. });
  205. }
  206. },
  207. reset() {
  208. // this.queryParams.billCode = ''
  209. // this.queryParams.name = ''
  210. // this.queryParams.status = ''
  211. // this.queryParams.pageNum = 1
  212. this.pageStatus.pageNum = 1;
  213. this.pageStatus.pageSize = 10;
  214. this.params = this.$init.params(SearchColumns);
  215. this.getList(this.queryParams)
  216. },
  217. newAdd() {
  218. this.isList = false
  219. this.isComponent = 'addReq'
  220. this.page = 'add'
  221. this.disable = false
  222. },
  223. // 复制
  224. handleCopy() {
  225. this.isList = false;
  226. this.isComponent = 'addReq';
  227. this.page = 'copy';
  228. this.rowDetail = this.checkedList[0];
  229. this.disable = false;
  230. },
  231. // 导入
  232. handleImport() {
  233. this.importData.show = true
  234. },
  235. // 删除文件
  236. handleFileRemove(file, fileList) {
  237. console.log('删除文件', file, 'file', fileList, 'fileList');
  238. this.importData.list = fileList;
  239. },
  240. // 文件发生改变
  241. handleChangeFile(file, fileList) {
  242. this.importData.list = fileList;
  243. },
  244. // 导入弹窗操作
  245. handleImportData(type) {
  246. switch (type) {
  247. // 取消
  248. case 'cancal':
  249. this.importData.list = [];
  250. this.importData.show = false;
  251. break;
  252. // 确认
  253. case 'confirm':
  254. if (this.importData.list.length) {
  255. let formData = new FormData();
  256. formData.append('file', this.importData.list[0].raw);
  257. importData(formData).then(res => {
  258. if (res.code == 200) {
  259. this.importData.show = false;
  260. this.importData.list = [];
  261. if (res.data.flag) {
  262. this.failLoad = true;
  263. console.log(res.data.datas)
  264. let param = {failDatas: res.data.datas}
  265. if (null != param) {
  266. fileImport(param).then(res => {
  267. console.log('res',res)
  268. const isBlob = blobValidate(res);
  269. if (isBlob) {
  270. const blob = new Blob([res]);
  271. saveAs(blob, '导入失败的物料申请单数据.xlsx');
  272. }
  273. this.failLoad = false;
  274. })
  275. }
  276. }
  277. this.$message({
  278. message: res.data.msg,
  279. type: res.data.flag ? 'warning' : 'success'
  280. });
  281. } else {
  282. this.$message({
  283. message: res.msg,
  284. type: res.code == 200 ? 'success' : 'warning'
  285. });
  286. }
  287. })
  288. } else {
  289. this.$message({
  290. message: '请上传文件之后在确认!',
  291. type: 'warning'
  292. });
  293. }
  294. break;
  295. }
  296. },
  297. handlefileDialogColse(done){
  298. this.importData.list = [];
  299. done();
  300. },
  301. // Select框
  302. handleSelect(selection, row) {
  303. this.checkedList = selection;
  304. console.log(this.checkedList, 'this.checkedList');
  305. },
  306. getList(val) {
  307. console.log('val', val)
  308. getReqList({...this.params,...this.pageStatus}).then(res => {
  309. if (res.code === 200) {
  310. this.tableList = res.rows;
  311. // this.total = res.total;
  312. this.pageStatus.total = res.total;
  313. }
  314. })
  315. this.checkedList = [];
  316. },
  317. // 表格内状态栏判断值
  318. statusJug(row) {
  319. if (row.status == 0) {
  320. return '未提交'
  321. } else if (row.status == 1) {
  322. return '审批中'
  323. } else if (row.status == 2) {
  324. return '已完成'
  325. } else if (row.status == 3) {
  326. return '已驳回'
  327. }
  328. },
  329. //
  330. handleSelectionChange(selection) {
  331. this.checkedList = selection;
  332. },
  333. check(row) {
  334. console.log('查看详情', row)
  335. this.isList = false
  336. this.isComponent = 'addReq'
  337. this.page = 'check'
  338. this.rowDetail = row
  339. this.disable = true
  340. },
  341. edit(row) {
  342. console.log('修改先加载详情', row)
  343. this.isList = false
  344. this.isComponent = 'addReq'
  345. this.page = 'edit'
  346. this.rowDetail = row
  347. this.disable = false
  348. },
  349. commit(row) {
  350. console.log('row', row)
  351. },
  352. deleteRow(row) {
  353. this.$confirm('是否删除此条数据?', '提示', {
  354. confirmButtonText: '确定',
  355. cancelButtonText: '取消',
  356. type: 'warning'
  357. }).then(() => {
  358. delReq(row.id).then(res => {
  359. if (res.code === 200) {
  360. this.$message({
  361. message: res.msg,
  362. type: 'success'
  363. });
  364. this.getList(this.queryParams)
  365. }
  366. })
  367. }).catch(() => {
  368. })
  369. },
  370. handleSizeChange(val) {
  371. console.log(`每页 ${val} 条`);
  372. this.queryParams.pageSize = val
  373. this.getList(this.queryParams)
  374. },
  375. handleCurrentChange(val) {
  376. console.log(`当前页: ${val}`);
  377. this.queryParams.pageNum = val
  378. this.getList(this.queryParams)
  379. }
  380. }
  381. }
  382. </script>
  383. <style scoped lang="scss">
  384. .requisition {
  385. // height: calc(100vh - 84px);
  386. padding: 12px;
  387. box-sizing: border-box;
  388. }
  389. </style>