index.vue 13 KB

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