Przeglądaj źródła

更新 添加货种

wzh 3 lat temu
rodzic
commit
48346b7973
4 zmienionych plików z 172 dodań i 47 usunięć
  1. 4 1
      src/apis/config.js
  2. 30 10
      src/apis/fetch.js
  3. 3 0
      src/main.js
  4. 135 36
      src/views/cargoManage/cargoList.vue

+ 4 - 1
src/apis/config.js

@@ -16,7 +16,10 @@ export const $http = function (url, data) {
   return axios({
     method: data ? "post" : "get",
     url: baseurl + url,
-    data,
+    data: {
+      ...data,
+      loginAccountId: localStorage.loginAccountId,
+    },
     withCredentials: true,
   });
 };

+ 30 - 10
src/apis/fetch.js

@@ -73,16 +73,6 @@ export default {
     return $http("/role/permission/updateRole", data);
   },
 
-  // 添加货种
-  addCargo(data) {
-    return $http("/cargo/add", data);
-  },
-
-  // 货种列表
-  getCargoList(data) {
-    return $http("/cargo/list", data);
-  },
-
   // 获取代理列表
   getAgencyList(data) {
     return $http("/user/cargo/proxy/list", data);
@@ -181,4 +171,34 @@ export default {
   getCargoSelect(data) {
     return $http("/cargo/select", data);
   },
+
+  // 启用/禁用货种
+  updateCargoStatus(data) {
+    return $http("/cargo/active", data);
+  },
+
+  // 添加货种
+  addCargo(data) {
+    return $http("/cargo/add", data);
+  },
+
+  // 货种列表
+  getCargoList(data) {
+    return $http("/cargo/list", data);
+  },
+
+  // 获取 代理公司select
+  getAgencySelect(data) {
+    return $http("/cargo/proxy/select", data);
+  },
+
+  // 获取 已选择代理公司select
+  getAgencySelected(data) {
+    return $http("/cargo/proxy/selected", data);
+  },
+
+  // 更新 货种
+  updateCargo(data) {
+    return $http("/cargo/update", data);
+  },
 };

+ 3 - 0
src/main.js

@@ -10,8 +10,11 @@ import "./styles/index.css";
 import Uploader from "./components/Uploader.vue";
 import Certs from "./components/Certs.vue";
 import RemoteSearch from "./components/RemoteSearch.vue";
+import RemoteSelect from "./components/RemoteSelect.vue";
 
 const app = createApp(App);
+app.component("RemoteSelect", RemoteSelect);
+
 app.component("RemoteSearch", RemoteSearch);
 app.component("Certs", Certs);
 app.component("Uploader", Uploader);

+ 135 - 36
src/views/cargoManage/cargoList.vue

@@ -12,11 +12,53 @@
         ></el-input>
         <div class="seach-btn" @click="getCargoList">查询</div>
       </div>
-      <el-button v-auth="'ADDCARGO'" type="primary" @click="addCargo">
+      <el-button v-auth="'ADDCARGO'" type="primary" @click="visable = true">
         添加货种
       </el-button>
     </div>
-
+    <el-dialog
+      v-model="visable"
+      :title="currentCargoId ? '修改货种' : '添加货种'"
+      width="550px"
+      @close="resetForm()"
+    >
+      <template v-slot:default>
+        <div class="df jcc">
+          <el-form
+            :model="ruleForm"
+            :rules="rules"
+            ref="form"
+            label-width="110px"
+            label-position="left"
+          >
+            <el-form-item prop="cargo" label="货种名称">
+              <el-input
+                style="width: 200px"
+                v-model="ruleForm.cargo"
+                placeholder="请填写货种名称"
+              ></el-input>
+            </el-form-item>
+            <el-form-item prop="proxyIds" label="启用代理">
+              <RemoteSelect
+                api="getAgencySelect"
+                v-model="ruleForm.proxyIds"
+                multiple
+                @selectItem="selectAgency($event)"
+                class="mb10"
+              ></RemoteSelect>
+            </el-form-item>
+          </el-form>
+        </div>
+      </template>
+      <template v-slot:footer>
+        <div class="dialog-footer">
+          <el-button @click="resetForm">取 消</el-button>
+          <el-button type="primary" @click="addCargo(ruleForm)">
+            确 定
+          </el-button>
+        </div>
+      </template>
+    </el-dialog>
     <div style="margin-top: 24px">
       <el-table :data="tableData" stripe style="width: 100%">
         <el-table-column
@@ -41,8 +83,21 @@
             {{ subTimeStr(scope.row.createTime) }}
           </template>
         </el-table-column>
+        <el-table-column label="启用/禁用" min-width="80" align="center">
+          <template v-slot="scope">
+            <el-switch v-model="scope.disabled"></el-switch>
+          </template>
+        </el-table-column>
         <el-table-column label="操作" min-width="80" align="center">
-          <el-button disabled size="small" type="danger">删除</el-button>
+          <template v-slot="scope">
+            <el-button
+              size="small"
+              @click="showUpdate(scope.row)"
+              type="primary"
+            >
+              修改
+            </el-button>
+          </template>
         </el-table-column>
       </el-table>
       <div style="width: 100%; text-align: right; margin-top: 43px">
@@ -68,7 +123,36 @@ let currentPage = ref(1);
 let total = ref(0);
 let term = ref("");
 let loginAccountId = ref(0);
-let cargo = ref("");
+let currentCargoId = ref(0);
+let form = ref(null);
+let visable = ref(false);
+let ruleForm = ref({
+  cargo: "",
+  proxyIds: "",
+});
+function resetForm() {
+  visable.value = false;
+  form.value.resetFields();
+}
+const rules = ref({
+  cargo: [
+    {
+      required: true,
+      message: "请填写货种",
+      trigger: "blur",
+    },
+  ],
+  proxyIds: [
+    {
+      required: true,
+      message: "请选择代理",
+      trigger: "blur",
+    },
+  ],
+});
+function selectAgency(e) {
+  console.log(e);
+}
 
 async function getCargoList() {
   let res = await api.getCargoList({
@@ -90,40 +174,55 @@ function pageChange(e) {
   currentPage.value = e;
   getCargoList();
 }
-function addCargo() {
-  ElMessageBox.prompt("请输入货种名称", "添加货种", {
-    confirmButtonText: "添加",
-    cancelButtonText: "取消",
-    inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
-    inputErrorMessage: "请输入货种名称",
-  })
-    .then(async ({ value }) => {
-      let res = await api.addCargo({
-        loginAccountId: loginAccountId.value,
-        cargo: value,
-      });
-      if (res.data.status == 0) {
-        ElNotification({
-          title: "成功",
-          duration: 1500,
-          message: res.data.msg,
-          type: "success",
-        });
-        getCargoList();
-      } else {
-        ElNotification({
-          title: "失败",
-          duration: 1500,
-          message: res.data.msg,
-          type: "error",
-        });
-      }
-    })
-    .catch(() => {});
+async function addCargo() {
+  console.log(ruleForm.value);
+  let { cargo, proxyIds } = ruleForm.value;
+  let arr = [];
+  for (let i of proxyIds) {
+    arr.push(i.value);
+  }
+  let res = await api.addCargo({
+    cargo,
+    proxyIds: arr.join(","),
+  });
+  if (res.data.status == 0) {
+    ElNotification({
+      title: "成功",
+      duration: 1500,
+      message: res.data.msg,
+      type: "success",
+    });
+    resetForm();
+    getCargoList();
+  } else {
+    ElNotification({
+      title: "失败",
+      duration: 1500,
+      message: res.data.msg,
+      type: "error",
+    });
+  }
 }
 
-function closeModal() {
-  cargo.value = "";
+async function showUpdate(item) {
+  console.log(item);
+  visable.value = true;
+  let { id: cargoId } = item;
+  currentCargoId.value = cargoId;
+  ruleForm.value = {
+    proxyIds: [],
+  };
+  let res = await api.getAgencySelected({
+    cargoId,
+  });
+  ruleForm.value.proxyIds = [];
+  for (let i of res.data.result) {
+    ruleForm.value.proxyIds.push({
+      value: i.proxyName,
+      key: i.proxyId,
+    });
+  }
+  console.log(res);
 }
 
 onMounted(() => {