index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <!-- 计量单位 -->
  2. <template>
  3. <basic-container>
  4. <avue-crud :option="option"
  5. :table-loading="loading"
  6. :data="data"
  7. :page.sync="page"
  8. :permission="permissionList"
  9. id="out-table"
  10. :header-cell-class-name="headerClassName"
  11. :before-open="beforeOpen"
  12. v-model="form"
  13. ref="crud"
  14. @row-update="rowUpdate"
  15. @row-save="rowSave"
  16. @row-del="rowDel"
  17. @search-change="searchChange"
  18. @search-reset="searchReset"
  19. @selection-change="selectionChange"
  20. @current-change="currentChange"
  21. @size-change="sizeChange"
  22. @refresh-change="refreshChange"
  23. @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 296)"
  24. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 296)"
  25. @on-load="onLoad">
  26. <template slot="code" slot-scope="scope">
  27. <avue-text-ellipsis :text="scope.row.code" :height="30" use-tooltip placement="top">
  28. <small slot="more">...</small>
  29. </avue-text-ellipsis>
  30. </template>
  31. <template slot="cnName" slot-scope="scope">
  32. <avue-text-ellipsis :text="scope.row.cnName" :height="30" use-tooltip placement="top">
  33. <small slot="more">...</small>
  34. </avue-text-ellipsis>
  35. </template>
  36. <template slot="enName" slot-scope="scope">
  37. <avue-text-ellipsis :text="scope.row.enName" :height="30" use-tooltip placement="top">
  38. <small slot="more">...</small>
  39. </avue-text-ellipsis>
  40. </template>
  41. <template slot="remarks" slot-scope="scope">
  42. <avue-text-ellipsis :text="scope.row.remarks" :height="30" use-tooltip placement="top">
  43. <small slot="more">...</small>
  44. </avue-text-ellipsis>
  45. </template>
  46. <template slot="menuLeft">
  47. <el-button type="danger"
  48. size="small"
  49. icon="el-icon-delete"
  50. plain
  51. v-if="permission.bunits_delete"
  52. @click="handleDelete">删 除
  53. </el-button>
  54. </template>
  55. </avue-crud>
  56. </basic-container>
  57. </template>
  58. <script>
  59. import {getBunitsList, getBunitsDetail, addBunits, updateBunits, removeBunits} from "@/api/iosBasicData/bunits";
  60. import {mapGetters} from "vuex";
  61. export default {
  62. data() {
  63. return {
  64. form: {},
  65. query: {},
  66. loading: true,
  67. page: {
  68. pageSize: 10,
  69. currentPage: 1,
  70. total: 0
  71. },
  72. selectionList: [],
  73. option: {},
  74. optionBack: {
  75. height:'auto',
  76. stripe: true,
  77. searchIcon: true,
  78. searchIndex: 3,
  79. calcHeight: 30,
  80. tip: false,
  81. searchShow: true,
  82. searchMenuSpan: 6,
  83. border: true,
  84. index: true,
  85. viewBtn: true,
  86. selection: true,
  87. dialogClickModal: false,
  88. column: [
  89. // {
  90. // label: "主键",
  91. // prop: "id",
  92. // rules: [{
  93. // required: true,
  94. // message: "请输入主键",
  95. // trigger: "blur"
  96. // }]
  97. // },
  98. // {
  99. // label: "创建人 Id",
  100. // prop: "createUser",
  101. // rules: [{
  102. // required: true,
  103. // message: "请输入创建人 Id",
  104. // trigger: "blur"
  105. // }]
  106. // },
  107. // {
  108. // label: "创建人",
  109. // prop: "createUserName",
  110. // rules: [{
  111. // required: true,
  112. // message: "请输入创建人",
  113. // trigger: "blur"
  114. // }]
  115. // },
  116. // {
  117. // label: "创建部门 Id",
  118. // prop: "createDept",
  119. // rules: [{
  120. // required: true,
  121. // message: "请输入创建部门 Id",
  122. // trigger: "blur"
  123. // }]
  124. // },
  125. // {
  126. // label: "创建部门",
  127. // prop: "createDeptName",
  128. // rules: [{
  129. // required: true,
  130. // message: "请输入创建部门",
  131. // trigger: "blur"
  132. // }]
  133. // },
  134. // {
  135. // label: "创建时间",
  136. // prop: "createTime",
  137. // rules: [{
  138. // required: true,
  139. // message: "请输入创建时间",
  140. // trigger: "blur"
  141. // }]
  142. // },
  143. // {
  144. // label: "修改人 Id",
  145. // prop: "updateUser",
  146. // rules: [{
  147. // required: true,
  148. // message: "请输入修改人 Id",
  149. // trigger: "blur"
  150. // }]
  151. // },
  152. // {
  153. // label: "修改人",
  154. // prop: "updateUserName",
  155. // rules: [{
  156. // required: true,
  157. // message: "请输入修改人",
  158. // trigger: "blur"
  159. // }]
  160. // },
  161. // {
  162. // label: "修改时间",
  163. // prop: "updateTime",
  164. // rules: [{
  165. // required: true,
  166. // message: "请输入修改时间",
  167. // trigger: "blur"
  168. // }]
  169. // },
  170. {
  171. label: "代码",
  172. prop: "code",
  173. search: true,
  174. slot: true,
  175. rules: [{
  176. required: true,
  177. message: "请输入代码",
  178. trigger: "blur"
  179. }]
  180. },
  181. {
  182. label: "中文名称",
  183. prop: "cnName",
  184. search: true,
  185. slot: true,
  186. rules: [{
  187. required: true,
  188. message: "请输入中文名称",
  189. trigger: "blur"
  190. }]
  191. },
  192. {
  193. label: "英文名称",
  194. prop: "enName",
  195. search: true,
  196. slot: true,
  197. rules: [{
  198. required: true,
  199. message: "请输入英文名称",
  200. trigger: "blur"
  201. }]
  202. },
  203. {
  204. label: "单一窗口代码",
  205. prop: "codeSw",
  206. search: true,
  207. rules: [{
  208. required: true,
  209. message: "请输入单一窗口代码",
  210. trigger: "blur"
  211. }]
  212. },
  213. {
  214. label: "数量规则",
  215. prop: "quantityRule",
  216. // rules: [{
  217. // required: true,
  218. // message: "请输入数量规则,用于根据单位自动计算数量",
  219. // trigger: "blur"
  220. // }]
  221. },
  222. // {
  223. // label: "quantity_rule=FIXED 时,默认的数量",
  224. // prop: "quantity",
  225. // rules: [{
  226. // required: true,
  227. // message: "请输入quantity_rule=FIXED 时,默认的数量",
  228. // trigger: "blur"
  229. // }]
  230. // },
  231. {
  232. label: "版本",
  233. prop: "version",
  234. display:false,
  235. },
  236. {
  237. label: "状态",
  238. prop: "status",
  239. type: "select",
  240. dicData:[{
  241. label:'启用',
  242. value:0
  243. },{
  244. label:'停用',
  245. value:1
  246. }],
  247. value: 0
  248. },
  249. // {
  250. // label: "是否已删除(0 否 1是)",
  251. // prop: "isDeleted",
  252. // rules: [{
  253. // required: true,
  254. // message: "请输入是否已删除(0 否 1是)",
  255. // trigger: "blur"
  256. // }]
  257. // },
  258. {
  259. label: "备注",
  260. prop: "remarks",
  261. type: 'textarea',
  262. width: "180",
  263. span: 24,
  264. minRows: 3,
  265. slot: true
  266. },
  267. ]
  268. },
  269. data: []
  270. };
  271. },
  272. computed: {
  273. ...mapGetters(["permission"]),
  274. permissionList() {
  275. return {
  276. // addBtn: this.vaildData(this.permission.bunits_add, false),
  277. // viewBtn: this.vaildData(this.permission.bunits_view, false),
  278. // delBtn: this.vaildData(this.permission.bunits_delete, false),
  279. // editBtn: this.vaildData(this.permission.bunits_edit, false)
  280. };
  281. },
  282. ids() {
  283. let ids = [];
  284. this.selectionList.forEach(ele => {
  285. ids.push(ele.id);
  286. });
  287. return ids.join(",");
  288. }
  289. },
  290. async created() {
  291. this.option = await this.getColumnData(this.getColumnName(296), this.optionBack);
  292. },
  293. methods: {
  294. rowSave(row, done, loading) {
  295. addBunits(row).then(() => {
  296. this.onLoad(this.page);
  297. this.$message({
  298. type: "success",
  299. message: "操作成功!"
  300. });
  301. done();
  302. }, error => {
  303. loading();
  304. window.console.log(error);
  305. });
  306. },
  307. rowUpdate(row, index, done, loading) {
  308. updateBunits(row).then(() => {
  309. this.onLoad(this.page);
  310. this.$message({
  311. type: "success",
  312. message: "操作成功!"
  313. });
  314. done();
  315. }, error => {
  316. loading();
  317. console.log(error);
  318. });
  319. },
  320. rowDel(row) {
  321. if (row.status === 1) {
  322. this.$confirm("确定将选择数据删除?", {
  323. confirmButtonText: "确定",
  324. cancelButtonText: "取消",
  325. type: "warning"
  326. })
  327. .then(() => {
  328. return removeBunits(row.id);
  329. })
  330. .then(() => {
  331. this.onLoad(this.page);
  332. this.$message({
  333. type: "success",
  334. message: "操作成功!"
  335. });
  336. });
  337. } else {
  338. this.$message({
  339. message: '非禁用状态无法删除',
  340. type: 'warning'
  341. });
  342. }
  343. },
  344. handleDelete() {
  345. if (this.selectionList.length === 0) {
  346. this.$message.warning("请选择至少一条数据");
  347. return;
  348. }
  349. this.$confirm("确定将选择数据删除?", {
  350. confirmButtonText: "确定",
  351. cancelButtonText: "取消",
  352. type: "warning"
  353. })
  354. .then(() => {
  355. return removeBunits(this.ids);
  356. })
  357. .then(() => {
  358. this.onLoad(this.page);
  359. this.$message({
  360. type: "success",
  361. message: "操作成功!"
  362. });
  363. this.$refs.crud.toggleSelection();
  364. });
  365. },
  366. beforeOpen(done, type) {
  367. if (["edit", "view"].includes(type)) {
  368. getBunitsDetail(this.form.id).then(res => {
  369. this.form = res.data.data;
  370. });
  371. }
  372. done();
  373. },
  374. searchReset() {
  375. this.query = {};
  376. this.onLoad(this.page);
  377. },
  378. searchChange(params, done) {
  379. this.query = params;
  380. this.page.currentPage = 1;
  381. this.onLoad(this.page, params);
  382. done();
  383. },
  384. selectionChange(list) {
  385. this.selectionList = list;
  386. // 选择的数据抛出
  387. this.$emit('selectionChange',list)
  388. },
  389. selectionClear() {
  390. this.selectionList = [];
  391. this.$refs.crud.toggleSelection();
  392. },
  393. currentChange(currentPage){
  394. this.page.currentPage = currentPage;
  395. },
  396. sizeChange(pageSize){
  397. this.page.pageSize = pageSize;
  398. },
  399. refreshChange() {
  400. this.onLoad(this.page, this.query);
  401. },
  402. onLoad(page, params = {}) {
  403. this.loading = true;
  404. getBunitsList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  405. const data = res.data.data;
  406. this.page.total = data.total;
  407. this.data = data.records;
  408. this.loading = false;
  409. this.selectionClear();
  410. });
  411. },
  412. //自定义列保存
  413. async saveColumnTwo(ref, option, optionBack, code) {
  414. /**
  415. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  416. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  417. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  418. */
  419. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  420. if (inSave) {
  421. this.$message.success("保存成功");
  422. //关闭窗口
  423. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  424. }
  425. },
  426. //自定义列重置
  427. async resetColumnTwo(ref, option, optionBack, code) {
  428. this[option] = this[optionBack];
  429. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  430. if (inSave) {
  431. this.$message.success("重置成功");
  432. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  433. }
  434. },
  435. // 更改表格颜色
  436. headerClassName(tab){
  437. //颜色间隔
  438. let back = ""
  439. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  440. if (tab.columnIndex % 2 === 0) {
  441. back = "back-one"
  442. } else if (tab.columnIndex % 2 === 1) {
  443. back = "back-two"
  444. }
  445. }
  446. return back;
  447. },
  448. }
  449. };
  450. </script>
  451. <style lang="scss" scoped>
  452. ::v-deep#out-table .back-one {
  453. background: #ecf5ff !important;
  454. }
  455. ::v-deep#out-table .back-two {
  456. background: #ecf5ff !important;
  457. }
  458. /deep/ .el-col-md-8 {
  459. width: 24.33333%;
  460. }
  461. </style>