shipyard.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <basic-container>
  3. <el-row>
  4. <el-col :span="12">
  5. <avue-crud :option="option"
  6. :table-loading="loading"
  7. :data="data"
  8. :page.sync="page"
  9. :permission="permissionList"
  10. :before-open="beforeOpen"
  11. v-model="form"
  12. ref="crud"
  13. @row-update="rowUpdate"
  14. @row-save="rowSave"
  15. @row-del="rowDel"
  16. @row-click="rowClick"
  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. @on-load="onLoad">
  24. <template slot="menuLeft">
  25. <el-button type="danger"
  26. size="small"
  27. icon="el-icon-delete"
  28. plain
  29. v-if="permission.shipyard_delete"
  30. @click="handleDelete">删 除
  31. </el-button>
  32. </template>
  33. </avue-crud>
  34. </el-col>
  35. <el-col :span="12">
  36. <avue-crud :option="optionShip"
  37. :table-loading="loadingShip"
  38. :data="dataShip"
  39. :page.sync="pageShip"
  40. :permission="permissionListShip"
  41. :before-open="beforeOpenShip"
  42. v-model="formShip"
  43. ref="crudShip"
  44. @row-update="rowUpdateShip"
  45. @row-save="rowSaveShip"
  46. @row-del="rowDelShip"
  47. @search-change="searchChangeShip"
  48. @search-reset="searchResetShip"
  49. @selection-change="selectionChangeShip"
  50. @current-change="currentChangeShip"
  51. @size-change="sizeChangeShip"
  52. @refresh-change="refreshChangeShip"
  53. >
  54. <template slot="menuLeft">
  55. <el-button type="danger"
  56. size="small"
  57. icon="el-icon-delete"
  58. plain
  59. v-if="permission.ship_delete"
  60. @click="handleDeleteShip">删 除
  61. </el-button>
  62. <span>【{{yardName}}】</span>
  63. </template>
  64. </avue-crud>
  65. </el-col>
  66. </el-row>
  67. </basic-container>
  68. </template>
  69. <script>
  70. import {getList, getDetail, add, update, remove} from "@/api/ship/shipyard";
  71. import {mapGetters} from "vuex";
  72. import {getList as getListShip, getDetail as getDetailShip, add as addShip, update as updateShip, remove as removeShip} from "@/api/ship/ship";
  73. export default {
  74. data() {
  75. return {
  76. form: {},
  77. query: {},
  78. loading: true,
  79. page: {
  80. pageSize: 10,
  81. currentPage: 1,
  82. total: 0
  83. },
  84. selectionList: [],
  85. option: {
  86. height:'auto',
  87. calcHeight: 30,
  88. tip: false,
  89. // searchBtn: false,
  90. searchShow: true,
  91. searchMenuSpan: 6,
  92. searchSpan: 12,
  93. border: true,
  94. index: true,
  95. viewBtn: true,
  96. selection: true,
  97. dialogClickModal: false,
  98. align: "center",
  99. column: [
  100. /*{
  101. label: "船厂编号",
  102. prop: "code",
  103. search: true,
  104. rules: [{
  105. required: true,
  106. message: "请输入船厂编号",
  107. trigger: "blur"
  108. }]
  109. },*/
  110. {
  111. label: "船厂名称",
  112. prop: "name",
  113. search: true,
  114. rules: [{
  115. required: true,
  116. message: "请输入船厂名称",
  117. trigger: "blur"
  118. }]
  119. },
  120. ]
  121. },
  122. data: [],
  123. yardId: '',
  124. formShip: {},
  125. queryShip: {},
  126. loadingShip: true,
  127. pageShip: {
  128. pageSize: 10,
  129. currentPage: 1,
  130. total: 0
  131. },
  132. selectionListShip: [],
  133. optionShip: {
  134. addTitle:'',
  135. editTitle:'',
  136. height:'auto',
  137. calcHeight: 30,
  138. tip: false,
  139. searchShow: true,
  140. searchMenuSpan: 6,
  141. searchSpan: 12,
  142. border: true,
  143. index: true,
  144. viewBtn: true,
  145. selection: true,
  146. dialogClickModal: false,
  147. align: "center",
  148. column: [
  149. {
  150. label: "船只编号",
  151. prop: "code",
  152. rules: [{
  153. required: true,
  154. message: "请输入船只编号",
  155. trigger: "blur"
  156. }]
  157. },
  158. {
  159. label: "船只名称",
  160. prop: "name",
  161. search: true,
  162. rules: [{
  163. required: true,
  164. message: "请输入船只名称",
  165. trigger: "blur"
  166. }]
  167. },
  168. ]
  169. },
  170. dataShip: []
  171. };
  172. },
  173. computed: {
  174. ...mapGetters(["permission"]),
  175. permissionList() {
  176. return {
  177. addBtn: this.vaildData(this.permission.shipyard_add, false),
  178. viewBtn: this.vaildData(this.permission.shipyard_view, false),
  179. delBtn: this.vaildData(this.permission.shipyard_delete, false),
  180. editBtn: this.vaildData(this.permission.shipyard_edit, false)
  181. };
  182. },
  183. ids() {
  184. let ids = [];
  185. this.selectionList.forEach(ele => {
  186. ids.push(ele.id);
  187. });
  188. return ids.join(",");
  189. },
  190. permissionListShip() {
  191. return {
  192. addBtn: this.vaildData(this.permission.ship_add, false),
  193. viewBtn: this.vaildData(this.permission.ship_view, false),
  194. delBtn: this.vaildData(this.permission.ship_delete, false),
  195. editBtn: this.vaildData(this.permission.ship_edit, false)
  196. };
  197. },
  198. idsShip() {
  199. let ids = [];
  200. this.selectionList.forEach(ele => {
  201. ids.push(ele.id);
  202. });
  203. return ids.join(",");
  204. }
  205. },
  206. methods: {
  207. rowClick(row, column, event){
  208. this.yardId = row.id;
  209. this.yardName = row.name;
  210. this.onLoadShip(this.pageShip)
  211. },
  212. rowSave(row, done, loading) {
  213. add(row).then(() => {
  214. this.onLoad(this.page);
  215. this.$message({
  216. type: "success",
  217. message: "操作成功!"
  218. });
  219. done();
  220. }, error => {
  221. loading();
  222. window.console.log(error);
  223. });
  224. },
  225. rowUpdate(row, index, done, loading) {
  226. update(row).then(() => {
  227. this.onLoad(this.page);
  228. this.$message({
  229. type: "success",
  230. message: "操作成功!"
  231. });
  232. done();
  233. }, error => {
  234. loading();
  235. console.log(error);
  236. });
  237. },
  238. rowDel(row) {
  239. this.$confirm("确定将选择数据删除?", {
  240. confirmButtonText: "确定",
  241. cancelButtonText: "取消",
  242. type: "warning"
  243. })
  244. .then(() => {
  245. return remove(row.id);
  246. })
  247. .then(() => {
  248. this.onLoad(this.page);
  249. this.$message({
  250. type: "success",
  251. message: "操作成功!"
  252. });
  253. });
  254. },
  255. handleDelete() {
  256. if (this.selectionList.length === 0) {
  257. this.$message.warning("请选择至少一条数据");
  258. return;
  259. }
  260. this.$confirm("确定将选择数据删除?", {
  261. confirmButtonText: "确定",
  262. cancelButtonText: "取消",
  263. type: "warning"
  264. })
  265. .then(() => {
  266. return remove(this.ids);
  267. })
  268. .then(() => {
  269. this.onLoad(this.page);
  270. this.$message({
  271. type: "success",
  272. message: "操作成功!"
  273. });
  274. this.$refs.crud.toggleSelection();
  275. });
  276. },
  277. beforeOpen(done, type) {
  278. if (["edit", "view"].includes(type)) {
  279. getDetail(this.form.id).then(res => {
  280. this.form = res.data.data;
  281. });
  282. }
  283. done();
  284. },
  285. searchReset() {
  286. this.query = {};
  287. this.onLoad(this.page);
  288. },
  289. searchChange(params, done) {
  290. this.query = params;
  291. this.page.currentPage = 1;
  292. this.onLoad(this.page, params);
  293. done();
  294. },
  295. selectionChange(list) {
  296. this.selectionList = list;
  297. },
  298. selectionClear() {
  299. this.selectionList = [];
  300. this.$refs.crud.toggleSelection();
  301. },
  302. currentChange(currentPage){
  303. this.page.currentPage = currentPage;
  304. },
  305. sizeChange(pageSize){
  306. this.page.pageSize = pageSize;
  307. },
  308. refreshChange() {
  309. this.onLoad(this.page, this.query);
  310. },
  311. onLoad(page, params = {}) {
  312. this.loading = true;
  313. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  314. const data = res.data.data;
  315. this.page.total = data.total;
  316. this.data = data.records;
  317. if (this.data.length > 0){
  318. this.yardId = this.data[0].id;
  319. this.yardName = this.data[0].name;
  320. this.onLoadShip(this.pageShip)
  321. }
  322. this.loading = false;
  323. this.selectionClear();
  324. });
  325. },
  326. //*********************** 右组件 ***************************************//
  327. rowSaveShip(row, done, loading) {
  328. row.yardId = this.yardId;
  329. addShip(row).then(() => {
  330. this.onLoadShip(this.pageShip);
  331. this.$message({
  332. type: "success",
  333. message: "操作成功!"
  334. });
  335. done();
  336. }, error => {
  337. loading();
  338. window.console.log(error);
  339. });
  340. },
  341. rowUpdateShip(row, index, done, loading) {
  342. row.yardId = this.yardId;
  343. updateShip(row).then(() => {
  344. this.onLoadShip(this.pageShip);
  345. this.$message({
  346. type: "success",
  347. message: "操作成功!"
  348. });
  349. done();
  350. }, error => {
  351. loading();
  352. console.log(error);
  353. });
  354. },
  355. rowDelShip(row) {
  356. this.$confirm("确定将选择数据删除?", {
  357. confirmButtonText: "确定",
  358. cancelButtonText: "取消",
  359. type: "warning"
  360. })
  361. .then(() => {
  362. return removeShip(row.id);
  363. })
  364. .then(() => {
  365. this.onLoadShip(this.pageShip);
  366. this.$message({
  367. type: "success",
  368. message: "操作成功!"
  369. });
  370. });
  371. },
  372. handleDeleteShip() {
  373. if (this.selectionList.length === 0) {
  374. this.$message.warning("请选择至少一条数据");
  375. return;
  376. }
  377. this.$confirm("确定将选择数据删除?", {
  378. confirmButtonText: "确定",
  379. cancelButtonText: "取消",
  380. type: "warning"
  381. })
  382. .then(() => {
  383. return removeShip(this.ids);
  384. })
  385. .then(() => {
  386. this.onLoadShip(this.page);
  387. this.$message({
  388. type: "success",
  389. message: "操作成功!"
  390. });
  391. this.$refs.crudShip.toggleSelection();
  392. });
  393. },
  394. beforeOpenShip(done, type) {
  395. if (type == 'add'){
  396. this.optionShip.addTitle = "新增【" + this.yardName + "】";
  397. }
  398. if (type == 'edit'){
  399. this.optionShip.editTitle = "编辑【" + this.yardName + "】";
  400. }
  401. if (["edit", "view"].includes(type)) {
  402. getDetailShip(this.formShip.id).then(res => {
  403. this.formShip = res.data.data;
  404. });
  405. }
  406. done();
  407. },
  408. searchResetShip() {
  409. this.queryShip = {};
  410. this.onLoadShip(this.pageShip);
  411. },
  412. searchChangeShip(params, done) {
  413. this.queryShip = params;
  414. this.pageShip.currentPage = 1;
  415. this.onLoadShip(this.pageShip, params);
  416. done();
  417. },
  418. selectionChangeShip(list) {
  419. this.selectionListShip = list;
  420. },
  421. selectionClearShip() {
  422. this.selectionListShip = [];
  423. this.$refs.crudShip.toggleSelection();
  424. },
  425. currentChangeShip(currentPage){
  426. this.pageShip.currentPage = currentPage;
  427. },
  428. sizeChangeShip(pageSize){
  429. this.pageShip.pageSize = pageSize;
  430. },
  431. refreshChangeShip() {
  432. this.onLoadShip(this.pageShip, this.queryShip);
  433. },
  434. onLoadShip(page, params = {}) {
  435. this.loadingShip = true;
  436. params.yardId = this.yardId;
  437. getListShip(page.currentPage, page.pageSize, Object.assign(params, this.queryShip)).then(res => {
  438. const data = res.data.data;
  439. this.pageShip.total = data.total;
  440. this.dataShip = data.records;
  441. this.loadingShip = false;
  442. this.selectionClearShip();
  443. });
  444. }
  445. }
  446. };
  447. </script>
  448. <style>
  449. </style>