index.vue 7.5 KB

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