index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div>
  3. <div style="display:flex">
  4. <el-select
  5. v-model="value"
  6. placeholder="请选择"
  7. :disabled="disabled"
  8. @input="$emit('balabala', value)"
  9. filterable
  10. clearable
  11. >
  12. <el-option
  13. v-for="item in portList"
  14. :key="item.id"
  15. :label="item.name"
  16. :value="item.name"
  17. >
  18. </el-option>
  19. </el-select>
  20. <el-button
  21. icon="el-icon-search"
  22. @click="portinfoVisible = true"
  23. :disabled="disabled"
  24. size="mini"
  25. ></el-button>
  26. </div>
  27. <el-dialog
  28. title="港口信息"
  29. top="5vh"
  30. :visible.sync="portinfoVisible"
  31. width="60%"
  32. append-to-body
  33. @closed="closed"
  34. v-dialog-drag
  35. >
  36. <span>
  37. <el-row>
  38. <el-col :span="5">
  39. <el-scrollbar>
  40. <basic-container>
  41. <avue-tree
  42. :option="treeOption"
  43. :data="treeData"
  44. @node-click="nodeClick"
  45. />
  46. </basic-container>
  47. </el-scrollbar>
  48. </el-col>
  49. <el-col :span="19">
  50. <avue-crud
  51. ref="crud"
  52. :data="data"
  53. :option="tableOption"
  54. :page.sync="page"
  55. :table-loading="loading"
  56. v-model="form"
  57. :search.sync="search"
  58. :before-open="beforeOpen"
  59. @size-change="sizeChange"
  60. @current-change="currentChange"
  61. @search-change="searchChange"
  62. @refresh-change="refreshChange"
  63. @row-save="rowSave"
  64. @row-del="rowDel"
  65. @row-update="rowUpdate"
  66. @on-load="getList"
  67. @saveColumn="saveColumn"
  68. @tree-load="treeLoad"
  69. @selection-change="selectionChange"
  70. >
  71. </avue-crud>
  72. </el-col>
  73. </el-row>
  74. </span>
  75. <span slot="footer" class="dialog-footer">
  76. <el-button @click="portinfoVisible = false">取 消</el-button>
  77. <el-button
  78. type="primary"
  79. @click="importPort"
  80. :disabled="selectionList.length != 1"
  81. >确 定</el-button
  82. >
  83. </span>
  84. </el-dialog>
  85. </div>
  86. </template>
  87. <script>
  88. import option from "./configuration/mainList.json";
  89. import reportDialog from "@/components/report-dialog/main";
  90. import {
  91. getList,
  92. add,
  93. update,
  94. remove,
  95. getPortTypeTree,
  96. getTypeTree
  97. } from "@/api/basicData/portinformation";
  98. export default {
  99. data() {
  100. return {
  101. switchDialog: false, //报表
  102. loading: true,
  103. data: [],
  104. tableOption: option,
  105. form: {},
  106. search: {},
  107. treeDeptId: "",
  108. treeDeptName: "",
  109. page: {
  110. currentPage: 1,
  111. total: 0,
  112. pageSize: 10
  113. },
  114. treeOption: {
  115. nodeKey: "id",
  116. lazy: true,
  117. treeLoad: function(node, resolve) {
  118. const parentId = node.level === 0 ? 0 : node.data.id;
  119. getPortTypeTree(parentId).then(res => {
  120. resolve(
  121. res.data.map(item => {
  122. return {
  123. ...item,
  124. leaf: !item.hasChildren
  125. };
  126. })
  127. );
  128. });
  129. },
  130. addBtn: false,
  131. menu: false,
  132. size: "small",
  133. props: {
  134. labelText: "标题",
  135. label: "name",
  136. value: "id",
  137. children: "children"
  138. }
  139. },
  140. portinfoVisible: false,
  141. selectionList: [],
  142. portList: []
  143. };
  144. },
  145. props: {
  146. value: String,
  147. disabled: Boolean
  148. },
  149. model: {
  150. prop: "value",
  151. event: "balabala"
  152. },
  153. created() {
  154. getList().then(res => {
  155. this.portList = res.data.data.records;
  156. });
  157. },
  158. components: {
  159. reportDialog
  160. },
  161. mounted() {
  162. //查询服务类别字典项
  163. getTypeTree().then(res => {
  164. this.findObject(this.tableOption.column, "typeId").dicData =
  165. res.data.data;
  166. });
  167. },
  168. methods: {
  169. closed() {
  170. this.$refs.crud.toggleSelection();
  171. },
  172. importPort() {
  173. this.$emit("balabala", this.selectionList[0].name);
  174. this.portinfoVisible = false;
  175. },
  176. //打印
  177. openReport() {
  178. this.switchDialog = !this.switchDialog;
  179. },
  180. //关闭打印
  181. onClose(val) {
  182. this.switchDialog = val;
  183. },
  184. getList(page, params = {}) {
  185. this.loading = true;
  186. getList(page.currentPage, page.pageSize, params, this.treeDeptId).then(
  187. res => {
  188. this.data = res.data.data.records;
  189. this.page.total = res.data.data.total;
  190. this.loading = false;
  191. if (this.page.total) {
  192. this.tableOption.height = window.innerHeight - 350;
  193. }
  194. }
  195. );
  196. },
  197. //点击新增打开的窗口 取消时触发
  198. // beforeClose(){
  199. // },
  200. selectionChange(list) {
  201. this.selectionList = list;
  202. },
  203. //点击新增或修改时
  204. beforeOpen(done, type) {
  205. if (["add"].includes(type)) {
  206. this.tableOption.column.forEach(e => {
  207. if (e.prop == "typeId") {
  208. this.$set(this.tableOption.column, 3, {
  209. ...e,
  210. value: this.treeDeptId
  211. });
  212. }
  213. });
  214. }
  215. done();
  216. },
  217. searchChange(params, done) {
  218. this.getList(this.page, params);
  219. done();
  220. },
  221. sizeChange(val) {
  222. this.page.pageSize = val;
  223. this.getList();
  224. },
  225. currentChange(val) {
  226. this.page.currentPage = val;
  227. this.getList();
  228. },
  229. refreshChange() {
  230. this.getList(this.page, this.search);
  231. },
  232. rowSave(row, done, loading) {
  233. add(row).then(
  234. () => {
  235. this.page.currentPage = 1;
  236. this.getList(this.page);
  237. this.$message.success("保存成功");
  238. done();
  239. },
  240. error => {
  241. window.console.log(error);
  242. loading();
  243. }
  244. );
  245. },
  246. rowUpdate(row, index, done, loading) {
  247. row.createTime = "";
  248. update(row).then(
  249. () => {
  250. this.getList(this.page);
  251. this.$message({
  252. type: "success",
  253. message: "操作成功!"
  254. });
  255. // 数据回调进行刷新
  256. done(row);
  257. },
  258. error => {
  259. window.console.log(error);
  260. loading();
  261. }
  262. );
  263. },
  264. rowDel(row, index, done) {
  265. this.$confirm("确定将选择数据删除?", {
  266. confirmButtonText: "确定",
  267. cancelButtonText: "取消",
  268. type: "warning"
  269. })
  270. .then(() => {
  271. return remove(row.id);
  272. })
  273. .then(() => {
  274. this.$message({
  275. type: "success",
  276. message: "操作成功!"
  277. });
  278. this.getList(this.page);
  279. done(row);
  280. });
  281. },
  282. cellDblclick(row, column, cell, event) {
  283. this.$refs.crud.rowEdit(row);
  284. },
  285. saveColumn(row, column) {
  286. console.log(row, column);
  287. },
  288. //展开主页左边类型
  289. nodeClick(data) {
  290. this.treeDeptName = data.cname;
  291. this.treeDeptId = data.id;
  292. this.page.currentPage = 1;
  293. this.getList(this.page);
  294. },
  295. //列表内展开树节点
  296. treeLoad(tree, treeNode, resolve) {
  297. const parentId = tree.id;
  298. getList({ parentId: parentId }).then(res => {
  299. resolve(res.data.data.records);
  300. });
  301. }
  302. }
  303. };
  304. </script>
  305. <style scoped lang="scss"></style>