cargoList.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <div class="full-container-p24">
  3. <div class="df aic jcsb">
  4. <div class="df aic">
  5. <el-input
  6. placeholder="请输入货种/货主公司"
  7. prefix-icon="el-icon-search"
  8. v-model="term"
  9. clearable
  10. @clear="getCargoList(1)"
  11. style="height: 32px; width: 330px; line-height: 32px"
  12. ></el-input>
  13. <el-button
  14. @click="getCargoList(1)"
  15. type="primary"
  16. style="margin-left: 10px"
  17. >
  18. 查询
  19. </el-button>
  20. </div>
  21. <el-button type="primary" @click="bindModel = true">新增货种</el-button>
  22. </div>
  23. <div style="margin-top: 24px">
  24. <el-table :data="tableData" stripe style="width: 100%" border>
  25. <el-table-column
  26. type="index"
  27. label="序号"
  28. width="120"
  29. align="center"
  30. ></el-table-column>
  31. <el-table-column
  32. prop="cargoName"
  33. label="货种名称"
  34. min-width="120"
  35. align="center"
  36. ></el-table-column>
  37. <el-table-column label="操作" align="center">
  38. <template v-slot="scope">
  39. <el-button
  40. @click="checkCargoOwner(scope.row)"
  41. link
  42. type="primary"
  43. size="small"
  44. >
  45. 查看货主公司
  46. </el-button>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. <div style="width: 100%; text-align: right; margin-top: 43px">
  51. <el-pagination
  52. background
  53. layout="prev, pager, next"
  54. :current-page="currentPage"
  55. :total="total"
  56. @current-change="pageChange"
  57. ></el-pagination>
  58. </div>
  59. </div>
  60. <el-dialog v-model="cargoOwnerModelVisible" style="width: 800px">
  61. <template #header="{ close, titleId, titleClass }">
  62. <div class="df jcsb" style="color: #409eff">
  63. <div>{{ currentCargo + " - 货主公司列表" }}</div>
  64. <el-button
  65. type="primary"
  66. @click="(bindModel = true), (ruleForm.cargoName = currentCargo)"
  67. >
  68. 新增绑定货主公司
  69. </el-button>
  70. </div>
  71. </template>
  72. <el-table :data="cargoOwnerInfos" border>
  73. <el-table-column
  74. type="index"
  75. label="序号"
  76. width="60"
  77. align="center"
  78. ></el-table-column>
  79. <el-table-column
  80. prop="cargoOwnerName"
  81. label="货主公司名称"
  82. min-width="120"
  83. align="center"
  84. ></el-table-column>
  85. <el-table-column
  86. prop="create_time"
  87. label="创建时间"
  88. width="180"
  89. align="center"
  90. ></el-table-column>
  91. <el-table-column label="启用/禁用" width="160" align="center">
  92. <template v-slot="scope">
  93. <el-switch
  94. v-model="scope.row.status"
  95. active-color="#13ce66"
  96. inactive-color="#ff4949"
  97. active-text="启用"
  98. inactive-text="禁用"
  99. :active-value="1"
  100. :inactive-value="0"
  101. @change="enableDisableCargoOwnerCompany($event, scope.row)"
  102. >
  103. >
  104. </el-switch>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. </el-dialog>
  109. <el-dialog
  110. v-model="bindModel"
  111. :title="
  112. cargoOwnerModelVisible
  113. ? currentCargo + ' - 新增绑定货主公司'
  114. : '新增货种'
  115. "
  116. @close="
  117. ruleForm = {
  118. cargoName: '',
  119. cargoOwnerIds: [],
  120. }
  121. "
  122. >
  123. <el-form
  124. ref="ruleFormRef"
  125. :model="ruleForm"
  126. :rules="rules"
  127. label-width="120px"
  128. >
  129. <el-form-item label="货种名称" prop="cargoName">
  130. <el-input
  131. v-model="ruleForm.cargoName"
  132. :disabled="cargoOwnerModelVisible"
  133. ></el-input>
  134. </el-form-item>
  135. <el-form-item label="货主公司(多选)" prop="cargoOwnerIds">
  136. <el-select
  137. v-model="ruleForm.cargoOwnerIds"
  138. multiple
  139. style="width: 400px"
  140. >
  141. <el-option
  142. v-for="(item, index) in cargoOwnerModelVisible
  143. ? filterCargoOwnerOptions
  144. : cargoOwnerOptions"
  145. :key="index"
  146. :label="item.value"
  147. :value="item.key"
  148. ></el-option>
  149. </el-select>
  150. </el-form-item>
  151. </el-form>
  152. <div class="df aic jcfe mt30 mr30">
  153. <el-button type="default" @click="bindModel = false">取消</el-button>
  154. <el-button type="primary" @click="submit()">确认</el-button>
  155. </div>
  156. </el-dialog>
  157. </div>
  158. </template>
  159. <script setup>
  160. import { ref, h, reactive, toRefs, onMounted, computed } from "vue";
  161. import { ElNotification, ElMessageBox, ElMessage } from "element-plus";
  162. import store from "../../store";
  163. import router from "../../router";
  164. import md5 from "md5";
  165. import api from "../../apis/fetch";
  166. let currentPage = ref(1);
  167. let term = ref("");
  168. let tableData = ref([]);
  169. let total = ref(0);
  170. async function getCargoList(page) {
  171. currentPage.value = page || currentPage.value;
  172. let res = await api.getCargoList({
  173. currentPage: currentPage.value,
  174. size: 10,
  175. term: term.value,
  176. });
  177. if (res.data.status == 0) {
  178. tableData.value = res.data.result;
  179. total.value = res.data.total;
  180. } else {
  181. tableData.value = [];
  182. total.value = 0;
  183. }
  184. }
  185. async function cargoDetail(cargoName) {
  186. console.log(cargoName);
  187. }
  188. function pageChange(e) {
  189. currentPage.value = e;
  190. getCargoList();
  191. }
  192. const cargoOwnerInfos = ref([]);
  193. const cargoOwnerModelVisible = ref(false);
  194. const currentCargo = ref("");
  195. function checkCargoOwner(row) {
  196. cargoOwnerModelVisible.value = true;
  197. currentCargo.value = row.cargoName;
  198. cargoOwnerInfos.value = row.cargoOwnerInfos;
  199. }
  200. async function enableDisableCargoOwnerCompany(status, row) {
  201. let { data } = await api.enableDisableCargoOwnerCompany({
  202. cargoId: row.cargoId,
  203. status,
  204. });
  205. if (data.status == 0) {
  206. ElMessage({
  207. message: data.msg,
  208. type: "success",
  209. });
  210. } else {
  211. ElMessage({
  212. message: data.msg,
  213. type: "error",
  214. });
  215. row.status = status === 1 ? 0 : 1;
  216. }
  217. }
  218. const bindModel = ref(false);
  219. const cargoOwnerOptions = ref([]);
  220. const filterCargoOwnerOptions = computed(() => {
  221. return cargoOwnerOptions.value.filter(
  222. (item) =>
  223. !cargoOwnerInfos.value.some((obj) => obj.cargoOwnerName === item.value)
  224. );
  225. });
  226. async function getCargoOwnerCompanySelect() {
  227. let { data } = await api.getCargoOwnerCompanySelect({});
  228. cargoOwnerOptions.value = data.result;
  229. }
  230. const ruleFormRef = ref(null);
  231. const ruleForm = ref({
  232. cargoName: "",
  233. cargoOwnerIds: [],
  234. });
  235. const rules = ref({
  236. cargoName: [{ required: true, message: "请输入货种名称", trigger: "blur" }],
  237. cargoOwnerIds: [
  238. { required: true, message: "请选择货主公司", trigger: "blur" },
  239. ],
  240. });
  241. function cancel() {}
  242. function submit() {
  243. ruleFormRef.value.validate(async (valid) => {
  244. if (valid) {
  245. let { data } = await api[
  246. cargoOwnerModelVisible.value ? "bindCargoOwnerCompany" : "addCargo"
  247. ]({
  248. cargoName: ruleForm.value.cargoName,
  249. cargoOwnerIds: ruleForm.value.cargoOwnerIds.join(","),
  250. });
  251. if (data.status == 0) {
  252. ElNotification({
  253. message: data.msg,
  254. type: "success",
  255. });
  256. bindModel.value = false;
  257. cargoOwnerModelVisible.value = false;
  258. } else {
  259. ElMessage({
  260. message: data.msg,
  261. type: "error",
  262. });
  263. }
  264. getCargoList();
  265. }
  266. });
  267. }
  268. onMounted(() => {
  269. getCargoList();
  270. getCargoOwnerCompanySelect();
  271. });
  272. </script>
  273. <style scoped>
  274. .seach-btn {
  275. display: inline-block;
  276. width: 60px;
  277. height: 38px;
  278. background: #0094fe;
  279. border-radius: 2px;
  280. font-size: 14px;
  281. font-family: PingFangSC-Regular, PingFang SC;
  282. font-weight: 400;
  283. color: #ffffff;
  284. text-align: center;
  285. line-height: 38px;
  286. margin-left: 10px;
  287. cursor: pointer;
  288. }
  289. .cargo-owner-add {
  290. width: 80px;
  291. height: 32px;
  292. border-radius: 2px;
  293. border: 1px solid #0094fe;
  294. font-size: 14px;
  295. font-family: PingFangSC-Regular, PingFang SC;
  296. font-weight: 400;
  297. color: #0094fe;
  298. line-height: 32px;
  299. text-align: center;
  300. cursor: pointer;
  301. }
  302. :deep().el-dialog {
  303. width: 560px;
  304. padding: 20px 50px;
  305. border-radius: 6px;
  306. }
  307. :deep() .el-dialog__title {
  308. font-size: 18px;
  309. font-family: PingFangSC-Regular, PingFang SC;
  310. font-weight: 400;
  311. color: #0094fe;
  312. }
  313. </style>