index.vue 13 KB

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