cargoList.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.native="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. >添加货种</el-button
  17. >
  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. <template v-slot="scope">
  45. <div class="df aic jcsa">
  46. <!-- <el-switch
  47. v-model="scope.row.status"
  48. active-color="#13ce66"
  49. inactive-color="#ff4949"
  50. active-text="启用"
  51. inactive-text="禁用"
  52. :active-value="1"
  53. :inactive-value="0"
  54. /> -->
  55. <el-button disabled size="small" type="danger">删除</el-button>
  56. </div>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. <div style="width: 100%; text-align: right; margin-top: 43px">
  61. <el-pagination
  62. background
  63. layout="prev, pager, next"
  64. :total="total"
  65. @current-change="pageChange"
  66. ></el-pagination>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <script setup>
  72. import api from "../../apis/fetch";
  73. import { ref, onMounted } from "vue";
  74. import { ElNotification, ElMessageBox } from "element-plus";
  75. import { subTimeStr } from "../../utils/utils";
  76. let tableData = ref([]);
  77. let currentPage = ref(1);
  78. let total = ref(0);
  79. let term = ref("");
  80. let loginAccountId = ref(0);
  81. let cargo = ref("");
  82. async function getCargoList() {
  83. let res = await api.getCargoList({
  84. term: term.value,
  85. currentPage: currentPage.value,
  86. size: 10,
  87. loginAccountId: loginAccountId.value,
  88. });
  89. if (res.data.status == 0) {
  90. tableData.value = res.data.result;
  91. total.value = res.data.total;
  92. } else {
  93. tableData.value = [];
  94. total.value = 0;
  95. }
  96. }
  97. function pageChange(e) {
  98. currentPage.value = e;
  99. getCargoList();
  100. }
  101. function addCargo() {
  102. ElMessageBox.prompt("请输入货种名称", "添加货种", {
  103. confirmButtonText: "添加",
  104. cancelButtonText: "取消",
  105. inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
  106. inputErrorMessage: "请输入货种名称",
  107. })
  108. .then(async ({ value }) => {
  109. let res = await api.addCargo({
  110. loginAccountId: loginAccountId.value,
  111. cargo: value,
  112. });
  113. if (res.data.status == 0) {
  114. ElNotification({
  115. title: "成功",
  116. duration: 1500,
  117. message: res.data.msg,
  118. type: "success",
  119. });
  120. getCargoList();
  121. } else {
  122. ElNotification({
  123. title: "失败",
  124. duration: 1500,
  125. message: res.data.msg,
  126. type: "error",
  127. });
  128. }
  129. })
  130. .catch(() => {});
  131. }
  132. function closeModal() {
  133. cargo.value = "";
  134. }
  135. onMounted(() => {
  136. loginAccountId.value = localStorage.loginAccountId;
  137. getCargoList();
  138. });
  139. </script>
  140. <style scoped>
  141. .seach-btn {
  142. display: inline-block;
  143. width: 60px;
  144. height: 38px;
  145. background: #0094fe;
  146. border-radius: 2px;
  147. font-size: 14px;
  148. font-family: PingFangSC-Regular, PingFang SC;
  149. font-weight: 400;
  150. color: #ffffff;
  151. text-align: center;
  152. line-height: 38px;
  153. margin-left: 10px;
  154. cursor: pointer;
  155. }
  156. </style>