index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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', 287)"
  24. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 287)"
  25. @on-load="onLoad" >
  26. <template slot="remarks" slot-scope="scope">
  27. <avue-text-ellipsis :text="scope.row.remarks" :height="30">
  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.bcountrys_delete"
  37. @click="handleDelete">删 除
  38. </el-button>
  39. </template>
  40. </avue-crud>
  41. </basic-container>
  42. </template>
  43. <script>
  44. import {bcountrysList, bcountrysDetail, bcountrysSubmit, bcountrysRemove} from "@/api/iosBasicData/bcountrys";
  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. calcHeight: 30,
  62. tip: false,
  63. searchShow: true,
  64. searchMenuSpan: 6,
  65. border: true,
  66. index: true,
  67. viewBtn: true,
  68. selection: true,
  69. dialogClickModal: false,
  70. column: [
  71. {
  72. label: "编码",
  73. prop: "code",
  74. rules: [{
  75. required: true,
  76. message: "请输入编码",
  77. trigger: "blur"
  78. }]
  79. },
  80. {
  81. label: "国际三字码",
  82. prop: "unCode",
  83. rules: [{
  84. // max: 3,
  85. required: true,
  86. message: "请输入三个字符",
  87. trigger: "blur"
  88. },{
  89. pattern:/^[a-zA-Z0-9]{1,3}$/,
  90. message:"请输入英文字母或数字",
  91. trigger:'blur'
  92. }]
  93. },
  94. {
  95. label: "中文名称",
  96. prop: "cnName",
  97. rules: [{
  98. required: true,
  99. message: "请输入中文名称",
  100. trigger: "blur"
  101. }]
  102. },
  103. {
  104. label: "英文名称",
  105. prop: "enName",
  106. rules: [{
  107. required: true,
  108. message: "请输入英文名称",
  109. trigger: "blur"
  110. }]
  111. },
  112. {
  113. label: "版本",
  114. prop: "version",
  115. rules: [{
  116. required: true,
  117. message: "请输入版本",
  118. trigger: "blur"
  119. }]
  120. },
  121. {
  122. label: "状态",
  123. prop: "status",
  124. type:'select',
  125. dicData:[{
  126. label:'正常',
  127. value:0
  128. },{
  129. label:'停用',
  130. value:1
  131. }],
  132. },
  133. {
  134. label: "主键",
  135. prop: "id",
  136. hide:true,
  137. display:false,
  138. },
  139. {
  140. label: "创建人 Id",
  141. prop: "createUser",
  142. hide:true,
  143. display:false,
  144. },
  145. {
  146. label: "创建人",
  147. prop: "createUserName",
  148. display:false,
  149. },
  150. {
  151. label: "创建部门 Id",
  152. prop: "createDept",
  153. hide:true,
  154. display:false,
  155. },
  156. {
  157. label: "创建部门",
  158. prop: "createDeptName",
  159. display:false,
  160. },
  161. {
  162. label: "创建时间",
  163. prop: "createTime",
  164. hide:true,
  165. display:false,
  166. },
  167. {
  168. label: "修改人 Id",
  169. prop: "updateUser",
  170. hide:true,
  171. display:false,
  172. },
  173. {
  174. label: "修改人",
  175. prop: "updateUserName",
  176. display:false,
  177. },
  178. {
  179. label: "修改时间",
  180. prop: "updateTime",
  181. display:false,
  182. },
  183. {
  184. label: "是否已删除(0 否 1是)",
  185. prop: "isDeleted",
  186. hide:true,
  187. display:false,
  188. },
  189. {
  190. label: "备注",
  191. prop: "remarks",
  192. type: 'textarea',
  193. width: "180",
  194. slot: true,
  195. span: 24,
  196. minRows: 3,
  197. },
  198. ]
  199. },
  200. data: []
  201. };
  202. },
  203. computed: {
  204. ...mapGetters(["permission"]),
  205. // 表格多个按钮权限控制,采用函数方式可以精确到行控制
  206. permissionList() {
  207. return {
  208. // addBtn: this.vaildData(this.permission.bcountrys_add, false),
  209. // viewBtn: this.vaildData(this.permission.bcountrys_view, false),
  210. // delBtn: this.vaildData(this.permission.bcountrys_delete, false),
  211. // editBtn: this.vaildData(this.permission.bcountrys_edit, false)
  212. };
  213. },
  214. ids() {
  215. let ids = [];
  216. this.selectionList.forEach(ele => {
  217. ids.push(ele.id);
  218. });
  219. return ids.join(",");
  220. }
  221. },
  222. async created() {
  223. this.option = await this.getColumnData(this.getColumnName(287), this.optionBack);
  224. },
  225. methods: {
  226. // 新增数据后点击确定触发该事件 (新增确认)
  227. rowSave(row, done, loading) {
  228. bcountrysSubmit(row).then(() => {
  229. this.onLoad(this.page);
  230. this.$message({
  231. type: "success",
  232. message: "操作成功!"
  233. });
  234. done();
  235. }, error => {
  236. loading();
  237. window.console.log(error);
  238. });
  239. },
  240. // 更新数据后确定触发该事件 (编辑确认)
  241. rowUpdate(row, index, done, loading) {
  242. bcountrysSubmit(row).then(() => {
  243. this.onLoad(this.page);
  244. this.$message({
  245. type: "success",
  246. message: "操作成功!"
  247. });
  248. done();
  249. }, error => {
  250. loading();
  251. console.log(error);
  252. });
  253. },
  254. // 行数据删除触发 (删除)
  255. rowDel(row) {
  256. this.$confirm("确定将选择数据删除?", {
  257. confirmButtonText: "确定",
  258. cancelButtonText: "取消",
  259. type: "warning"
  260. })
  261. .then(() => {
  262. return bcountrysRemove(row.id);
  263. })
  264. .then(() => {
  265. this.onLoad(this.page);
  266. this.$message({
  267. type: "success",
  268. message: "操作成功!"
  269. });
  270. });
  271. },
  272. // 多选删除触发
  273. handleDelete() {
  274. if (this.selectionList.length === 0) {
  275. this.$message.warning("请选择至少一条数据");
  276. return;
  277. }
  278. this.$confirm("确定将选择数据删除?", {
  279. confirmButtonText: "确定",
  280. cancelButtonText: "取消",
  281. type: "warning"
  282. })
  283. .then(() => {
  284. return bcountrysRemove(this.ids);
  285. })
  286. .then(() => {
  287. this.onLoad(this.page);
  288. this.$message({
  289. type: "success",
  290. message: "操作成功!"
  291. });
  292. this.$refs.crud.toggleSelection();
  293. });
  294. },
  295. // 打开前的回调,会暂停Dialog的打开,done用于关闭Dialog,type为当前窗口的类型
  296. beforeOpen(done, type) {
  297. if (["edit", "view"].includes(type)) {
  298. bcountrysDetail(this.form.id).then(res => {
  299. this.form = res.data.data;
  300. });
  301. }
  302. done();
  303. },
  304. // 清空搜索回调方法
  305. searchReset() {
  306. this.query = {};
  307. this.onLoad(this.page);
  308. },
  309. // 点击搜索后触发该事件(由于page分页信息和search搜索信息,可以直接通过this.page和this.search拿到)
  310. searchChange(params, done) {
  311. this.query = params;
  312. this.page.currentPage = 1;
  313. this.onLoad(this.page, params);
  314. done();
  315. },
  316. // 当选择项发生变化时会触发该事件 (多选)
  317. selectionChange(list) {
  318. this.selectionList = list;
  319. },
  320. // 用于多选表格,传递数组进去,会勾选数组中的对象,如果已经勾选则会取消勾选
  321. selectionClear() {
  322. this.selectionList = [];
  323. this.$refs.crud.toggleSelection();
  324. },
  325. // 分页页数
  326. currentChange(currentPage){
  327. this.page.currentPage = currentPage;
  328. },
  329. // 分页条数
  330. sizeChange(pageSize){
  331. this.page.pageSize = pageSize;
  332. },
  333. // 点击刷新
  334. refreshChange() {
  335. this.onLoad(this.page, this.query);
  336. },
  337. // 获取列表数据
  338. onLoad(page, params = {}) {
  339. this.loading = true;
  340. bcountrysList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  341. const data = res.data.data;
  342. this.page.total = data.total;
  343. this.data = data.records;
  344. this.loading = false;
  345. this.selectionClear();
  346. });
  347. },
  348. //自定义列保存
  349. async saveColumnTwo(ref, option, optionBack, code) {
  350. /**
  351. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  352. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  353. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  354. */
  355. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  356. if (inSave) {
  357. this.$message.success("保存成功");
  358. //关闭窗口
  359. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  360. }
  361. },
  362. //自定义列重置
  363. async resetColumnTwo(ref, option, optionBack, code) {
  364. this[option] = this[optionBack];
  365. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  366. if (inSave) {
  367. this.$message.success("重置成功");
  368. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  369. }
  370. },
  371. // 更改表格颜色
  372. headerClassName(tab){
  373. //颜色间隔
  374. let back = ""
  375. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  376. if (tab.columnIndex % 2 === 0) {
  377. back = "back-one"
  378. } else if (tab.columnIndex % 2 === 1) {
  379. back = "back-two"
  380. }
  381. }
  382. return back;
  383. },
  384. }
  385. };
  386. </script>
  387. <style lang="scss" scoped>
  388. ::v-deep#out-table .back-one {
  389. background: #ecf5ff !important;
  390. }
  391. ::v-deep#out-table .back-two {
  392. background: #ecf5ff !important;
  393. }
  394. /deep/ .el-col-md-8 {
  395. width: 24.33333%;
  396. }
  397. </style>