ソースを参照

change: 创建payment record页面. statement上传时机跳转, 增加汇总值和货币类型参数. 关联逻辑改动.

peter 1 年間 前
コミット
e6640146d5

+ 4 - 0
src/pages/payment-record/components/edit.vue

@@ -325,6 +325,10 @@ watchEffect(() => {
     },
     JSON.parse(JSON.stringify(props.currentEditRow)),
   )
+  form.value.statement = {
+    label: form.value.statement_name,
+    value: form.value.statement_id,
+  }
   if (props.disableFlag) {
     form.value.currency = props.lockedCurrency
   }

+ 33 - 29
src/pages/payment-record/components/upload.vue

@@ -55,7 +55,10 @@
           </el-form-item>
 
           <el-form-item label="Upload Mode">
-            <el-select v-model="form.mode">
+            <el-select
+              v-model="form.mode"
+              disabled
+            >
               <el-option
                 v-for="option in uploadOption"
                 :key="option.value"
@@ -92,7 +95,7 @@
               <div class="el-upload">
                 单个Excel数据最好控制在100行内, 处理起来会慢
               </div>
-              <br>
+              <br />
               <div
                 v-if="tableData.length"
                 style="color: green"
@@ -299,35 +302,36 @@ const next = (formEl: FormInstance | undefined) => {
   formEl.validate((valid, fields) => {
     if (valid) {
       loading.value = true
-      request
-        .post('/payment_request/createStatementData', [
-          {
-            Name: form.value.statement_name,
-          },
-        ])
-        .then((response) => {
-          if (response.data.code !== 1) return
-          const res = response.data.result
+      // 创建statement 动作调整到主界面点击保存再调用.
+      // request
+      //   .post('/payment_request/createStatementData', [
+      //     {
+      //       Name: form.value.statement_name,
+      //     },
+      //   ])
+      //   .then((response) => {
+      // if (response.data.code !== 1) return
+      // const res = response.data.result
 
-          let result = {
-            mode: form.value.mode,
-            data: tableData.value.map((i) => {
-              return {
-                ...i,
-                po_number: i.po_number.toUpperCase(),
-                payment_type: form.value.paymentType,
-                statement_name: form.value.statement_name,
-                currency: form.value.currency,
-                statement_id: res.data[0].details.id,
-              }
-            }),
+      let result = {
+        mode: form.value.mode,
+        data: tableData.value.map((i) => {
+          return {
+            ...i,
+            po_number: i.po_number.toUpperCase(),
+            payment_type: form.value.paymentType,
+            statement_name: form.value.statement_name,
+            currency: form.value.currency,
+            statement_id: form.value.statement_name,
           }
-          emit('update-table-data', result)
-          handleClose(false)
-        })
-        .finally(() => {
-          loading.value = false
-        })
+        }),
+      }
+      emit('update-table-data', result)
+      handleClose(false)
+      // })
+      // .finally(() => {
+      loading.value = false
+      // })
     } else {
       console.log('check form has not pass!', fields)
       ElMessage.error('请检查表单必填项')

+ 33 - 8
src/pages/payment-record/index.vue

@@ -37,7 +37,7 @@
           <el-button
             :disabled="tableData.length < 1"
             type="primary"
-            @click="save"
+            @click="createStatement"
           >
             Save
           </el-button>
@@ -313,16 +313,16 @@ const computedTableData = computed(() => {
 })
 const computedStatementList = computed(() => {
   const result: any[] = []
-  const result2: any[] = []
+
   tableData.value.forEach((i) => {
     if (i.statement_name?.length && !result.includes(i.statement_name)) {
       result.push(i.statement_name)
-      result2.push(i.statement_id)
     }
   })
   return result.map((i, index) => {
+    // statement调整成点击保存再创建了, 而不是之前的在上传对话框创建, 所以逻辑变动, 这里拿不到id, 只能拿name凑合.
     return {
-      value: result2[index],
+      value: i,
       label: i,
     }
   })
@@ -365,23 +365,47 @@ const onEditRow = function (data: IPoItem) {
     data,
   )
 }
-
-const save = function () {
+const statementID = ref('')
+const createStatement = function () {
   if (!['Finance Manager', 'CEO'].includes(userInfo.value.role.name)) {
     ElMessage.error('当前用户没有处理的权限')
     return
   }
+  loading.value = true
+  request
+    .post('/payment_request/createStatementData', [
+      {
+        Total_Amount: computedSum.value,
+        Currency: tableData.value[0].currency,
+        Name: tableData.value[0].statement_name,
+      },
+    ])
+    .then((response) => {
+      if (response.data.code !== 1) {
+        ElMessage.error('创建statement出错')
+        return
+      }
+      statementID.value = response.data.result.data[0].details.id
+
+      save()
+    })
+    .catch(() => {
+      loading.value = false
+    })
+}
+
+const save = function () {
   const formData = tableData.value.map((i, index) => {
     const result: any = {
       Unit_Price: i.unit_price,
-      Quantity: i.quantity,
+      Quantity: i.quantity ? i.quantity.toString() : '',
       Sample_Fee: i.sample_fee,
       Setup_Service_Fee: i.setup_service_fee,
       Total: i.total,
       Currency: i.currency,
       Description: i.description,
       PO_id: i.po_number,
-      Statement: { name: i.statement_name, id: i.statement_id },
+      Statement: { name: i.statement_name, id: statementID.value },
       Request_Type: '月结申请',
       Name: '/',
       Unit_Price_Non_Currency: i.unit_price ? i.unit_price.toString() : '',
@@ -415,6 +439,7 @@ const save = function () {
   Promise.all(pool)
     .then(() => {
       tableData.value = []
+      statementID.value = ''
     })
     .finally(() => {
       loading.value = false