cargoList.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="full-container-p24">
  3. <div style="display: flex; justify-content: space-between">
  4. <div style="display: flex">
  5. <el-input
  6. placeholder="请输入货种名称"
  7. prefix-icon="el-icon-search"
  8. v-model="term"
  9. clearable
  10. style="height: 32px; width: 330px; line-height: 32px"
  11. @keyup.enter="getCargoList"
  12. ></el-input>
  13. <div class="seach-btn" @click="getCargoList">查询</div>
  14. </div>
  15. <el-button v-auth="'ADDCARGO'" type="primary" @click="addCargo">
  16. 添加货种
  17. </el-button>
  18. </div>
  19. <div style="margin-top: 24px">
  20. <el-table :data="tableData" stripe style="width: 100%">
  21. <el-table-column
  22. type="index"
  23. label="序号"
  24. min-width="80"
  25. align="center"
  26. ></el-table-column>
  27. <el-table-column
  28. prop="cargo"
  29. label="货种名称"
  30. min-width="120"
  31. align="center"
  32. ></el-table-column>
  33. <el-table-column
  34. prop="createTime"
  35. label="添加时间"
  36. min-width="160"
  37. align="center"
  38. >
  39. <template v-slot="scope">
  40. {{ subTimeStr(scope.row.createTime) }}
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="操作" min-width="80" align="center">
  44. <el-button disabled size="small" type="danger">删除</el-button>
  45. </el-table-column>
  46. </el-table>
  47. <div style="width: 100%; text-align: right; margin-top: 43px">
  48. <el-pagination
  49. background
  50. layout="prev, pager, next"
  51. :total="total"
  52. @current-change="pageChange"
  53. ></el-pagination>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script setup>
  59. import api from "../../apis/fetch";
  60. import { ref, onMounted } from "vue";
  61. import { ElNotification, ElMessageBox } from "element-plus";
  62. import { subTimeStr } from "../../utils/utils";
  63. let tableData = ref([]);
  64. let currentPage = ref(1);
  65. let total = ref(0);
  66. let term = ref("");
  67. let loginAccountId = ref(0);
  68. let cargo = ref("");
  69. async function getCargoList() {
  70. let res = await api.getCargoList({
  71. term: term.value,
  72. currentPage: currentPage.value,
  73. size: 10,
  74. loginAccountId: loginAccountId.value,
  75. });
  76. if (res.data.status == 0) {
  77. tableData.value = res.data.result;
  78. total.value = res.data.total;
  79. } else {
  80. tableData.value = [];
  81. total.value = 0;
  82. }
  83. }
  84. function pageChange(e) {
  85. currentPage.value = e;
  86. getCargoList();
  87. }
  88. function addCargo() {
  89. ElMessageBox.prompt("请输入货种名称", "添加货种", {
  90. confirmButtonText: "添加",
  91. cancelButtonText: "取消",
  92. inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
  93. inputErrorMessage: "请输入货种名称",
  94. })
  95. .then(async ({ value }) => {
  96. let res = await api.addCargo({
  97. loginAccountId: loginAccountId.value,
  98. cargo: value,
  99. });
  100. if (res.data.status == 0) {
  101. ElNotification({
  102. title: "成功",
  103. duration: 1500,
  104. message: res.data.msg,
  105. type: "success",
  106. });
  107. getCargoList();
  108. } else {
  109. ElNotification({
  110. title: "失败",
  111. duration: 1500,
  112. message: res.data.msg,
  113. type: "error",
  114. });
  115. }
  116. })
  117. .catch(() => {});
  118. }
  119. function closeModal() {
  120. cargo.value = "";
  121. }
  122. onMounted(() => {
  123. loginAccountId.value = localStorage.loginAccountId;
  124. getCargoList();
  125. });
  126. </script>
  127. <style scoped>
  128. .seach-btn {
  129. display: inline-block;
  130. width: 60px;
  131. height: 38px;
  132. background: #0094fe;
  133. border-radius: 2px;
  134. font-size: 14px;
  135. font-family: PingFangSC-Regular, PingFang SC;
  136. font-weight: 400;
  137. color: #ffffff;
  138. text-align: center;
  139. line-height: 38px;
  140. margin-left: 10px;
  141. cursor: pointer;
  142. }
  143. </style>