zhangwencui
16 小时以前 263b4a60670671cef5445b102e670c40ba34a162
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
  <view class="account-detail">
    <PageHeader :title="pageTitle" @back="goBack" />
    <up-form ref="formRef" :model="form" :rules="rules" label-width="110">
      <up-form-item label="供应商名称" prop="supplierName" required>
        <up-input v-model="form.supplierName" placeholder="请输入" clearable />
      </up-form-item>
      <up-form-item label="纳税人识别号" prop="taxpayerIdentificationNum" required>
        <up-input v-model="form.taxpayerIdentificationNum" placeholder="请输入" clearable />
      </up-form-item>
      <up-form-item label="公司地址" prop="companyAddress" required>
        <up-input v-model="form.companyAddress" placeholder="请输入" clearable />
      </up-form-item>
      <up-form-item label="供应商类型" prop="supplierType" required>
        <up-input
          v-model="supplierTypeText"
          placeholder="请选择"
          readonly
          @click="showSupplierTypeSheet = true"
        />
        <template #right>
          <up-icon name="arrow-right" @click="showSupplierTypeSheet = true"></up-icon>
        </template>
      </up-form-item>
      <up-form-item label="是否白名单" prop="isWhite" required>
        <up-input
          v-model="isWhiteText"
          placeholder="请选择"
          readonly
          @click="showIsWhiteSheet = true"
        />
        <template #right>
          <up-icon name="arrow-right" @click="showIsWhiteSheet = true"></up-icon>
        </template>
      </up-form-item>
      <up-form-item label="维护人" prop="maintainUserName">
        <up-input v-model="form.maintainUserName" placeholder="自动填充" disabled />
      </up-form-item>
      <up-form-item label="维护时间" prop="maintainTime">
        <up-input v-model="form.maintainTime" placeholder="自动填充" disabled />
      </up-form-item>
    </up-form>
    <FooterButtons :loading="loading" confirmText="保存" @cancel="goBack" @confirm="handleSubmit" />
 
    <up-action-sheet
      :show="showSupplierTypeSheet"
      title="选择供应商类型"
      :actions="supplierTypeActions"
      @select="onSelectSupplierType"
      @close="showSupplierTypeSheet = false"
    />
    <up-action-sheet
      :show="showIsWhiteSheet"
      title="选择白名单"
      :actions="isWhiteActions"
      @select="onSelectIsWhite"
      @close="showIsWhiteSheet = false"
    />
  </view>
</template>
 
<script setup>
  import { computed, onMounted, ref } from "vue";
  import { onLoad } from "@dcloudio/uni-app";
  import FooterButtons from "@/components/FooterButtons.vue";
  import useUserStore from "@/store/modules/user";
  import { formatDateToYMD } from "@/utils/ruoyi";
  import { addSupplier, getSupplier, updateSupplier } from "@/api/basicData/supplierManageFile";
 
  const userStore = useUserStore();
  const formRef = ref();
  const loading = ref(false);
  const supplierId = ref(undefined);
 
  const form = ref({
    supplierName: "",
    taxpayerIdentificationNum: "",
    companyAddress: "",
    maintainUserId: "",
    maintainUserName: "",
    maintainTime: "",
    supplierType: "",
    isWhite: 0,
  });
 
  const rules = {
    supplierName: [{ required: true, message: "请输入供应商名称", trigger: "blur" }],
    taxpayerIdentificationNum: [{ required: true, message: "请输入纳税人识别号", trigger: "blur" }],
    companyAddress: [{ required: true, message: "请输入公司地址", trigger: "blur" }],
    supplierType: [{ required: true, message: "请选择供应商类型", trigger: "change" }],
    isWhite: [{ required: true, message: "请选择白名单", trigger: "change" }],
  };
 
  const pageTitle = computed(() => {
    return supplierId.value ? "编辑供应商" : "新增供应商";
  });
 
  const supplierTypeActions = [
    { name: "甲", value: "甲" },
    { name: "乙", value: "乙" },
    { name: "丙", value: "丙" },
    { name: "丁", value: "丁" },
  ];
  const isWhiteActions = [
    { name: "是", value: 0 },
    { name: "否", value: 1 },
  ];
 
  const showSupplierTypeSheet = ref(false);
  const showIsWhiteSheet = ref(false);
 
  const supplierTypeText = computed(() => form.value.supplierType || "");
  const isWhiteText = computed(() => {
    return String(form.value.isWhite) === "0" ? "是" : "否";
  });
 
  const onSelectSupplierType = action => {
    form.value.supplierType = action.value;
    showSupplierTypeSheet.value = false;
  };
 
  const onSelectIsWhite = action => {
    form.value.isWhite = action.value;
    showIsWhiteSheet.value = false;
  };
 
  const initForAdd = () => {
    form.value.maintainUserId = userStore.id;
    form.value.maintainUserName = userStore.nickName;
    form.value.maintainTime = formatDateToYMD(Date.now());
    form.value.isWhite = 0;
  };
 
  const loadDetail = () => {
    if (!supplierId.value) return;
    uni.showLoading({ title: "加载中...", mask: true });
    getSupplier(supplierId.value)
      .then(res => {
        form.value = { ...form.value, ...(res.data || {}) };
      })
      .catch(() => {
        uni.showToast({ title: "获取详情失败", icon: "error" });
      })
      .finally(() => {
        uni.hideLoading();
      });
  };
 
  const goBack = () => {
    uni.navigateBack();
  };
 
  const handleSubmit = async () => {
    const valid = await formRef.value.validate().catch(() => false);
    if (!valid) return;
    loading.value = true;
    const action = supplierId.value ? updateSupplier : addSupplier;
    action({ ...form.value, id: supplierId.value })
      .then(() => {
        uni.showToast({ title: "保存成功", icon: "success" });
        uni.navigateBack();
      })
      .catch(() => {
        uni.showToast({ title: "保存失败", icon: "error" });
      })
      .finally(() => {
        loading.value = false;
      });
  };
 
  onMounted(() => {
    userStore.getInfo();
    initForAdd();
  });
 
  onLoad(options => {
    if (options?.id) supplierId.value = options.id;
    if (supplierId.value) loadDetail();
  });
</script>
 
<style scoped lang="scss">
  @import "@/static/scss/form-common.scss";
</style>