Forráskód Böngészése

用户绑定供应商

刘洋 1 éve
szülő
commit
dc58abe3f4

+ 12 - 0
src/api/user.js

@@ -163,3 +163,15 @@ export const getAttachmentListByKey = (key) =>
     url: '/api/admin/common/file/preview/app',
     params: { key },
   });
+//根据用户id查询可绑定的供应商列表options
+export const getSupplierByUser = (params) =>
+  request({
+    url: '/api/admin/user/query/supplier',
+    params,
+  });
+//用户绑定供应商
+export const userBindSupplier = (params) =>
+  request({
+    url: '/api/admin/user/band/supplier',
+    params,
+  });

+ 23 - 10
src/components/common/select-supplier/index.vue

@@ -29,7 +29,7 @@ const props = defineProps({
   modelValue: { type: [Number, String, Array], default: '' },
   type: { type: String, default: '' },
   typeRequired: { type: Boolean, default: false },
-  apiFunc: { type: Function, default: () => {} },
+  options: { type: [Array, null], default: null },
 });
 const isMultiple = computed(() => {
   const multiple = attrs.multiple;
@@ -37,17 +37,20 @@ const isMultiple = computed(() => {
 });
 
 const search = async () => {
-  if (props.typeRequired && !props.type) return;
+  if (props.options) {
+    optionList.value = props.options;
+  } else {
+    if (props.typeRequired && !props.type) return;
 
-  optionList.value = [];
-  let data = { enable: true };
-  if (props.type) data.type = props.type;
-  const res = props.apiFunc
-    ? await apiFunc().catch(() => {})
-    : await supplierListApi(data).catch(() => {});
-  if (!res) return;
+    optionList.value = [];
+    let data = { enable: true };
+    if (props.type) data.type = props.type;
+    const res = await supplierListApi(data).catch(() => {});
+    if (!res) return;
+
+    optionList.value = res;
+  }
 
-  optionList.value = res;
   emit('getOptions', optionList.value);
 };
 
@@ -84,4 +87,14 @@ watch(
     }
   }
 );
+watch(
+  () => props.options,
+  (val) => {
+    if (val) {
+      search();
+      emit('update:modelValue', null);
+      emit('change', isMultiple.value ? [] : null);
+    }
+  }
+);
 </script>

+ 18 - 15
src/views/user/auth-manage/user-manage/bind-supplier-dialog.vue

@@ -7,13 +7,13 @@
     @close="emit('update:visible', false)"
   >
     <t-form ref="formRef" :data="formData" :rules="rules" labelAlign="top">
-      <t-row :gutter="[20, 20]">
-        <t-col :span="12">
-          <t-form-item label="供应商" name="a">
-            <t-input v-model="formData.a"></t-input>
-          </t-form-item>
-        </t-col>
-      </t-row>
+      <t-form-item label="供应商:" name="id">
+        <!-- <t-input v-model="formData.id"></t-input> -->
+        <select-supplier
+          v-model="formData.id"
+          :options="options"
+        ></select-supplier>
+      </t-form-item>
     </t-form>
     <template #foot>
       <t-button theme="default" @click="emit('update:visible', false)"
@@ -26,19 +26,19 @@
 <script setup name="AddUserDialog">
 import useClearDialog from '@/hooks/useClearDialog';
 import { ref, computed } from 'vue';
+import { userBindSupplier } from '@/api/user';
 
 const props = defineProps({
   visible: Boolean,
   curRow: Object,
+  options: Array,
 });
 const emit = defineEmits(['close', 'success']);
 const formRef = ref(null);
-const getDetail = async () => {
-  //编辑状态下获取回显数据的接口请求业务,如果curRow里的字段够用,就直接把curRow里的字段赋值给formData
-};
+const getDetail = async () => {};
 const { formData, isEdit } = useClearDialog(
   {
-    a: '',
+    id: '',
   },
   props,
   formRef,
@@ -46,7 +46,7 @@ const { formData, isEdit } = useClearDialog(
 );
 
 const rules = {
-  a: [
+  id: [
     {
       required: true,
       message: '请选择供应商',
@@ -56,9 +56,12 @@ const rules = {
   ],
 };
 const bindHandler = () => {
-  //   addUser({ ...formData, id: props.curRow?.id || undefined }).then(() => {
-  //     emit('success');
-  //   });
+  userBindSupplier({
+    supplierId: formData.id,
+    id: curRow.id,
+  }).then(() => {
+    emit('success');
+  });
 };
 const save = () => {
   formRef.value.validate().then(async (result) => {

+ 12 - 2
src/views/user/auth-manage/user-manage/index.vue

@@ -50,6 +50,7 @@
               修改
             </t-link>
             <t-link
+              :disabled="!row.bandSupplier"
               theme="primary"
               hover="color"
               @click="handleBindSupplier(row)"
@@ -87,6 +88,7 @@
       v-model:visible="showBindSupplierDialog"
       :curRow="curRow"
       @success="bindSupplierSuccess"
+      :options="canBindSupplierList"
     >
     </BindSupplierDialog>
   </div>
@@ -94,7 +96,7 @@
 
 <script setup name="User">
 import { ref } from 'vue';
-import { getUserList, initUserPassword } from '@/api/user';
+import { getUserList, initUserPassword, getSupplierByUser } from '@/api/user';
 import useFetchTable from '@/hooks/useFetchTable';
 import AddUserDialog from './add-user-dialog.vue';
 import UpdateUserPwdDialog from './update-user-pwd-dialog.vue';
@@ -107,7 +109,7 @@ const { perm } = usePermission();
 const showAddUserDialog = ref(false);
 const showUpdateUserPwdDialog = ref(false);
 const curRow = ref(null);
-
+const canBindSupplierList = ref([]);
 const columns = [
   { colKey: 'loginName', title: '登录名', width: 140 },
   { colKey: 'realName', title: '姓名', minWidth: 90 },
@@ -144,6 +146,13 @@ const handleEdit = (row) => {
 const showBindSupplierDialog = ref(false);
 const handleBindSupplier = (row) => {
   curRow.value = row;
+  getSupplierByUser({ id: row.id })
+    .then((res) => {
+      canBindSupplierList.value = res;
+    })
+    .catch((err) => {
+      canBindSupplierList.value = [];
+    });
   showBindSupplierDialog.value = true;
 };
 const handleEnable = (row) => {
@@ -197,6 +206,7 @@ const updatePwdSuccess = () => {
 };
 
 const bindSupplierSuccess = () => {
+  showBindSupplierDialog.value = false;
   MessagePlugin.success('绑定成功');
 };
 </script>