Explorar o código

feat(utils/ygoa): 大写人民币金额转换工具
refactor(process/detail): 修改重复表变量名
refactor(work/edit): 修改重复表变量名

wangpx hai 1 ano
pai
achega
b74c117dad
Modificáronse 3 ficheiros con 104 adicións e 42 borrados
  1. 20 20
      pages/process/detail/index.vue
  2. 24 22
      pages/work/edit/index.vue
  3. 60 0
      utils/ygoa.js

+ 20 - 20
pages/process/detail/index.vue

@@ -13,23 +13,23 @@
 			</uni-list>
 		</uni-card>
 		<!-- 重复表 -->
-		<uni-card v-if="repeatingTableNotEmpty">
-			<button @click="handleRepeatingTable" type="primary">查看重复表</button>
+		<uni-card v-if="repeatingFormNotEmpty">
+			<button @click="handlerepeatingForm" type="primary">查看重复表</button>
 		</uni-card >
-		<uni-popup v-if="repeatingTableNotEmpty" ref="repeatingTablePopup">
+		<uni-popup v-if="repeatingFormNotEmpty" ref="repeatingFormPopup">
 			<uni-card margin="0px" spacing="0px" padding="0px">
 				<view class="repeating_table_container">
 					<uni-table :border="true" stripe>
 						<uni-tr>
-							<uni-th align="center" v-for="(item, index) in repeatingTable.elementItem" :key="index">
+							<uni-th align="center" v-for="(item, index) in repeatingForm.elementItem" :key="index">
 							{{ item.elementName.slice(3, 5) }}
 							<!-- {{ item.elementName.slice(3) }} -->
 							</uni-th>
 						</uni-tr>
-						<uni-tr v-for="(item, index) in (repeatingTable.elements.length / repeatingTable.elementItem.length)" :key="index">
-							<uni-td align="center" v-for="col in repeatingTable.elementItem.length" :key="col">
+						<uni-tr v-for="(item, index) in (repeatingForm.elements.length / repeatingForm.elementItem.length)" :key="index">
+							<uni-td align="center" v-for="col in repeatingForm.elementItem.length" :key="col">
 							<!-- (列数 - 1) * 总行数 + 当前行数 -->
-							{{repeatingTable.elements[(col-1)*(repeatingTable.elements.length / repeatingTable.elementItem.length) + index]!.defaultValue}}
+							{{repeatingForm.elements[(col-1)*(repeatingForm.elements.length / repeatingForm.elementItem.length) + index]!.defaultValue}}
 							</uni-td>
 						</uni-tr>
 					</uni-table>
@@ -71,19 +71,19 @@
 		initProcessInfo()
 	})
 	
-	const repeatingTable = ref({
+	const repeatingForm = ref({
 		elements: [],
 		elementItem: [],
 	})
-	const repeatingTableNotEmpty = ref(false)
-	function repeatingTableHasValue() {
-		if (repeatingTable.value === undefined) return
-		if (repeatingTable.value.elementItem.length <= 0) return
-		repeatingTable.value.elements.forEach(({defaultValue}) => {
+	const repeatingFormNotEmpty = ref(false)
+	function repeatingFormHasValue() {
+		if (repeatingForm.value === undefined) return
+		if (repeatingForm.value.elementItem.length <= 0) return
+		repeatingForm.value.elements.forEach(({defaultValue}) => {
 			if (defaultValue != "") {
-				repeatingTableNotEmpty.value = true
+				repeatingFormNotEmpty.value = true
 				return new Promise((resolve, reject) => {
-					resolve(repeatingTableNotEmpty)
+					resolve(repeatingFormNotEmpty)
 				})
 			}
 		})
@@ -94,14 +94,14 @@
 	function initProcessInfo() {
 		getProcessInfo(userStore.user.useId, processInfo.insId).then(({ returnParams }) => {
 			formElements.value = returnParams.formElements
-			repeatingTable.value = returnParams.repeatingTable
+			repeatingForm.value = returnParams.repeatingForm
 			fileList.value = returnParams.fileList
-			repeatingTableHasValue()
+			repeatingFormHasValue()
 		})
 	}
-	const repeatingTablePopup = ref(null)
-	function handleRepeatingTable() {
-		repeatingTablePopup.value.open()
+	const repeatingFormPopup = ref(null)
+	function handlerepeatingForm() {
+		repeatingFormPopup.value.open()
 	}
 </script>
 

+ 24 - 22
pages/work/edit/index.vue

@@ -40,25 +40,25 @@
 			</uni-forms>
 		</uni-card>
 
-		<view v-if="repeatingTable.elementItem.length > 0" class="repeating_table">
-			<uni-card v-for="(table, tableIndex) in repeatingTable.elements" margin="10px" spacing="0"
+		<view v-if="repeatingForm.elementItem.length > 0" class="repeating_table">
+			<uni-card v-for="(table, tableIndex) in repeatingForm.elements" margin="10px" spacing="0"
 				:key="tableIndex">
 				<uni-forms label-position="left" :label-width="125" :border="true">
 					<uni-forms-item v-for="(item, itemIndex) in table"
-						:label="repeatingTable.elementItem[itemIndex].elementName.slice(3)" :key="itemIndex">
-						<uni-easyinput v-if="repeatingTable.elementItem[itemIndex].bddzText" :disabled="true"
-							:placeholder="''" :value="computedRepeatingTableItemValue(item, table)"></uni-easyinput>
+						:label="repeatingForm.elementItem[itemIndex].elementName.slice(3)" :key="itemIndex">
+						<uni-easyinput v-if="repeatingForm.elementItem[itemIndex].bddzText" :disabled="true"
+							:placeholder="''" :value="computedrepeatingFormItemValue(item, table)"></uni-easyinput>
 						<uni-easyinput v-else placeholder="请输入内容" v-model="item.value"></uni-easyinput>
 					</uni-forms-item>
 				</uni-forms>
 				<view class="repeating_table_button_container">
 					<uni-row>
 						<uni-col :span="10" :offset="1">
-							<button @click="addRepeatingTableItem(tableIndex)" type="primary">新增</button>
+							<button @click="addrepeatingFormItem(tableIndex)" type="primary">新增</button>
 						</uni-col>
 						<uni-col :span="10" :offset="2">
-							<button @click="delRepeatingTableItem(tableIndex)"
-								:disabled="repeatingTable.elements.length <= 1" type="warn">删除</button>
+							<button @click="delrepeatingFormItem(tableIndex)"
+								:disabled="repeatingForm.elements.length <= 1" type="warn">删除</button>
 						</uni-col>
 					</uni-row>
 				</view>
@@ -80,6 +80,7 @@ import { onLoad } from '@dcloudio/uni-app'
 import { useUserStore } from '@/store/user.js'
 import $modal from '@/plugins/modal.js'
 import $tab from '@/plugins/tab.js'
+import { convertToChineseCurrency } from '@/utils/ygoa.js'
 import { getProcessInfo, getProcessForm, submitProcessForm, uploadFile } from '@/api/work.js'
 
 let processInfo = reactive({
@@ -128,10 +129,10 @@ function initProcessInfo() {
 function initProcessForm() {
 	getProcessForm(userStore.user, processInfo).then(({ returnParams }) => {
 		formElements.value = returnParams.formElements
-		repeatingTable.value = returnParams.repeatingTable
+		repeatingForm.value = returnParams.repeatingForm
 		// 生成第一个重复表数据
-		if (repeatingTable.value) {
-			addRepeatingTableItem(0)
+		if (repeatingForm.value) {
+			addrepeatingFormItem(0)
 		}
 
 		startEleIndex.value = formElements.value.findIndex((item) => '开始时间' == item.elementName)
@@ -148,14 +149,14 @@ function initProcessForm() {
 }
 
 const formElements = ref([])
-const repeatingTable = ref({
+const repeatingForm = ref({
 	elementItem: [],
 	elements: []
 })
 const startEleIndex = ref(0) // 开始时间
 const endEleIndex = ref(0) // 结束时间
-function addRepeatingTableItem(index) {
-	const table = repeatingTable.value.elementItem.map(({ tableField, bddzText }) => {
+function addrepeatingFormItem(index) {
+	const table = repeatingForm.value.elementItem.map(({ tableField, bddzText }) => {
 		const item = {
 			name: tableField,
 			value: ""
@@ -163,29 +164,30 @@ function addRepeatingTableItem(index) {
 		if (bddzText != '') {
 			const mulItem = bddzText.split('*')
 			item['bddzText'] = mulItem.map(item => {
-				return repeatingTable.value.elementItem.findIndex(({ elementName }) => item == elementName)
+				return repeatingForm.value.elementItem.findIndex(({ elementName }) => item == elementName)
 			})
 		}
 		return item
 	})
-	repeatingTable.value.elements.splice(index + 1, 0, table)
+	repeatingForm.value.elements.splice(index + 1, 0, table)
 }
-function delRepeatingTableItem(index) {
-	console.log("delRepeatingTableItem: " + index);
+function delrepeatingFormItem(index) {
+	console.log("delrepeatingFormItem: " + index);
 	$modal.confirm('', '确认删除该重复表数据')
 		.then(() => {
-			repeatingTable.value.elements.splice(index, 1)
+			repeatingForm.value.elements.splice(index, 1)
 		})
 		.catch(err => {
 
 		})
 }
-function computedRepeatingTableItemValue(item, table) {
+function computedrepeatingFormItemValue(item, table) {
 	let res = 1
 	item.bddzText.forEach(itemIndex => {
 		res = res * table[itemIndex].value
 	})
 	item.value = res
+	console.log('convertToChineseCurrency', convertToChineseCurrency(res));
 	return res
 }
 
@@ -278,7 +280,7 @@ function submitProcess() { // 提交表单
 	processInfo.form = formElements.value.map(({ tableField, defaultValue }) => {
 		return { name: tableField, value: defaultValue }
 	})
-	repeatingTable.value.elements.forEach((item, index) => {
+	repeatingForm.value.elements.forEach((item, index) => {
 		const newItem = item.map(({ name, value }) => {
 			return {
 				name: name + '_' + (index + 1),
@@ -288,7 +290,7 @@ function submitProcess() { // 提交表单
 		processInfo.form.push(...newItem)
 	})
 	// console.log('submitProcessForm', processInfo.form);
-	// console.log('repeatingTable', repeatingTable.value);
+	// console.log('repeatingForm', repeatingForm.value);
 	// console.log('formElements', formElements.value);
 	// console.log('fileList', fileList.value);
 	// console.log('fileSeqs', fileSeqs.value);

+ 60 - 0
utils/ygoa.js

@@ -0,0 +1,60 @@
+export function convertToChineseCurrency(amount) {
+
+    if (amount === "0" || amount === 0) {
+        return "零元整";
+    }
+
+    const CN_NUMS = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
+    const CN_INT = ["", "拾", "佰", "千"];
+    const CN_UNIT = ["", "万", "亿", "兆"];
+    const CN_DECIMAL = ["角", "分", "厘", "毫"];
+
+    // 将金额转换为字符串并去掉多余的零
+    let str = amount.toString().replace(/[^0-9.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./, '').replace('$#$', '.');
+
+    let [integerPart, decimalPart] = str.split('.');
+
+    // 处理整数部分
+    let integerLen = integerPart.length;
+    let integerResult = '';
+    let zeroCount = 0; // 记录连续的零
+
+    for (let i = 0; i < integerLen; i++) {
+        let num = integerPart.charAt(i);
+        let unitPos = integerLen - i - 1;
+        let unitIndex = unitPos % 4;
+
+        // 当前位为零时不进行处理
+        if (num === '0') {
+            zeroCount++;
+        } else {
+            if (zeroCount > 0) {
+                integerResult += CN_NUMS[0];
+            }
+            zeroCount = 0;
+            integerResult += CN_NUMS[parseInt(num)] + CN_INT[unitIndex];
+        }
+
+        if (unitIndex === 0) {
+            integerResult += CN_UNIT[Math.floor(unitPos / 4)];
+        }
+    }
+
+    // 处理小数部分
+    let decimalResult = '';
+    if (decimalPart) {
+        let decimalLen = decimalPart.length;
+        for (let i = 0; i < decimalLen; i++) {
+            let num = decimalPart.charAt(i);
+            if (num !== '0') {
+                decimalResult += CN_NUMS[parseInt(num)] + CN_DECIMAL[i];
+            }
+        }
+    }
+
+    if (!decimalResult) {
+        decimalResult = '整';
+    }
+
+    return integerResult + decimalResult;
+}