index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <!-- 包装 -->
  2. <template>
  3. <basic-container>
  4. <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
  5. id="out-table" :header-cell-class-name="headerClassName" :before-open="beforeOpen" :search.sync="search"
  6. v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
  7. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
  8. @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
  9. @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 289)"
  10. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 289)" @on-load="onLoad">
  11. <template slot="code" slot-scope="scope">
  12. <avue-text-ellipsis :text="scope.row.code" :height="30" use-tooltip placement="top">
  13. <small slot="more">...</small>
  14. </avue-text-ellipsis>
  15. </template>
  16. <template slot="cnName" slot-scope="scope">
  17. <div style="color: #1e9fff;cursor: pointer;" @click.stop="rowViewfun(scope.row,scope.index)">
  18. <avue-text-ellipsis :text="scope.row.cnName" :height="30" use-tooltip placement="top">
  19. <small slot="more">...</small>
  20. </avue-text-ellipsis>
  21. </div>
  22. </template>
  23. <template slot="enName" slot-scope="scope">
  24. <avue-text-ellipsis :text="scope.row.enName" :height="30" use-tooltip placement="top">
  25. <small slot="more">...</small>
  26. </avue-text-ellipsis>
  27. </template>
  28. <template slot="remarks" slot-scope="scope">
  29. <avue-text-ellipsis :text="scope.row.remarks" :height="30" use-tooltip placement="top">
  30. <small slot="more">...</small>
  31. </avue-text-ellipsis>
  32. </template>
  33. <template slot="menuLeft">
  34. <el-button type="primary" size="small" icon="el-icon-plus" @click="addbtnfun()">新建包装
  35. </el-button>
  36. <el-button type="danger" size="small" icon="el-icon-delete" plain @click="handleDelete">删 除
  37. </el-button>
  38. <el-button type="warning" size="small" icon="el-icon-printer" @click="excelBox = true">导入
  39. </el-button>
  40. <el-button type="success" size="small" @click="handleExport" icon="el-icon-printer">导出</el-button>
  41. </template>
  42. <template slot-scope="scope" slot="extendedDataArr">
  43. <span style="color: #1e9fff" @click="extendedDataview(scope.row)">
  44. {{ scope.row.extendedDataArr.length }}
  45. </span>
  46. </template>
  47. <template slot-scope="{type,disabled,row}" slot="extendedDataArrForm">
  48. <el-button type="primary" size="small" @click="dialogVisible = true">EDI CODE
  49. </el-button>
  50. </template>
  51. <template slot-scope="scope" slot="menu">
  52. <el-button type="text" icon="el-icon-view" size="small" @click.stop="rowViewfun(scope.row, scope.index)">查看
  53. </el-button>
  54. <el-button type="text" icon="el-icon-edit" size="small" @click.stop="rowEditfun(scope.row, scope.index)">编辑
  55. </el-button>
  56. <el-button type="text" icon="el-icon-delete" size="small" @click.stop="rowDel(scope.row, scope.index)">删除
  57. </el-button>
  58. <el-button v-if="scope.row.status == 1" type="text" icon="el-icon-turn-off" style="color: #85e967" size="small"
  59. @click.stop="statusfun(scope.row.id,0)">
  60. 启用
  61. </el-button>
  62. <el-button v-if="scope.row.status == 0" type="text" icon="el-icon-turn-off" style="color: #e83c3a" size="small"
  63. @click.stop="statusfun(scope.row.id,1)">
  64. 停用
  65. </el-button>
  66. </template>
  67. </avue-crud>
  68. <el-dialog title="EDI CODE" :visible.sync="dialogVisible" width="50%" append-to-body :destroy-on-close="true"
  69. :modal-append-to-body="false" :before-close="handleClose">
  70. <div>
  71. <el-button type="primary" size="small" :disabled="extendedDisabled" @click="extendedDataAdd">新增
  72. </el-button>
  73. <el-table stripe :data="form.extendedDataArr" id="out-table" :header-cell-class-name="headerClassName"
  74. style="width: 100%">
  75. <el-table-column prop="name" label="名称">
  76. <template slot-scope="{row}">
  77. <el-input v-if="row.edit" size="mini" v-model="row.name" placeholder="请输入名称"></el-input>
  78. <span v-else>{{ row.name }}</span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column prop="value" label="键值">
  82. <template slot-scope="{row}">
  83. <el-input v-if="row.edit" size="mini" v-model="row.value" placeholder="请输入键值"></el-input>
  84. <span v-else>{{ row.value }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作">
  88. <template slot-scope="scope">
  89. <el-button type="text" size="mini" :disabled="extendedDisabled"
  90. @click.stop="extendedDataEdit(scope.$index, scope.row)">{{ scope.row.edit ? '保存' : '编辑' }}</el-button>
  91. <el-button size="mini" type="text" :disabled="extendedDisabled"
  92. @click.stop="extendedDataDelete(scope.$index, scope.row)">删除</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. </div>
  97. <span slot="footer" class="dialog-footer">
  98. <el-button @click="dialogVisible = false; extendedDisabled = false">取 消</el-button>
  99. <el-button type="primary" @click="extendedDatafun">确 定</el-button>
  100. </span>
  101. </el-dialog>
  102. <el-dialog title="导入往来单位" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
  103. v-dialog-drag>
  104. <avue-form :option="excelOption" v-model="excelForm" :table-loading="excelLoading" :upload-before="uploadBefore"
  105. :upload-after="onSuccess">
  106. <template slot="excelTemplate">
  107. <el-button type="primary" @click="handleGet">
  108. 点击下载<i class="el-icon-download el-icon--right"></i>
  109. </el-button>
  110. </template>
  111. </avue-form>
  112. <p style="text-align: center;color: #DC0505">
  113. 温馨提示 第一次导入时请先下载模板
  114. </p>
  115. </el-dialog>
  116. </basic-container>
  117. </template>
  118. <script>
  119. import { bpackagesList, bpackagesDetail, bpackagesSubmit, bpackagesRemove } from "@/api/iosBasicData/bpackages";
  120. import { mapGetters } from "vuex";
  121. import { getToken } from "@/util/auth";
  122. export default {
  123. data() {
  124. return {
  125. // 扩展数据弹窗
  126. dialogVisible: false,
  127. form: {
  128. extendedDataArr: []
  129. },
  130. query: {},
  131. loading: true,
  132. excelBox: false,
  133. search: {},
  134. excelForm: {},
  135. excelLoading: false,
  136. excelOption: {
  137. submitBtn: false,
  138. emptyBtn: false,
  139. column: [
  140. {
  141. label: "模板下载",
  142. prop: "excelTemplate",
  143. formslot: true,
  144. span: 24
  145. },
  146. {
  147. label: "模板上传",
  148. prop: "excelFile",
  149. type: "upload",
  150. drag: true,
  151. loadText: "模板上传中,请稍等",
  152. span: 24,
  153. propsHttp: {
  154. res: "data"
  155. },
  156. tip: "请上传 .xls,.xlsx 标准格式文件",
  157. action: "/api/blade-los/bpackages/importBPackages"
  158. }
  159. ]
  160. },
  161. page: {
  162. pageSize: 10,
  163. currentPage: 1,
  164. total: 0,
  165. ageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
  166. },
  167. selectionList: [],
  168. option: {
  169. dialogDrag: true,
  170. },
  171. optionBack: {
  172. dialogDrag: true,
  173. addBtnText: '新建包装',
  174. addTitle: '新建包装',
  175. editBtnText: '编辑包装',
  176. editTitle: '编辑包装',
  177. viewBtnText: '查看包装',
  178. viewTitle: '查看包装',
  179. height: 'auto',
  180. stripe: true,
  181. calcHeight: 30,
  182. tip: false,
  183. searchShow: true,
  184. searchMenuSpan: 6,
  185. border: true,
  186. index: true,
  187. viewBtn: true,
  188. selection: true,
  189. dialogClickModal: false,
  190. menuWidth:260,
  191. column: [
  192. {
  193. label: "编码",
  194. prop: "code",
  195. width: "180",
  196. search: true,
  197. rules: [{
  198. required: true,
  199. message: "请输入编码",
  200. trigger: "blur"
  201. }]
  202. },
  203. {
  204. label: "中文名称",
  205. prop: "cnName",
  206. width: "180",
  207. search: true,
  208. rules: [{
  209. required: true,
  210. message: "请输入中文名称",
  211. trigger: "blur"
  212. }]
  213. },
  214. {
  215. label: "英文名称",
  216. prop: "enName",
  217. width: "180",
  218. search: true,
  219. rules: [{
  220. required: true,
  221. message: "请输入英文名称",
  222. trigger: "blur"
  223. }]
  224. },
  225. {
  226. label: "标准编码",
  227. prop: "standardCode",
  228. // rules: [{
  229. // required: true,
  230. // message: "请输入标准编码",
  231. // trigger: "blur"
  232. // }]
  233. },
  234. {
  235. label: "换算率%",
  236. prop: "exrate",
  237. rules: [{
  238. pattern: /[1-9]\d*.\d*|0\.\d*[1-9]\d*/,
  239. message: "请输入数字",
  240. trigger: 'blur'
  241. }]
  242. },
  243. {
  244. label: "状态",
  245. prop: "status",
  246. type: 'select',
  247. dicData: [{
  248. label: '启用',
  249. value: 0
  250. }, {
  251. label: '停用',
  252. value: 1
  253. }],
  254. },
  255. {
  256. label: "EDI CODE",
  257. prop: "extendedDataArr",
  258. type: 'tree',
  259. formslot: true,
  260. dicData: [],
  261. // rules: [{
  262. // required: true,
  263. // message: "请输入EDI CODE",
  264. // trigger: "blur"
  265. // }]
  266. },
  267. {
  268. label: "创建人",
  269. prop: "createUserName",
  270. display: false,
  271. },
  272. {
  273. label: "创建部门",
  274. prop: "createDeptName",
  275. display: false,
  276. },
  277. {
  278. label: "创建时间",
  279. prop: "createTime",
  280. width: 160,
  281. display: false,
  282. },
  283. {
  284. label: "修改人",
  285. prop: "updateUserName",
  286. display: false,
  287. },
  288. {
  289. label: "修改时间",
  290. prop: "updateTime",
  291. display: false,
  292. },
  293. {
  294. label: "是否已删除(0 否 1是)",
  295. prop: "isDeleted",
  296. hide: true,
  297. display: false,
  298. },
  299. {
  300. label: "备注",
  301. prop: "remarks",
  302. type: 'textarea',
  303. width: "180",
  304. slot: true,
  305. span: 24,
  306. minRows: 3,
  307. },
  308. ]
  309. },
  310. data: [],
  311. // 扩展数据的是否禁用
  312. extendedDisabled: false,
  313. // 扩展数据弹窗是查看弹窗还是点击弹窗
  314. viewDisabled: false,
  315. };
  316. },
  317. computed: {
  318. ...mapGetters(["permission"]),
  319. permissionList() {
  320. return {
  321. addBtn: this.vaildData(this.permission.bpackages_add, false),
  322. viewBtn: this.vaildData(this.permission.bpackages_view, false),
  323. delBtn: this.vaildData(this.permission.bpackages_delete, false),
  324. editBtn: this.vaildData(this.permission.bpackages_edit, false)
  325. };
  326. },
  327. ids() {
  328. let ids = [];
  329. this.selectionList.forEach(ele => {
  330. ids.push(ele.id);
  331. });
  332. return ids.join(",");
  333. }
  334. },
  335. async created() {
  336. this.option = await this.getColumnData(this.getColumnName(289), this.optionBack);
  337. },
  338. methods: {
  339. // 禁用启用按钮
  340. statusfun(id,status){
  341. this.$confirm("确定将选择数据更改状态?", {
  342. confirmButtonText: "确定",
  343. cancelButtonText: "取消",
  344. type: "warning"
  345. }).then(()=>{
  346. bpackagesDetail(id).then(res=>{
  347. let obj = res.data.data;
  348. obj.status = status
  349. bpackagesSubmit(obj).then(()=>{
  350. this.onLoad(this.page);
  351. this.$message({
  352. type: "success",
  353. message: "操作成功!"
  354. });
  355. })
  356. })
  357. })
  358. },
  359. // 导出
  360. handleExport() {
  361. var condition = ''
  362. for (const key in this.search) {
  363. var value = this.search[key]
  364. if (value) {
  365. condition += `&${key}=${this.search[key]}`
  366. }
  367. }
  368. this.$confirm('是否导出包装?', '提示', {
  369. confirmButtonText: '确定',
  370. cancelButtonText: '取消',
  371. type: 'warning'
  372. }).then(() => {
  373. window.open(
  374. `/api/blade-los/bpackages/exportBPackages?${this.website.tokenHeader
  375. }=${getToken()}${condition}`
  376. );
  377. }).catch(() => {
  378. this.$message({
  379. type: 'info',
  380. message: '已取消' //
  381. });
  382. })
  383. },
  384. uploadBefore(file, done, loading) {
  385. done();
  386. loading = true;
  387. },
  388. // 上传成功
  389. onSuccess(res, done, loading, column) {
  390. this.excelBox = false;
  391. this.$message.success("导入成功!");
  392. loading = false;
  393. this.onLoad(this.page);
  394. done();
  395. },
  396. // 下载模板
  397. handleGet() {
  398. window.open(
  399. `/api/blade-los/bpackages/exportBPackages/template?${this.website.tokenHeader
  400. }=${getToken()}`
  401. );
  402. },
  403. // 扩展数据详情的---------------------------------------
  404. // 扩展数据添加
  405. extendedDataAdd() {
  406. // console.log(this.form.extendedDataArr, 'this.form.extendedDataArr')
  407. // this.form.extendedDataArr.map(item => {
  408. // item.edit = false
  409. // })
  410. this.form.extendedDataArr.push({
  411. edit: true
  412. })
  413. },
  414. // 扩展数据编辑
  415. extendedDataEdit(index, row) {
  416. this.$set(row, 'edit', !row.edit)
  417. // row.edit = !row.edit
  418. },
  419. // 扩展数据删除
  420. extendedDataDelete(index, row) {
  421. this.form.extendedDataArr.splice(index, 1)
  422. },
  423. // 扩展数据表格点击查询详情
  424. extendedDataview(row) {
  425. this.form = row
  426. this.extendedDisabled = true
  427. this.dialogVisible = true
  428. },
  429. // 扩展数据弹窗关闭
  430. handleClose(done) {
  431. this.$confirm('确认关闭?')
  432. .then(_ => {
  433. done();
  434. })
  435. .catch(_ => { });
  436. },
  437. // 扩展数据的确认
  438. extendedDatafun(){
  439. for(let item of this.form.extendedDataArr) {
  440. if (!item.name) {
  441. this.$message({
  442. type: "warning",
  443. message: "请填写名称!"
  444. });
  445. return
  446. }
  447. if (!item.value) {
  448. this.$message({
  449. type: "warning",
  450. message: "请填写键值!"
  451. });
  452. return;
  453. }
  454. }
  455. this.dialogVisible = false;
  456. this.extendedDisabled = false
  457. this.form.extendedDataArr.map(item => {
  458. item.edit = false
  459. })
  460. },
  461. // 表格操作------------------------------------------------------------
  462. rowSave(row, done, loading) {
  463. row.extendedDataArr.map(item => {
  464. delete item.edit
  465. })
  466. row.extendedData = JSON.stringify(row.extendedDataArr)
  467. delete row.extendedDataArr
  468. bpackagesSubmit(row).then(() => {
  469. this.onLoad(this.page);
  470. this.$message({
  471. type: "success",
  472. message: "操作成功!"
  473. });
  474. done();
  475. }, error => {
  476. loading();
  477. window.console.log(error);
  478. });
  479. },
  480. rowUpdate(row, index, done, loading) {
  481. row.extendedDataArr.map(item => {
  482. delete item.edit
  483. })
  484. row.extendedData = JSON.stringify(row.extendedDataArr)
  485. delete row.extendedDataArr
  486. bpackagesSubmit(row).then(() => {
  487. this.onLoad(this.page);
  488. this.$message({
  489. type: "success",
  490. message: "操作成功!"
  491. });
  492. done();
  493. }, error => {
  494. loading();
  495. console.log(error);
  496. });
  497. },
  498. // 新增
  499. addbtnfun() {
  500. this.form.status = 0
  501. this.$refs.crud.rowAdd()
  502. },
  503. // 查看
  504. rowViewfun(row, index) {
  505. this.extendedDisabled = true
  506. this.$refs.crud.rowView(row, index)
  507. },
  508. // 编辑
  509. rowEditfun(row, index) {
  510. bpackagesDetail(row.id).then(res => {
  511. this.form = res.data.data;
  512. this.form.extendedDataArr.map(item => {
  513. item.edit = false
  514. })
  515. this.$refs.crud.rowEdit(row, index)
  516. });
  517. },
  518. // 数据删除
  519. rowDel(row) {
  520. if (row.status === 1) {
  521. this.$confirm("确定将选择数据删除?", {
  522. confirmButtonText: "确定",
  523. cancelButtonText: "取消",
  524. type: "warning"
  525. })
  526. .then(() => {
  527. return bpackagesRemove(row.id);
  528. })
  529. .then(() => {
  530. this.onLoad(this.page);
  531. this.$message({
  532. type: "success",
  533. message: "操作成功!"
  534. });
  535. });
  536. } else {
  537. this.$message({
  538. message: '非禁用状态无法删除',
  539. type: 'warning'
  540. });
  541. }
  542. },
  543. // 多选删除
  544. handleDelete() {
  545. if (this.selectionList.length === 0) {
  546. this.$message.warning("请选择至少一条数据");
  547. return;
  548. }
  549. for (const selection of this.selectionList) {
  550. if (selection.status == 0) {
  551. this.$message.warning("选中的数据中有启用数据,启用数据不可删除!");
  552. return;
  553. }
  554. }
  555. this.$confirm("确定将选择数据删除?", {
  556. confirmButtonText: "确定",
  557. cancelButtonText: "取消",
  558. type: "warning"
  559. })
  560. .then(() => {
  561. return bpackagesRemove(this.ids);
  562. })
  563. .then(() => {
  564. this.onLoad(this.page);
  565. this.$message({
  566. type: "success",
  567. message: "操作成功!"
  568. });
  569. this.$refs.crud.toggleSelection();
  570. });
  571. },
  572. beforeOpen(done, type) {
  573. if (["edit", "view"].includes(type)) {
  574. bpackagesDetail(this.form.id).then(res => {
  575. this.form = res.data.data;
  576. });
  577. }
  578. done();
  579. },
  580. searchReset() {
  581. this.query = {};
  582. this.onLoad(this.page);
  583. },
  584. searchChange(params, done) {
  585. this.query = params;
  586. this.page.currentPage = 1;
  587. this.onLoad(this.page, params);
  588. done();
  589. },
  590. selectionChange(list) {
  591. this.selectionList = list;
  592. },
  593. selectionClear() {
  594. this.selectionList = [];
  595. this.$refs.crud.toggleSelection();
  596. },
  597. currentChange(currentPage) {
  598. this.page.currentPage = currentPage;
  599. },
  600. sizeChange(pageSize) {
  601. this.page.pageSize = pageSize;
  602. },
  603. refreshChange() {
  604. this.onLoad(this.page, this.query);
  605. },
  606. onLoad(page, params = {}) {
  607. this.loading = true;
  608. bpackagesList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  609. const data = res.data.data;
  610. this.page.total = data.total;
  611. this.data = data.records;
  612. this.loading = false;
  613. this.selectionClear();
  614. });
  615. },
  616. //自定义列保存
  617. async saveColumnTwo(ref, option, optionBack, code) {
  618. /**
  619. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  620. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  621. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  622. */
  623. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  624. if (inSave) {
  625. this.$message.success("保存成功");
  626. //关闭窗口
  627. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  628. }
  629. },
  630. //自定义列重置
  631. async resetColumnTwo(ref, option, optionBack, code) {
  632. this[option] = this[optionBack];
  633. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  634. if (inSave) {
  635. this.$message.success("重置成功");
  636. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  637. }
  638. },
  639. // 更改表格颜色
  640. headerClassName(tab) {
  641. //颜色间隔
  642. let back = ""
  643. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  644. if (tab.columnIndex % 2 === 0) {
  645. back = "back-one"
  646. } else if (tab.columnIndex % 2 === 1) {
  647. back = "back-two"
  648. }
  649. }
  650. return back;
  651. },
  652. }
  653. };
  654. </script>
  655. <style lang="scss" scoped>
  656. ::v-deep#out-table .back-one {
  657. background: #ecf5ff !important;
  658. }
  659. ::v-deep#out-table .back-two {
  660. background: #ecf5ff !important;
  661. }
  662. /deep/ .el-col-md-8 {
  663. width: 24.33333%;
  664. }
  665. </style>