index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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="80%"
  32. append-to-body
  33. @closed="closed"
  34. v-dialog-drag
  35. >
  36. <span>
  37. <el-row>
  38. <el-col :span="4">
  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="20">
  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. getAllList
  98. } from "@/api/basicData/portinformation";
  99. export default {
  100. data() {
  101. return {
  102. switchDialog: false, //报表
  103. loading: true,
  104. data: [],
  105. tableOption: option,
  106. form: {},
  107. search: {},
  108. treeDeptId: "",
  109. treeDeptName: "",
  110. page: {
  111. currentPage: 1,
  112. total: 0,
  113. pageSize: 10
  114. },
  115. treeOption: {
  116. nodeKey: "id",
  117. lazy: true,
  118. treeLoad: function(node, resolve) {
  119. const parentId = node.level === 0 ? 0 : node.data.id;
  120. getPortTypeTree(parentId).then(res => {
  121. resolve(
  122. res.data.map(item => {
  123. return {
  124. ...item,
  125. leaf: !item.hasChildren
  126. };
  127. })
  128. );
  129. });
  130. },
  131. addBtn: false,
  132. menu: false,
  133. size: "small",
  134. props: {
  135. labelText: "标题",
  136. label: "name",
  137. value: "id",
  138. children: "children"
  139. }
  140. },
  141. portinfoVisible: false,
  142. selectionList: [],
  143. portList: []
  144. };
  145. },
  146. props: {
  147. value: String,
  148. disabled: Boolean
  149. },
  150. model: {
  151. prop: "value",
  152. event: "balabala"
  153. },
  154. created() {
  155. getAllList().then(res => {
  156. this.portList = res.data.data;
  157. });
  158. },
  159. components: {
  160. reportDialog
  161. },
  162. mounted() {
  163. //查询服务类别字典项
  164. getTypeTree().then(res => {
  165. this.findObject(this.tableOption.column, "typeId").dicData =
  166. res.data.data;
  167. });
  168. },
  169. methods: {
  170. closed() {
  171. this.$refs.crud.toggleSelection();
  172. },
  173. importPort() {
  174. this.$emit("balabala", this.selectionList[0].name);
  175. this.portinfoVisible = false;
  176. },
  177. //打印
  178. openReport() {
  179. this.switchDialog = !this.switchDialog;
  180. },
  181. //关闭打印
  182. onClose(val) {
  183. this.switchDialog = val;
  184. },
  185. getList(page, params = {}) {
  186. this.loading = true;
  187. getList(page.currentPage, page.pageSize, params, this.treeDeptId).then(
  188. res => {
  189. this.data = res.data.data.records;
  190. this.page.total = res.data.data.total;
  191. this.loading = false;
  192. if (this.page.total) {
  193. this.tableOption.height = window.innerHeight - 350;
  194. }
  195. }
  196. );
  197. },
  198. //点击新增打开的窗口 取消时触发
  199. // beforeClose(){
  200. // },
  201. selectionChange(list) {
  202. this.selectionList = list;
  203. },
  204. //点击新增或修改时
  205. beforeOpen(done, type) {
  206. if (["add"].includes(type)) {
  207. this.tableOption.column.forEach(e => {
  208. if (e.prop == "typeId") {
  209. this.$set(this.tableOption.column, 3, {
  210. ...e,
  211. value: this.treeDeptId
  212. });
  213. }
  214. });
  215. }
  216. done();
  217. },
  218. searchChange(params, done) {
  219. this.getList(this.page, params);
  220. done();
  221. },
  222. sizeChange(val) {
  223. this.page.pageSize = val;
  224. this.getList();
  225. },
  226. currentChange(val) {
  227. this.page.currentPage = val;
  228. this.getList(this.page);
  229. },
  230. refreshChange() {
  231. this.getList(this.page, this.search);
  232. },
  233. rowSave(row, done, loading) {
  234. add(row).then(
  235. () => {
  236. this.page.currentPage = 1;
  237. this.getList(this.page);
  238. this.$message.success("保存成功");
  239. done();
  240. },
  241. error => {
  242. window.console.log(error);
  243. loading();
  244. }
  245. );
  246. },
  247. rowUpdate(row, index, done, loading) {
  248. row.createTime = "";
  249. update(row).then(
  250. () => {
  251. this.getList(this.page);
  252. this.$message({
  253. type: "success",
  254. message: "操作成功!"
  255. });
  256. // 数据回调进行刷新
  257. done(row);
  258. },
  259. error => {
  260. window.console.log(error);
  261. loading();
  262. }
  263. );
  264. },
  265. rowDel(row, index, done) {
  266. this.$confirm("确定将选择数据删除?", {
  267. confirmButtonText: "确定",
  268. cancelButtonText: "取消",
  269. type: "warning"
  270. })
  271. .then(() => {
  272. return remove(row.id);
  273. })
  274. .then(() => {
  275. this.$message({
  276. type: "success",
  277. message: "操作成功!"
  278. });
  279. this.getList(this.page);
  280. done(row);
  281. });
  282. },
  283. cellDblclick(row, column, cell, event) {
  284. this.$refs.crud.rowEdit(row);
  285. },
  286. saveColumn(row, column) {
  287. console.log(row, column);
  288. },
  289. //展开主页左边类型
  290. nodeClick(data) {
  291. this.treeDeptName = data.cname;
  292. this.treeDeptId = data.id;
  293. this.page.currentPage = 1;
  294. this.getList(this.page);
  295. },
  296. //列表内展开树节点
  297. treeLoad(tree, treeNode, resolve) {
  298. const parentId = tree.id;
  299. getList({ parentId: parentId }).then(res => {
  300. resolve(res.data.data.records);
  301. });
  302. }
  303. }
  304. };
  305. </script>
  306. <style scoped lang="scss"></style>