index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="airportInfo scroll-y">
  3. <div class="wrap">
  4. <Minheader
  5. :is-auth="true"
  6. :is-statuser="true"
  7. powerData="new_airport_companies_button"
  8. @addForm="addForm"
  9. >
  10. <template #header>
  11. <div class="status flex-wrap">
  12. <div class="manageTitle">机场公司维护</div>
  13. </div>
  14. </template></Minheader
  15. >
  16. <div class="app-containers">
  17. <DataTable
  18. :tableHeader="tableCols"
  19. :tableData="tableData"
  20. :tableBtnGroup="tableBtnGroup"
  21. :tableProperty="{ rowKey: 'ID' }"
  22. @btnClick="btnClick"
  23. />
  24. </div>
  25. <Dialog
  26. :flag="flag"
  27. :type="type"
  28. :msgTitle="msgTitle"
  29. :delName="tableForm.companyName"
  30. @resetForm="resetForm"
  31. @delRest="delRest"
  32. @submitForm="submitForm"
  33. @delRemove="delRemove"
  34. >
  35. <div class="diacont">
  36. <el-form
  37. :model="tableForm"
  38. :rules="formRules"
  39. ref="airportCompanyForm"
  40. >
  41. <el-row :gutter="24">
  42. <el-col>
  43. <el-form-item
  44. label="公司名称"
  45. size="default"
  46. :rules="formRules.isNotNull"
  47. prop="companyName"
  48. >
  49. <el-input
  50. v-model="tableForm.companyName"
  51. placeholder="请输入公司名称"
  52. />
  53. </el-form-item>
  54. </el-col>
  55. <el-col>
  56. <el-form-item label="上级公司" size="default">
  57. <el-select
  58. style="width: 100%"
  59. v-model="tableForm.parentID"
  60. class="input-shadow"
  61. filterable
  62. default-first-option
  63. clearable
  64. placeholder="请选择"
  65. >
  66. <el-option
  67. v-for="item in tableOptionser"
  68. :key="item.v"
  69. :label="item.k"
  70. :value="item.v"
  71. >
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. </el-col>
  76. <el-col>
  77. <el-form-item label="公司描述" size="default">
  78. <el-input
  79. type="textarea"
  80. v-model="tableForm.companyDesc"
  81. placeholder="请输入公司描述"
  82. />
  83. </el-form-item>
  84. </el-col>
  85. </el-row>
  86. </el-form>
  87. </div>
  88. </Dialog>
  89. </div>
  90. </div>
  91. </template>
  92. <script setup lang="ts">
  93. import DataTable from "@/components/tableTemp/index.vue";
  94. import Minheader from "@/components/minheader/index.vue";
  95. import Dialog from "@/components/dialog/index.vue";
  96. import { Query, GeneralDataReception } from "@/api/webApi";
  97. import * as _ from "lodash";
  98. import { ElMessage } from "element-plus";
  99. const power = ref<String>("new_airlines_button"); //权限
  100. const formRules = useElement().formRules;
  101. const page = ref<number>(0); //分页参数
  102. const dataContent = ref<object>({});
  103. const noMore = ref<Boolean>(false);
  104. const asShow = ref<Boolean>(false);
  105. const rowTitle = ref<String>("");
  106. const tableCols = ref([]); //表头数据
  107. const serviceId = ref<String>("");
  108. const tableObj = ref({}); //增删改数据缓存
  109. const flag = ref<Boolean>(false); //弹窗开关
  110. const type = ref<String>(""); //判断是否删除
  111. const msgTitle = ref<String>("新增机场公司维护"); //弹窗标题
  112. const tableOptionser = ref([]); //弹窗下拉
  113. const tableOptionCopys = ref([]); //弹窗下拉
  114. const tableColsCopys = reactive([]); //弹窗
  115. const tableForm = reactive({
  116. companyName: "",
  117. parentID: "",
  118. companyDesc: "",
  119. companyID: "",
  120. event: "",
  121. }); //弹窗内容
  122. const tableBtnGroup = ref([
  123. {
  124. name: "编辑",
  125. className: "editBtn",
  126. param: 2,
  127. is: "airport_company_editor_button",
  128. },
  129. {
  130. name: "删除",
  131. className: "delBtn",
  132. param: 3,
  133. is: "airport_company_deletion_button",
  134. },
  135. ]);
  136. //列表
  137. const tableData = ref([]);
  138. //表头
  139. const state = reactive({
  140. list: [
  141. { label: "公司名称", key: "name" },
  142. { label: "公司描述", key: "china" },
  143. { label: "上级公司", key: "englin" },
  144. ],
  145. listLoading: true,
  146. });
  147. //新增
  148. const addForm = () => {
  149. msgTitle.value = "新增机场公司维护";
  150. flag.value = true;
  151. type.value = "";
  152. tableForm.event = 1;
  153. asShow.value = false;
  154. asShow.value = true;
  155. };
  156. //取消
  157. const resetForm = () => {
  158. flag.value = false;
  159. tableForm.companyName = "";
  160. tableForm.parentID = "";
  161. tableForm.companyDesc = "";
  162. tableForm.companyID = "";
  163. };
  164. //编辑-删除
  165. const btnClick = (row, index, param) => {
  166. if (param === 2) {
  167. msgTitle.value = "编辑机场公司维护";
  168. flag.value = true;
  169. type.value = "";
  170. tableForm.event = 2;
  171. tableForm.companyName = index.companyName;
  172. tableForm.parentID = index.parentID;
  173. tableForm.companyDesc = index.companyDesc;
  174. tableForm.companyID = index.companyID;
  175. tableOptionser.value = [];
  176. tableOptionCopys.value.forEach((element) => {
  177. if (element.k !== index.companyName) {
  178. tableOptionser.value.push(element);
  179. }
  180. });
  181. console.log(tableOptionser);
  182. } else if (param === 3) {
  183. msgTitle.value = "删除机场公司维护";
  184. flag.value = true;
  185. type.value = "del";
  186. tableForm.event = 3;
  187. tableForm.companyName = index.companyName;
  188. tableForm.parentID = index.parentID;
  189. tableForm.companyDesc = index.companyDesc;
  190. tableForm.companyID = index.companyID;
  191. } else if (param === 4) {
  192. }
  193. };
  194. //删除
  195. const delRest = () => {
  196. flag.value = false;
  197. };
  198. //获取弹框-下拉数据
  199. const getSelectData = async (id, name) => {
  200. const { code, returnData } = await Query({
  201. id,
  202. dataContent: name ? [name] : name === null ? [null] : [],
  203. });
  204. if (code == 0) {
  205. tableOptionser.value = returnData.listValues;
  206. tableOptionCopys.value = _.cloneDeep(returnData.listValues);
  207. } else {
  208. tableOptionser.value = [];
  209. }
  210. };
  211. //获取表格数据
  212. const getQuery = async () => {
  213. try {
  214. const { code, returnData } = await Query({
  215. id: DATACONTENT_ID.airportTreeId,
  216. needPage: ++page.value,
  217. dataContent: Object.values(dataContent.value),
  218. });
  219. if (code === "0") {
  220. if (returnData.listValues.length === 0) {
  221. page.value--;
  222. noMore.value = true;
  223. }
  224. const titleColumn = returnData.columnSet.find(
  225. (item) => item.needShow === 1
  226. );
  227. if (titleColumn) {
  228. rowTitle.value = titleColumn.columnName;
  229. }
  230. tableData.value.push(...returnData.listValues);
  231. tableCols.value = returnData.columnSet;
  232. returnData.columnSet.forEach((item) => {
  233. if (item.listqueryTemplateID && item.columnName === "parentID") {
  234. getSelectData(item.listqueryTemplateID);
  235. }
  236. });
  237. tableCols.value.forEach((element) => {
  238. element.label = element.columnLabel;
  239. element.key = element.columnName;
  240. });
  241. serviceId.value = returnData.submitID;
  242. } else {
  243. page.value--;
  244. }
  245. } catch (error) {
  246. page.value--;
  247. }
  248. };
  249. const changeSelect = (data, name) => {
  250. if (tableForm[data].value === "") {
  251. tableForm[data].value = null;
  252. }
  253. };
  254. const resetTable = () => {
  255. page.value = 0;
  256. noMore.value = false;
  257. tableData.value = [];
  258. };
  259. //新增-编辑-删除
  260. const generalDataReception = async (data) => {
  261. try {
  262. data = {
  263. ...data,
  264. };
  265. const { code } = await GeneralDataReception({
  266. serviceId: serviceId.value,
  267. dataContent: JSON.stringify(data),
  268. });
  269. if (code == 0) {
  270. ElMessage.success(`操作成功`);
  271. // this.$message.success("操作成功");
  272. resetTable();
  273. getQuery();
  274. resetForm();
  275. flag.value = false;
  276. // rmFlag.value = false;
  277. tableObj.value = {};
  278. // this.$router.go(0);
  279. } else {
  280. ElMessage.error(`操作失败`);
  281. // this.$message.error("操作失败");
  282. // this.flag = false;
  283. // this.rmFlag = false;
  284. tableObj.value = {};
  285. resetForm();
  286. }
  287. } catch (error) {
  288. flag.value = false;
  289. // rmFlag.value = false;
  290. tableObj.value = {};
  291. resetForm();
  292. }
  293. };
  294. //确认提交
  295. const airportCompanyForm: any = ref(null);
  296. const submitForm = () => {
  297. airportCompanyForm.value.validate((valid: any) => {
  298. if (valid) {
  299. generalDataReception(tableForm);
  300. } else {
  301. return false;
  302. }
  303. });
  304. };
  305. const delRemove = () => {
  306. tableForm.event = 3;
  307. generalDataReception(tableForm);
  308. };
  309. getQuery();
  310. </script>
  311. <style lang="scss" scoped>
  312. ::v-deep .el-form-item__label {
  313. width: 100px;
  314. }
  315. </style>