Browse Source

优化发票代码

zaijin 1 year ago
parent
commit
0585b70646

+ 41 - 60
pages/invoiceModule/addInvoice/addInvoice.vue

@@ -12,17 +12,17 @@
     />
     <view class="invoice-form">
       <u-form :model="form" :rules="rules" ref="uForm" label-width="150" label-align="right">
-        <u-form-item label="抬头:">
+        <u-form-item label="抬头:" required>
           <u-radio-group v-model="queryParams.invoHeadType" @change="invoTypeChange">
             <u-radio :name="1">企业</u-radio>
             <u-radio :name="2">个人</u-radio>
           </u-radio-group>
         </u-form-item>
-        <u-form-item label="抬头名称:" prop="invoName">
+        <u-form-item label="抬头名称:" prop="invoName" required>
           <u-input v-model="form.invoName" placeholder="请选择发票抬头" border disabled />
           <u-icon slot="right" name="list-dot" size="40" color="#606266" @click="moreCompany" />
         </u-form-item>
-        <u-form-item label="税号:" prop="invoCode" v-if="queryParams.invoHeadType === 1">
+        <u-form-item label="税号:" prop="invoCode" required v-if="queryParams.invoHeadType === 1">
           <u-input v-model="form.invoCode" placeholder="税号自动填充" border disabled />
         </u-form-item>
         <u-form-item label="更多内容:" prop="moreContentValue">
@@ -34,18 +34,6 @@
     </view>
     <view class="invoice-form margin-top">
       <u-form :model="form" ref="uForm1" label-width="150" label-align="right">
-        <!-- <u-form-item label="开户银行:" prop="openBank">
-          <u-input v-model="form.openBank" placeholder="选填" border />
-        </u-form-item>
-        <u-form-item label="银行账号:" prop="numBank">
-          <u-input v-model="form.numBank" placeholder="选填" border />
-        </u-form-item>
-        <u-form-item label="企业地址:" prop="mapCom">
-          <u-input v-model="form.mapCom" placeholder="选填" border />
-        </u-form-item>
-        <u-form-item label="企业电话:" prop="phoneCom">
-          <u-input v-model="form.phoneCom" placeholder="选填" border />
-        </u-form-item> -->
         <u-form-item label="电子邮箱:" prop="invoMail">
           <u-input v-model="form.invoMail" placeholder="选填" border />
         </u-form-item>
@@ -221,58 +209,51 @@ export default {
       this.queryParams.invoHeadType = val;
       this.getInvoiceHeaderSelect();
     },
+    /**
+     * @description: 更多内容弹框确认
+     * @return {*}
+     */
     moreContentConfirm() {
       this.moreContentPop.show = false;
-      let moreContentTotal = 0;
-      if (this.form.openBank) {
-        moreContentTotal += 1;
-      }
-      if (this.form.numBank) {
-        moreContentTotal += 1;
-      }
-      if (this.form.mapCom) {
-        moreContentTotal += 1;
-      }
-      if (this.form.phoneCom) {
-        moreContentTotal += 1;
-      }
-      if (moreContentTotal > 0) {
-        this.moreContentPop.moreContentValue = `共4项 已填写${moreContentTotal}项`;
-      } else {
-        this.moreContentPop.moreContentValue = '';
-      }
+      const { openBank, numBank, mapCom, phoneCom } = this.form;
+      const moreContentTotal = [openBank, numBank, mapCom, phoneCom].filter(Boolean).length;
+      this.moreContentPop.moreContentValue = moreContentTotal ? `共4项 已填写${moreContentTotal}项` : '';
     },
     submitForm() {
       this.$refs.uForm.validate(async (valid) => {
-        if (valid) {
-          try {
-            this.loading = true;
-            const { invoHeadId, invoName, invoCode, invoMail, invoPhone, invoType, phoneCom, mapCom, openBank, numBank, orderIds } = this.form;
-            const { code } = await this.$u.api.invoiceModuleApi.addInvoiceApi({
-              invoHeadId,
-              invoName,
-              invoCode,
-              invoMail,
-              invoPhone,
-              invoType,
-              phoneCom,
-              mapCom,
-              openBank,
-              numBank,
-              orderIds
+        if (!valid) return;
+        try {
+          this.loading = true;
+          uni.showLoading({
+            title: '提交中...'
+          });
+          const { invoHeadId, invoName, invoCode, invoMail, invoPhone, invoType, phoneCom, mapCom, openBank, numBank, orderIds } = this.form;
+          const { code } = await this.$u.api.invoiceModuleApi.addInvoiceApi({
+            invoHeadId,
+            invoName,
+            invoCode,
+            invoMail,
+            invoPhone,
+            invoType,
+            phoneCom,
+            mapCom,
+            openBank,
+            numBank,
+            orderIds
+          });
+          if (code === 200) {
+            this.$refs.uToast.show({
+              title: '添加成功!',
+              type: 'success',
+              duration: 1000,
+              url: '/pages/invoiceModule/invoiceSuccess/invoiceSuccess'
             });
-            if (code === 200) {
-              this.loading = false;
-              this.$refs.uToast.show({
-                title: '添加成功!',
-                type: 'success',
-                duration: 2000,
-                url: '/pages/invoiceModule/invoiceSuccess/invoiceSuccess'
-              });
-            }
-          } catch (error) {
-            this.loading = false;
           }
+        } catch (error) {
+          console.error(error);
+        } finally {
+          uni.hideLoading();
+          this.loading = false;
         }
       });
     }

+ 41 - 50
pages/invoiceModule/addInvoiceHeader/addInvoiceHeader.vue

@@ -17,16 +17,16 @@
     </u-navbar>
     <view class="invoice-header-form">
       <u-form :model="form" ref="uForm" label-width="220" label-align="right">
-        <u-form-item label="抬 头:" prop="invoHeadType" class="u-skeleton-fillet">
+        <u-form-item label="抬 头:" prop="invoHeadType" required class="u-skeleton-fillet">
           <u-radio-group v-model="form.invoHeadType" :disabled="!!form.id">
             <u-radio :name="1">企业</u-radio>
             <u-radio :name="2">个人</u-radio>
           </u-radio-group>
         </u-form-item>
-        <u-form-item label="发票抬头:" prop="invoName" class="u-skeleton-fillet">
+        <u-form-item label="发票抬头:" prop="invoName" required class="u-skeleton-fillet">
           <u-input v-model="form.invoName" placeholder="请输入发票抬头" />
         </u-form-item>
-        <u-form-item label="税 号:" prop="invoCode" class="u-skeleton-fillet" v-if="form.invoHeadType === 1">
+        <u-form-item label="税 号:" prop="invoCode" required class="u-skeleton-fillet" v-if="form.invoHeadType === 1">
           <u-input v-model="form.invoCode" placeholder="请输入税号" />
         </u-form-item>
       </u-form>
@@ -153,56 +153,47 @@ export default {
      */
     submitForm() {
       this.$refs.uForm.validate(async (valid) => {
-        if (valid) {
-          this.loading = true;
-          const form = { ...this.form };
-          form.invoStatus = form.invoStatus ? 1 : 0;
-          if (form.invoHeadType === 2) {
-            form.invoCode = null;
-          }
+        if (!valid) return;
+        this.loading = true;
+        uni.showLoading({
+          title: '提交中...'
+        });
+        const form = { ...this.form };
+        form.invoStatus = form.invoStatus ? 1 : 0;
+        if (form.invoHeadType === 2) {
+          form.invoCode = null;
+        }
+        try {
+          let response;
           if (form.id) {
-            try {
-              const { code } = await this.$u.api.invoiceModuleApi.updateInvoiceHeaderApi({ ...form });
-              if (code === 200) {
-                this.$refs.uToast.show({
-                  title: '修改成功!',
-                  type: 'success',
-                  duration: 2000
-                  // url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
-                });
-                setTimeout(() => {
-                  this.$u.route({
-                    url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList',
-                    type: 'redirect'
-                  });
-                }, 2000);
-              }
-            } catch (error) {
-            } finally {
-              this.loading = false;
-            }
+            response = await this.$u.api.invoiceModuleApi.updateInvoiceHeaderApi({ ...form });
+            this.$refs.uToast.show({
+              title: '修改成功!',
+              type: 'success',
+              duration: 2000
+            });
           } else {
-            try {
-              const { code } = await this.$u.api.invoiceModuleApi.addInvoiceHeaderApi({ ...form });
-              if (code === 200) {
-                this.$refs.uToast.show({
-                  title: '保存成功!',
-                  type: 'success',
-                  duration: 2000
-                  // url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList'
-                });
-                setTimeout(() => {
-                  this.$u.route({
-                    url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList',
-                    type: 'redirect'
-                  });
-                }, 2000);
-              }
-            } catch (error) {
-            } finally {
-              this.loading = false;
-            }
+            response = await this.$u.api.invoiceModuleApi.addInvoiceHeaderApi({ ...form });
+            this.$refs.uToast.show({
+              title: '保存成功!',
+              type: 'success',
+              duration: 2000
+            });
+          }
+          if (response.code === 200) {
+            setTimeout(() => {
+              uni.hideLoading();
+              this.$u.route({
+                url: '/pages/invoiceModule/invoiceHeaderList/invoiceHeaderList',
+                type: 'redirect'
+              });
+            }, 2000);
           }
+        } catch (error) {
+          console.error(error);
+        } finally {
+          uni.hideLoading()
+          this.loading = false;
         }
       });
     }