transferCard.vue 28.9 KB
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245
<template>
	<view class="transfer-container">
		<view class="form-card">
			<view class="form-content">
				<form @submit="handleFormSubmit">
					<!-- 转出会员 -->
					<view class="form-group">
						<text class="form-label">转出会员</text>
						<view class="input-wrapper">
							<view class="custom-select" @tap="openSelectModal('fromMember')">
								<text class="select-text">{{ formData.fromMemberName || '请选择转出会员' }}</text>
								<text class="select-arrow">▼</text>
							</view>
						</view>
					</view>

					<!-- 转入会员 -->
					<view class="form-group">
						<text class="form-label">转入会员</text>
						<view class="input-wrapper">
							<view class="custom-select" @tap="openSelectModal('toMember')">
								<text class="select-text">{{ formData.toMemberName || '请选择转入会员' }}</text>
								<text class="select-arrow">▼</text>
							</view>
						</view>
					</view>

					<!-- 转卡品项明细 -->
					<view class="form-group">
						<text class="form-label">转卡品项明细</text>
						<view >
							<view v-for="(item, index) in transferItems" :key="index" class="transfer-row">
								<!-- 第一行:品项选择和删除按钮 -->
								<view class="transfer-row-first">
									<view class="transfer-select" @tap="selectTransferItem(index)">
										<text class="select-text">{{ item.itemName || '选择品项' }}</text>
										<text class="select-arrow">▼</text>
									</view>
									<button @click="deleteTransferRow(index)" class="transfer-delete">删除</button>
								</view>

								<!-- 第二行:数量和单价 -->
								<view class="transfer-row-second">
									<u-input v-model="item.transferQuantity" placeholder="数量" type="number" 
										class="transfer-count" @input="updateTransferQuantity(index, $event)" />
									<view class="transfer-unit-price" v-if="item.RemainingCount">
										<text class="price-value">剩余:{{ item.RemainingCount }}</text>
									</view>
									<view class="transfer-unit-price">
										<text class="price-value">总价:{{ item.itemPrice * item.transferQuantity || 0}}</text>
									</view>
								</view>
							</view>
						</view>
						<button type="primary" size="normal" @click="addTransferRow" class="btn-add-transfer">
							添加转卡品项
						</button>
					</view>

					<!-- 备注 -->
					<view class="form-group">
						<text class="form-label">备注</text>
						<view class="input-wrapper">
							<textarea v-model="formData.remarks" placeholder="请输入备注" :maxlength="500" :count="true"
								class="textarea-input" />
						</view>
					</view>

					<!-- 签字 -->
					<view class="form-group">
						<text class="form-label">签字</text>
						<view class="input-wrapper">
							<view v-if="!signatureFile" class="signature-placeholder">
								<button @click="openSignatureModal" class="btn-signature-placeholder">
									<text class="signature-placeholder-text">点击进行签字</text>
								</button>
							</view>
							<view v-if="signatureFile" class="signature-preview">
								<text class="preview-label">签字预览:</text>
								<image @tap="previewSignature(signatureFile)" :src="signatureFile"
									class="signature-image" mode="aspectFit" />
								<view class="signature-actions">
									<button @click="openSignatureModal" class="btn-re-signature">重新签字</button>
									<button @click="clearSignature" class="btn-clear-signature">清除签字</button>
								</view>
							</view>
						</view>
					</view>

					<!-- 提交按钮 -->
					<view class="btn-group">
						<button type="submit" class="btn btn-primary" :style="{opacity: isSubmitting?1:0.5}" 
							@tap="isSubmitting?submitTransfer():null">{{ isSubmitting?'确认转卡':'提交中...' }}</button>
					</view>
				</form>
			</view>
		</view>

		<!-- 选择弹窗 -->
		<SearchSelectModal :show="showModal" :title="modalTitle" :options="currentOptions" :loading="modalLoading"
			:has-more="hasMoreData" :search-param="searchParam" @confirm="handleModalConfirm" @close="closeModal"
			@load-more="handleLoadMore" @refresh="handleRefresh" @search="handleSearch" />

		<!-- 全屏签字弹窗 -->
		<view v-if="showSignatureModal" class="signature-modal-overlay" @tap="closeSignatureModal">
			<view class="signature-modal" @tap.stop>
				<view class="signature-modal-header">
					<text class="signature-modal-title">转卡签字</text>
					<button @click="closeSignatureModal" class="btn-close-modal">×</button>
				</view>
				<view class="signature-modal-content">
					<SignaturePad :width="800" :height="500" :line-width="4"
						stroke-color="#2e7d32" @confirm="handleSignatureConfirm" @clear="handleSignatureClear"
						ref="signaturePadModal" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import SearchSelectModal from '@/components/SearchSelectModal.vue'
	import SignaturePad from '@/components/SignaturePad.vue'
	import memberApi from '@/apis/modules/member.js'
	import lxApi from '@/apis/modules/lx.js'
	import config from '@/common/config.js'
	
	export default {
		components: {
			SearchSelectModal,
			SignaturePad
		},
		data() {
			return {
				isSubmitting: true,
				baseUrl: config.getApiBaseUrl(),
				
				// 表单数据
				formData: {
					fromMemberId: '',
					fromMemberName: '',
					toMemberId: '',
					toMemberName: '',
					remarks: ''
				},

				// 转卡品项列表
				transferItems: [],

				// 签字文件
				signatureFile: '',

				// 弹窗相关
				showModal: false,
				modalTitle: '',
				currentSelectField: '',
				currentOptions: [],
				modalLoading: false,
				hasMoreData: true,
				currentPage: 1,
				pageSize: 20,
				searchKeyword: '',
				searchParam: '',

				// 用户信息
				userInfo: null,

				// 选中的值
				selectedValues: {
					fromMember: null,
					toMember: null
				},

				// 当前操作的转卡品项索引
				currentTransferIndex: -1,

				// 签字弹窗
				showSignatureModal: false,
				scrollTop: 0
			}
		},
		onLoad(options) {
			this.initializePage();
		},
		onUnload() {
			this.enablePageScroll();
		},
		methods: {
			// 初始化页面
			async initializePage() {
				try {
					// 获取用户信息
					this.userInfo = uni.getStorageSync('userInfo');
					if (!this.userInfo || Object.keys(this.userInfo).length === 0) {
						uni.showToast({
							title: '请先登录',
							icon: 'none'
						});
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login'
							});
						}, 1500);
						return;
					}
					
					// 添加默认的转卡品项行
					this.addTransferRow();
				} catch (error) {
					console.error('页面初始化失败:', error);
					uni.showToast({
						title: '页面初始化失败',
						icon: 'none'
					});
				}
			},

			// 添加转卡品项行
			addTransferRow() {
				this.transferItems.push({
					billingItemId: '',
					transferQuantity: 1,
					itemName: '',
					itemPrice: 0
				});
			},

			// 删除转卡品项行
			deleteTransferRow(index) {
				if (this.transferItems.length > 1) {
					this.transferItems.splice(index, 1);
				} else {
					uni.showToast({
						title: '至少需要保留一个转卡品项',
						icon: 'none'
					});
				}
			},

			// 选择转卡品项
			selectTransferItem(index) {
				this.currentTransferIndex = index;
				this.openSelectModal('transferItem');
			},

			// 更新转卡品项数量
			updateTransferQuantity(index, value) {
				const count = parseInt(value) || 1;
				this.transferItems[index].transferQuantity = count < 1 ? 1 : count;
			},

			// 打开选择弹窗
			async openSelectModal(fieldId) {
				this.currentSelectField = fieldId;
				this.showModal = true;
				this.modalTitle = '加载中...';
				this.modalLoading = true;
				this.currentPage = 1;
				this.hasMoreData = true;
				this.searchKeyword = '';
				this.currentOptions = [];

				try {
					// 设置搜索参数
					switch (fieldId) {
						case 'fromMember':
						case 'toMember':
							this.searchParam = 'khmc';
							this.modalTitle = fieldId === 'fromMember' ? '选择转出会员' : '选择转入会员';
							break;
						case 'transferItem':
							this.searchParam = 'itemName';
							this.modalTitle = '选择转卡品项';
							break;
					}

					await this.loadOptionsData(fieldId, 1);
				} catch (error) {
					console.error('获取选项数据失败:', error);
					this.modalTitle = '加载失败';
					this.currentOptions = [];
					uni.showToast({
						title: '数据加载失败,请检查网络连接',
						icon: 'none'
					});
				} finally {
					this.modalLoading = false;
				}
			},

			// 关闭弹窗
			closeModal() {
				this.showModal = false;
				this.currentSelectField = '';
				this.currentOptions = [];
				this.modalLoading = false;
				this.hasMoreData = true;
				this.currentPage = 1;
				this.searchKeyword = '';
			},

			// 加载选项数据
			async loadOptionsData(fieldId, page = 1, searchKeyword = '') {
				let options = [];

				switch (fieldId) {
					case 'fromMember':
					case 'toMember':
						options = await this.getMemberOptions(page, searchKeyword);
						break;
					case 'transferItem':
						this.hasMoreData = false;
						options = await this.getTransferItemOptions(page, searchKeyword);
						break;
				}

				// 为每个选项添加全局唯一的 key
				options = options.map((option, index) => ({
					...option,
					uniqueKey: `${fieldId}_${page}_${index}_${Date.now()}`
				}));

				if (page === 1) {
					this.currentOptions = options;
				} else {
					this.currentOptions = [...this.currentOptions, ...options];
				}

				// 检查是否还有更多数据
				if (options.length < this.pageSize) {
					this.hasMoreData = false;
				}
			},

			// 处理弹窗确认
			async handleModalConfirm(selectedOption) {
				if (this.currentSelectField && selectedOption) {
					console.log('selectedOption', selectedOption);
					switch (this.currentSelectField) {
						case 'fromMember':
							this.formData.fromMemberId = selectedOption.value;
							this.formData.fromMemberName = selectedOption.label;
							this.selectedValues.fromMember = selectedOption.value;
							break;
						case 'toMember':
							this.formData.toMemberId = selectedOption.value;
							this.formData.toMemberName = selectedOption.label;
							this.selectedValues.toMember = selectedOption.value;
							break;
					case 'transferItem':
						if (this.currentTransferIndex >= 0) {
							// 先校验已经选择的品项有没有这个
							const existingIndex = this.transferItems.findIndex((item, index) => 
								index !== this.currentTransferIndex && item.billingItemId === selectedOption.value
							);
							if (existingIndex !== -1) {
								uni.showToast({
									title: '该品项已存在,请勿重复添加',
									icon: 'none',
									duration: 2000
								});
								this.closeModal();
								return;
							}
							
							this.transferItems[this.currentTransferIndex].billingItemId = selectedOption.value;
							this.transferItems[this.currentTransferIndex].itemName = selectedOption.label;
							this.transferItems[this.currentTransferIndex].itemPrice = selectedOption.itemPrice || 0;
							this.transferItems[this.currentTransferIndex].RemainingCount = selectedOption.RemainingCount || 0;
						}
						break;
					}
				}
			},

			// 处理加载更多
			async handleLoadMore(page) {
				if (this.currentSelectField && this.hasMoreData && !this.modalLoading) {
					this.modalLoading = true;
					try {
						await this.loadOptionsData(this.currentSelectField, page, this.searchKeyword);
					} catch (error) {
						console.error('加载更多数据失败:', error);
						uni.showToast({
							title: '加载失败',
							icon: 'none'
						});
					} finally {
						this.modalLoading = false;
					}
				}
			},

			// 处理刷新
			async handleRefresh() {
				if (this.currentSelectField) {
					this.currentPage = 1;
					this.hasMoreData = true;
					this.searchKeyword = '';
					await this.loadOptionsData(this.currentSelectField, 1);
				}
			},

			// 处理搜索
			async handleSearch(searchKeyword) {
				if (this.currentSelectField) {
					this.searchKeyword = searchKeyword;
					this.currentPage = 1;
					this.hasMoreData = true;
					this.modalLoading = true;

					try {
						await this.loadOptionsData(this.currentSelectField, 1, searchKeyword);
					} catch (error) {
						console.error('搜索失败:', error);
						uni.showToast({
							title: '搜索失败',
							icon: 'none'
						});
					} finally {
						this.modalLoading = false;
					}
				}
			},

			// 获取会员选项
			async getMemberOptions(page = 1, searchKeyword = '') {
				try {
					const params = {
						currentPage: page,
						pageSize: this.pageSize
					};

					if (searchKeyword) {
						params.keyword = searchKeyword;
					}

					const result = await memberApi.getMemberList(params);
					if (result.code === 200 && result.data) {
						return result.data.list.map((item, index) => ({
							value: item.id,
							label: item.khmc,
							sjh: item.sjh,
							khlxName: item.khlxName,
							khlx: item.khlx,
							subtitle: '客户类型:' + (item.khlxName || '无') + ';手机号:' + (item.sjh || '无') +
								';健康师:' + (item.mrsName || '无') + ';门店:' + (item.gsmdName || '无') + ';',
						}));
					}
					return [];
				} catch (error) {
					console.error('获取会员列表出错:', error);
					return [];
				}
			},

			// 获取转卡品项选项(转出会员的剩余品项)
			async getTransferItemOptions(page = 1, searchKeyword = '') {
				try {
					// 需要先选择转出会员才能获取剩余品项
					if (!this.selectedValues.fromMember) {
						uni.showToast({
							title: '请先选择转出会员',
							icon: 'none'
						});
						return [];
					}

					const params = {
						memberId: this.selectedValues.fromMember,
						currentPage: page,
						pageSize: this.pageSize
					};

					if (searchKeyword) {
						params.itemName = searchKeyword;
					}

					const result = await lxApi.getMemberRemainingItems(params);
					if (result.code === 200 && result.data) {
						return result.data.RemainingItems
							.filter(item => (item.RemainingCount || 0) > 0) // 只返回有剩余数量的品项
							.map((item, index) => ({
								value: item.BillingItemId,
								label: item.ItemName,
								itemPrice: item.ItemPrice || 0,
								RemainingCount: item.RemainingCount || 0,
								subtitle: '剩余: ' + (item.RemainingCount || 0) + ';类型:' + item.SourceType +
									';单价:' + item.ItemPrice +';备注:' + (item.Remark || '无')+ ';'
							}));
					}
					return [];
				} catch (error) {
					console.error('获取转出会员剩余品项出错:', error);
					return [];
				}
			},

			// 签字相关方法
			handleSignatureConfirm(signatureData) {
				this.signatureFile = signatureData.dataUrl;
				this.showSignatureModal = false;
				this.enablePageScroll();
				uni.showToast({
					title: '签字确认成功',
					icon: 'success'
				});
			},

			handleSignatureClear() {
				this.signatureFile = '';
			},

			clearSignature() {
				this.signatureFile = '';
				if (this.$refs.signaturePadModal) {
					this.$refs.signaturePadModal.clearSignature();
				}
				uni.showToast({
					title: '签字已清除',
					icon: 'success'
				});
			},

			// 全屏签字相关方法
			openSignatureModal() {
				this.showSignatureModal = true;
				this.disablePageScroll();
			},

			closeSignatureModal() {
				this.showSignatureModal = false;
				this.enablePageScroll();
			},

			previewSignature(e) {
				console.log('previewSignature', e);
				uni.previewImage({
					urls: [e]
				});
			},

			// 禁止页面滚动
			disablePageScroll() {
				this.scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
				document.body.style.overflow = 'hidden';
				document.body.style.position = 'fixed';
				document.body.style.width = '100%';
				document.body.style.top = `-${this.scrollTop}px`;
			},

			// 恢复页面滚动
			enablePageScroll() {
				document.body.style.overflow = '';
				document.body.style.position = '';
				document.body.style.width = '';
				document.body.style.top = '';
				if (this.scrollTop !== undefined) {
					window.scrollTo(0, this.scrollTop);
				}
			},

			// 表单提交
			handleFormSubmit(event) {
				event.preventDefault();
				this.submitTransfer();
			},

			// 表单验证
			validateForm() {
				// 验证转出会员
				if (!this.selectedValues.fromMember) {
					uni.showToast({
						title: '请选择转出会员',
						icon: 'none'
					});
					return false;
				}

				// 验证转入会员
				if (!this.selectedValues.toMember) {
					uni.showToast({
						title: '请选择转入会员',
						icon: 'none'
					});
					return false;
				}

				// 验证转出会员和转入会员不能相同
				if (this.selectedValues.fromMember === this.selectedValues.toMember) {
					uni.showToast({
						title: '转出会员和转入会员不能相同',
						icon: 'none'
					});
					return false;
				}

				// 验证转卡品项
				if (!this.transferItems || this.transferItems.length === 0) {
					uni.showToast({
						title: '请至少添加一个转卡品项',
						icon: 'none'
					});
					return false;
				}

				// 验证每个转卡品项
				for (let i = 0; i < this.transferItems.length; i++) {
					const item = this.transferItems[i];
					console.error(item)
					// 验证品项是否选择
					if (!item.billingItemId) {
						uni.showToast({
							title: `第${i + 1}个转卡品项请选择品项`,
							icon: 'none'
						});
						return false;
					}

					// 验证数量
					if (!item.transferQuantity || parseInt(item.transferQuantity) <= 0) {
						uni.showToast({
							title: `第${i + 1}个转卡品项数量必须大于0`,
							icon: 'none'
						});
						return false;
					}
					// 验证剩余数量不能超过剩余数量
					if (item.RemainingCount && parseInt(item.transferQuantity) > item.RemainingCount) {
						uni.showToast({
							title: `第${i + 1}个转卡品项剩余数量不能超过剩余数量`,
							icon: 'none'
						});
						return false;
					}
				}

				// 验证签字
				// if (!this.signatureFile) {
				// 	uni.showToast({
				// 		title: '请进行签字',
				// 		icon: 'none'
				// 	});
				// 	return false;
				// }

				return true;
			},

			// 上传签字文件
			async uploadSignatureFile() {
				try {
					const result = await lxApi.UploadBase64Image({
						"base64Data": this.signatureFile,
						"imageType": "png",
						"fileName": "transferSignature.png"
					});
					
					if (result.code == 200) {
						return result.data;
					}
					return null;
				} catch (error) {
					console.error('上传签字文件失败:', error);
					return null;
				}
			},

			// 提交转卡
			async submitTransfer() {
				try {
					// 验证表单
					if (!this.validateForm()) {
						return;
					}

					this.isSubmitting = false;
					uni.showLoading({
						title: '正在提交...'
					});
					let hyqz = []
					if(this.signatureFile) {
						let memberinfo = await this.uploadSignatureFile()
						console.error(memberinfo)
						if (memberinfo) {
							hyqz.push({
								name: memberinfo.name,
								fileId: memberinfo.name,
								url: memberinfo.url
							});
						}
					}
					

					// 准备提交数据
					const transferData = {
						fromMemberId: this.selectedValues.fromMember,
						toMemberId: this.selectedValues.toMember,
						signatureFile: JSON.stringify(hyqz),
						transferItems: this.transferItems.map(item => ({
							billingItemId: item.billingItemId,
							transferQuantity: parseInt(item.transferQuantity),
							itemName: item.itemName,
							itemPrice: parseFloat(item.itemPrice)
						})),
						remarks: this.formData.remarks,
						storeId: this.userInfo.mdid
					};

					console.log('transferData', transferData);
					// return;
					// 调用转卡接口
					const result = await lxApi.transferCard(transferData);
					uni.hideLoading();

					if (result.code == 200) {
						uni.showToast({
							title: '转卡成功!',
							icon: 'success'
						});
						this.clearForm();
						// 返回上一页
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 1500);
					} else {
						uni.showToast({
							title: result.msg || '转卡失败!',
							icon: 'none'
						});
					}
					this.isSubmitting = true;

				} catch (error) {
					uni.hideLoading();
					console.error('转卡失败:', error);
					uni.showToast({
						title: '网络错误,请稍后重试',
						icon: 'none'
					});
					this.isSubmitting = true;
				}
			},

			// 清空表单
			clearForm() {
				this.formData = {
					fromMemberId: '',
					fromMemberName: '',
					toMemberId: '',
					toMemberName: '',
					remarks: ''
				};

				this.selectedValues = {
					fromMember: null,
					toMember: null
				};

				this.transferItems = [];
				this.signatureFile = '';
				if (this.$refs.signaturePadModal) {
					this.$refs.signaturePadModal.clearSignature();
				}

				// 重新添加默认转卡品项
				this.addTransferRow();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.transfer-container {
		min-height: 100vh;
		background: linear-gradient(135deg, #e8f5e9 0%, #b2dfdb 100%);
		padding: 20rpx;
	}

	.form-card {
		background: #fff;
		border-radius: 36rpx;
		box-shadow: 0 8rpx 48rpx 0 rgba(76, 175, 80, 0.10);
		border: 3rpx solid #c8e6c9;
		overflow: hidden;
	}

	.form-content {
		padding: 48rpx;
	}

	.form-group {
		margin-bottom: 40rpx;
	}

	.form-group:last-child {
		margin-bottom: 0;
	}

	.form-label {
		display: block;
		margin-bottom: 16rpx;
		font-weight: bold;
		color: #388e3c;
		letter-spacing: 2rpx;
		font-size: 28rpx;
	}

	.input-wrapper {
		position: relative;
	}

	.custom-select {
		position: relative;
		background: #f9fff9;
		border: 3rpx solid #c8e6c9;
		border-radius: 20rpx;
		padding: 24rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		cursor: pointer;
		z-index: 10;
		min-height: 80rpx;
		box-sizing: border-box;
	}

	.select-text {
		font-size: 28rpx;
		color: #2e7d32;
		flex: 1;
	}

	.select-arrow {
		position: absolute;
		right: 24rpx;
		top: 50%;
		transform: translateY(-50%);
		color: #6a9c6a;
		font-size: 24rpx;
		pointer-events: none;
	}

	.textarea-input {
		background: #f9fff9;
		border: 3rpx solid #c8e6c9;
		border-radius: 20rpx;
		padding: 24rpx;
		font-size: 28rpx;
		color: #2e7d32;
		min-height: 200rpx;
		box-sizing: border-box;
		width: 100%;
	}

	/* 转卡品项相关样式 */
	.transfer-container {
		margin-bottom: 32rpx;
	}

	.transfer-row {
		display: flex;
		flex-direction: column;
		gap: 24rpx;
		margin-bottom: 32rpx;
		padding: 32rpx;
		border: 2rpx solid #e0e0e0;
		border-radius: 20rpx;
		background: #fafafa;
	}

	.transfer-row-first {
		display: flex;
		gap: 24rpx;
		align-items: center;
	}

	.transfer-row-second {
		display: flex;
		gap: 16rpx;
		align-items: center;
		width: 100%;
	}

	.transfer-select {
		flex: 1;
		padding: 24rpx;
		border: 3rpx solid #c8e6c9;
		border-radius: 20rpx;
		font-size: 28rpx;
		background: #f9fff9;
		color: #2e7d32;
		cursor: pointer;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.transfer-count {
		min-width: 80rpx;
		padding: 20rpx;
		border: 3rpx solid #c8e6c9;
		border-radius: 20rpx;
		font-size: 26rpx;
		background: #f9fff9;
		color: #2e7d32;
		text-align: center;
	}

	.transfer-unit-price {
		display: flex;
		align-items: center;
		gap: 8rpx;
		padding: 16rpx 0;
		background: #e8f5e9;
		border-radius: 12rpx;
		border: 2rpx solid #c8e6c9;
		width: 30%;
		justify-content: center;
		text-align: center;
	}

	.price-value {
		font-size: 24rpx;
		color: #1b5e20;
		font-weight: bold;
	}

	.transfer-delete {
		width: 20%;
		padding: 16rpx 0;
		border-radius: 20rpx;
		background: #f5f5f5;
		color: #666;
		font-size: 22rpx;
	}

	.btn-add-transfer {
		width: 100%;
		padding: 10rpx 40rpx;
		border: 3rpx solid #43a047;
		border-radius: 20rpx;
		background: #e8f5e9;
		color: #2e7d32;
		font-size: 28rpx;
		font-weight: bold;
	}

	.btn-group {
		display: flex;
		gap: 24rpx;
		margin-top: 48rpx;
	}

	.btn {
		flex: 1;
		padding: 10rpx 40rpx;
		border: none;
		border-radius: 20rpx;
		font-size: 28rpx;
		font-weight: bold;
		cursor: pointer;
		transition: all 0.2s ease;
		letter-spacing: 2rpx;
	}

	.btn-primary {
		background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
		color: #fff;
		box-shadow: 0 4rpx 16rpx rgba(67, 233, 123, 0.3);
	}

	.btn-primary:hover {
		box-shadow: 0 8rpx 32rpx rgba(67, 233, 123, 0.4);
		transform: translateY(-2rpx);
	}

	/* 签字相关样式 */
	.signature-preview {
		margin-top: 24rpx;
		padding: 24rpx;
		background: #f9fff9;
		border: 2rpx solid #c8e6c9;
		border-radius: 16rpx;
	}

	.preview-label {
		display: block;
		font-size: 26rpx;
		color: #2e7d32;
		font-weight: bold;
		margin-bottom: 16rpx;
	}

	.signature-image {
		width: 100%;
		max-width: 300rpx;
		height: 120rpx;
		border: 2rpx solid #e0e0e0;
		border-radius: 12rpx;
		background: #fff;
		margin-bottom: 16rpx;
	}

	.signature-actions {
		display: flex;
		gap: 16rpx;
		margin-top: 16rpx;
	}

	.btn-re-signature {
		flex: 1;
		padding: 12rpx 24rpx;
		background: #2e7d32;
		color: #fff;
		border: none;
		border-radius: 12rpx;
		font-size: 24rpx;
		font-weight: 500;
		cursor: pointer;
		transition: all 0.2s ease;
	}

	.btn-re-signature:hover {
		background: #1b5e20;
	}

	.btn-clear-signature {
		flex: 1;
		padding: 12rpx 24rpx;
		background: #f5f5f5;
		color: #666;
		border: 2rpx solid #ddd;
		border-radius: 12rpx;
		font-size: 24rpx;
		font-weight: 500;
		cursor: pointer;
		transition: all 0.2s ease;
	}

	.btn-clear-signature:hover {
		background: #e0e0e0;
	}

	/* 签字占位符样式 */
	.signature-placeholder {
		display: flex;
		justify-content: center;
		align-items: center;
		min-height: 200rpx;
		border: 2rpx dashed #c8e6c9;
		border-radius: 16rpx;
		background: #f9fff9;
	}

	.btn-signature-placeholder {
		background: #2e7d32;
		color: #fff;
		border: none;
		border-radius: 16rpx;
		font-size: 28rpx;
		font-weight: 500;
		cursor: pointer;
		transition: all 0.2s ease;
		box-shadow: 0 4rpx 16rpx rgba(46, 125, 50, 0.3);
	}

	.btn-signature-placeholder:hover {
		background: #1b5e20;
		transform: translateY(-2rpx);
		box-shadow: 0 8rpx 32rpx rgba(46, 125, 50, 0.4);
	}

	.signature-placeholder-text {
		color: #fff;
	}

	/* 全屏签字弹窗样式 */
	.signature-modal-overlay {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.7);
		z-index: 9999;
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
	}

	.signature-modal {
		width: 100%;
		background: #fff;
		overflow: hidden;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.signature-modal-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 40rpx;
		background: #f8f9fa;
		border-bottom: 2rpx solid #e9ecef;
	}

	.signature-modal-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #2e7d32;
	}

	.btn-close-modal {
		width: 60rpx;
		height: 60rpx;
		background: #f5f5f5;
		border: none;
		border-radius: 50%;
		font-size: 36rpx;
		color: #666;
		display: flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
		transition: all 0.2s ease;
		margin: 0;
	}

	.btn-close-modal:hover {
		background: #e0e0e0;
		color: #333;
	}

	.signature-modal-content {
		background: #fff;
		flex: 1;
		width: 100%;
	}

	/* 全屏模式下SignaturePad组件样式调整 */
	.signature-modal-content .signature-container {
		height: 100%;
		border: none;
		border-radius: 0;
		box-shadow: none;
	}

	.signature-modal-content .signature-header {
		padding: 20rpx 30rpx;
		background: #f8f9fa;
		border-bottom: 2rpx solid #e9ecef;
	}

	.signature-modal-content .signature-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #2e7d32;
	}

	.signature-modal-content .btn-clear,
	.signature-modal-content .btn-confirm {
		padding: 16rpx 32rpx;
		font-size: 28rpx;
		font-weight: 500;
		border-radius: 12rpx;
	}

	.signature-modal-content .btn-clear {
		background: #f5f5f5;
		color: #666;
		border: 2rpx solid #ddd;
	}

	.signature-modal-content .btn-clear:hover {
		background: #e0e0e0;
		color: #333;
	}

	.signature-modal-content .btn-confirm {
		background: #2e7d32;
		color: #fff;
		border: none;
	}

	.signature-modal-content .btn-confirm:hover {
		background: #1b5e20;
		transform: translateY(-2rpx);
	}

	.signature-modal-content .signature-pad {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 20rpx;
	}

	.signature-modal-content .signature-tips {
		padding: 20rpx;
		text-align: center;
		background: #f8f9fa;
		border-top: 2rpx solid #e9ecef;
	}

	.signature-modal-content .tips-text {
		font-size: 24rpx;
		color: #666;
	}

	// @media (max-width: 750rpx) {
	// 	.form-content {
	// 		padding: 40rpx;
	// 	}

	// 	.transfer-row-second {
	// 		gap: 16rpx;
	// 	}

	// 	.signature-preview {
	// 		padding: 20rpx;
	// 	}

	// 	.preview-label {
	// 		font-size: 24rpx;
	// 	}

	// 	.signature-image {
	// 		max-width: 250rpx;
	// 		height: 100rpx;
	// 	}

	// 	.btn-clear-signature {
	// 		padding: 10rpx 20rpx;
	// 		font-size: 22rpx;
	// 	}
	// }
</style>