detail_owner_invitation14.js 50.7 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 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
// pack-invitation/pages/detail_owner_invitation14.js
var mta = require('mta-wechat-analysis')
import util from '../../utils/util';
import App from '../../utils/api';
import TP from '../../utils/tpls';
import RS from '../../utils/reserveStatus'
import inviteBase from '../common/inviteBase';
import convertSolarLunar from '../../components/calendar/func/convertSolarLunar';

/** 农历:正月初七(解析失败返回空) */
function getLunarText(ddate) {
	if (!ddate) return '';
	const time = new Date(ddate * 1000);
	const lunar = convertSolarLunar.solar2lunar(time.getFullYear(), time.getMonth() + 1, time.getDate());
	if (!lunar || lunar === -1) return '';
	return lunar.IMonthCn + lunar.IDayCn;
}

/** 用餐日期:2027-02-14 星期六 正月初七 */
function formatInviteDate(ddate) {
	if (!ddate) return '';
	const datePart = util.unixtoTime(ddate, 'YYYY-MM-DD');
	const weekPart = util.unixtoTime(ddate, '星期WW');
	const time = new Date(ddate * 1000);
	const lunar = convertSolarLunar.solar2lunar(
		time.getFullYear(),
		time.getMonth() + 1,
		time.getDate()
	);
	if (!lunar || lunar === -1) {
		return `${datePart} ${weekPart}`;
	}
	return `${datePart} ${weekPart} ${lunar.IMonthCn}${lunar.IDayCn}`;
}

Page({
	...inviteBase,
	/**
	 * 页面的初始数据
	 */
	data: {
		barShow: false, //底部操作栏是否显示
		showMoreOnline: false, //再次预订-在线
		showMoreCall: false, //再次预订-电话
		canPay: false, //支付定金
		canShare: false, //转发邀请函
		isOver: false, //已结束/完成
		isOwner: false, //商家(发起人)视角
		canMeet: false, //客人可确认赴约
		needLogin: true, //确认赴约需先登录/授权
		guestShareCls: 'shareItem shareItem1', //客人转发按钮样式
		threeBtnMore: '', //3按钮布局(在线再次预订)
		threeBtnCall: '', //3按钮布局(电话再次预订)
		threeBtnPay: '', //3按钮布局(支付定金)
		themeImg: '',
		heroBottomStripImage: '',
		heroHeightPx: 410,
		contentStartPx: 350,
		windowHeight: 667,
		canChangeBg: '0', // 模拟:1可换/存背景图,0不可
		customThemeImg: '', // 用户本地更换的背景图
		savedBgImageUrl: '', // 已保存到七牛的地址
		bgSaved: false, // 当前预订是否已保存过背景图
		themeColor: 'pearlWhite',
		pageThemeClass: 'pagewhite',
		entranceIcon: 1,
		actionIcon: 1,
		titleObj: {}, //大标题:色/号可配;书法仅固定文案「预订安排|邀请函」
		shopObj: {}, //店名:色/号可配;字体由样式固定(不可换字体)
		titleCls: '', //大标题字体/字号 class
		shopCls: '', //店名字体/字号/换行 class
		titleStyle: '', //大标题内联色
		shopStyle: '', //店名内联色
		StyleTypeNum: 1, //样式1234
		titleInfo: [], //预订信息配置(接口未就绪,先用死数据)
		mealName: '', //多时段餐段名(getLocalLunchTime 回填,{餐段} 用它)
		titleRows: [], //预订信息行(样式1/3 按配置顺序渲染)
		titleRowMap: {}, //按字段类型索引(样式2/4 固定位置用)
		speakImgMode: '1', // 商家有话说图片:0平铺 1轮播(餐厅介绍/招牌菜品/主厨介绍)
		isCustom: '0', // 1自定义白字,0主题色
		options: {
			tplid: ''
		},
		detail: {},
		staffinfo: {},
		chef: {},
		marketing: {},
		home: {},
		reserve: {},
		signboard: {},
		store: {},
		recharge_data: [],
		coupon_dataList: [],
		seller: {
			name: '',
			tablesText: '',
			date: '',
			addr: ''
		},
		contactPhone: '',
		dataStr: Date.now() * 1 / 1000,
		swich_phone: '0',
		is_comments: '0',
		is_user_comments: false,
		roomimage: [],
		StyleType: '',
		showMoreTip: true,
		hasValueOrder: false, //商家是否开通提前点餐功能
		hasValueCertificate: false, //商家是否开通优惠券功能
		hasValueRecharge: false, //商家是否开通充值功能
		_attentionAnim: {},
		isPlay: '1',
		paymentStatus: '', //定金支付状态 1支付 0未支付
		reserveData: {}, //自定义图文数据
		showMerchantSpeak: false, // 商家有话说(自定义图文/餐厅/菜品/主厨任一有内容)
		toastBool: false, //支付定金提示框
		paymentId: '', //定金id
		wxml: null,
		imgSrc: '', //canvas图片地址
		couponData: '', //评价赠送优惠券数据
		timeList: [],
		index: 0,
		isMany: '0', //0默认餐段 1多时段
		temp_ddate: '', //展示的到店时间
		lite_style: '', //小程序转发卡片样式
		isMoreBtn: '', //再次预订按钮
		isPaymenBtn: '', //支付定金按钮
		isShareItem: '', //转发客人按钮
		couponArr: [], //待领取的优惠券列表
		couponList: [], //优惠券列表
		urlsArr: [], //包间预览图片
		animationData: {},
		animationData2: {},
		isShow: '0',
		isFrame: '0',
		isShowBtn: true, //是否展示赴约按钮
		purePhoneNumber: '', //当前人手机号
		wxNickname: '', //微信昵称
		wxAvatar: '', //微信头像
		reserveOpenid: '', //预订人的openid
		openid: getApp().openid,
		customersList: [], //预订人
		countDown: 5, //5秒后自动关闭弹框
		timer: null,
	},
	tablestr: '',
	screenHeight: '',
	attentionAnim: {},
	audioCtx: '', //播报
	timers: null, // 动画定时器
	n: 0,
	modal: '',
	couponModal: '',
	give_user: '',
	one: '0', //在邀请函页面,只弹领券框一次
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.id = options.id
		let param = {
			options: options,
			hasOwner: options.hasSellerShare == 1, //是否为发起人
		}
		param.tpls = [TP.tpls(options.tplid)]
		console.log(param);
		console.log(options);
		this.setData(param)
		mta.Page.init({
			"appID": "500667280",
			"eventID": "500667287",
			"statPullDownFresh": true,
			"statShareApp": true,
			"statReachBottom": true,
			"lauchOpts": options, //渠道分析
		});
		this.calculateLayout();
		const systemInfo = wx.getSystemInfoSync();
		this.screenHeight = systemInfo.windowHeight; // 获取屏幕高度
		this.setData({
			windowHeight: systemInfo.windowHeight || 667,
		});
		this.modal = this.selectComponent("#payModal"); //通过给组件所起的id调用组件
		this._onUserCaptureScreen = () => {
			this.modal && this.modal.showModal();
		};
		wx.onUserCaptureScreen(this._onUserCaptureScreen);
		this.couponModal = this.selectComponent("#couponModal");
		this.loadLocalFonts();
	},
	/**
	 * 外部字体:https ttf(downloadFile 合法域名需含 nosqn.colorcun.com)
	 */
	loadLocalFonts() {
		// 标题用三套 7 字极小包;店名走系统字体,不加载大字库
		const fonts = [{
				family: 'Noto Serif SC',
				url: 'https://nosqn.colorcun.com/NotoSerif_title.ttf',
				weight: 700,
			},
			{
				family: 'Noto Sans SC',
				url: 'https://nosqn.colorcun.com/NotoSans_title.ttf',
				weight: 700,
			},
			{
				family: 'XuanZongTi',
				url: 'https://nosqn.colorcun.com/xinkaiti_title.ttf',
				weight: 400,
			},
		];
		fonts.forEach((item) => {
			wx.loadFontFace({
				family: item.family,
				global: true,
				source: `url("${item.url}")`,
				scopes: ['webview', 'native'],
				desc: {
					style: 'normal',
					weight: String(item.weight),
				},
				success: () => console.log('font ok', item.family),
				fail: (err) => console.warn('font skip', item.family, err && err.errMsg),
			});
		});
	},
	/** 大标题是否为固定文案(预订安排 / 邀请函);空则按兜底算固定 */
	isFixedTitleText(text) {
		const t = (text == null ? '' : String(text)).trim();
		return !t || t === '预订安排' || t === '邀请函';
	},
	/** 按样式解析标题/店名 class 与内联色 */
	buildTitleShopStyle(StyleTypeNum, titleObj, shopObj) {
		titleObj = titleObj || {};
		shopObj = shopObj || {};
		const styleNum = String(StyleTypeNum || '1');
		const shopText = shopObj.textInfo || this.data.seller.name || (this.data.reserve && this.data.reserve.seller_name) || '';
		let titleCls = '';
		let shopCls = '';
		let titleStyle = '';
		let shopStyle = '';

		// 店名:各样式固定字体族,可换字号/颜色;忽略 shopObj.textFont
		if (styleNum === '4') {
			shopCls = 'shopFontPing';
		} else {
			shopCls = 'shopFont1'; // 样式1/2/3 黑体
		}
		if (shopObj.textFontSize) shopCls = (shopCls + ' shopSize' + shopObj.textFontSize).trim();
		if (shopObj.textFontSize == '1' && shopText.length > 11) shopCls = (shopCls + ' shopWrap').trim();
		if (shopObj.textColor) shopStyle = 'color:' + shopObj.textColor;

		// 大标题:样式1~4 同一套可配(字体/字号/颜色);自定义文案禁用书法
		const fixedTitle = this.isFixedTitleText(titleObj.textInfo);
		let fontKey = titleObj.textFont ? String(titleObj.textFont) : '';
		if (fontKey === '3' && !fixedTitle) fontKey = '1'; // 自定义文案 → 系统默认黑体
		if (fontKey === '1' || fontKey === '2' || fontKey === '3') titleCls = 'titleFont' + fontKey;
		if (titleObj.textFontSize) titleCls = (titleCls + ' titleSize' + titleObj.textFontSize).trim();
		if (titleObj.textColor) titleStyle = 'color:' + titleObj.textColor + ';-webkit-text-fill-color:' + titleObj.textColor + ';background-image:none;';
		return {
			titleCls,
			shopCls,
			titleStyle,
			shopStyle
		};
	},
	calculateLayout() {
		const info = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync();
		const width = info.windowWidth || 375;
		const heroHeightPx = Math.round(width * 1.08);
		this.setData({
			heroHeightPx,
			contentStartPx: Math.round(width * 0.92),
			windowHeight: info.windowHeight || 667,
		});
	},
	// 主题图候选:自定义图 → 包间首图 → 餐厅首图 → 门头照
	getThemeImgCandidates() {
		const roomimage = this.data.roomimage;
		const home = this.data.home;
		const marketing = this.data.marketing;
		const list = [];
		if (this.data.customThemeImg) list.push(this.data.customThemeImg);
		const roomFirst = roomimage && roomimage.length > 0 && roomimage[0] && roomimage[0].url;
		if (roomFirst) list.push(roomFirst);
		if (home && home.image) list.push(home.image);
		if (marketing && marketing.logo) list.push(marketing.logo);
		return list.filter((url, i) => url && list.indexOf(url) === i);
	},
	resolveThemeImg() {
		const failed = this._failedThemeImgs || {};
		let themeImg = this.getThemeImgCandidates().find(url => !failed[url]) || '';
		if (!themeImg) {
			themeImg = 'https://qn.colorcun.com/testImg/img4.png';
		}
		if (themeImg !== this.data.themeImg) {
			this.setData({
				themeImg
			});
		}
		return themeImg;
	},
	// 换照片:选本地图直接设为背景(与现有主题图/模糊底逻辑一致)
	onChangeBgPhoto() {
		if (this.data.bgSaved) {
			wx.showToast({
				title: '已保存,不可再更换',
				icon: 'none'
			});
			return;
		}
		// 选图前若正在播报则先暂停;选完/取消后再恢复
		this._skipOnShowRefresh = true;
		this.pauseAudioBeforeMediaPick();
		wx.chooseMedia({
			count: 1,
			mediaType: ['image'],
			sourceType: ['album', 'camera'],
			success: (res) => {
				const file = res.tempFiles && res.tempFiles[0];
				const path = file && (file.tempFilePath || file.path);
				if (!path) return;
				if (this._failedThemeImgs) {
					delete this._failedThemeImgs[path];
				}
				// 换照片后按自定义:白色主题
				this.setData({
					customThemeImg: path,
					themeImg: path,
					heroBottomStripImage: '',
					isCustom: '1',
					themeColor: 'pearlWhite',
					pageThemeClass: 'pagewhite',
					entranceIcon: 1,
					actionIcon: 1,
				});
			},
			complete: () => {
				setTimeout(() => {
					this.resumeAudioAfterMediaPick();
					this._skipOnShowRefresh = false;
				}, 300);
			},
		});
	},
	// 进相册前:正在播则暂停播报并停图标旋转
	pauseAudioBeforeMediaPick() {
		const playing = this.data.isPlay == '1' || (this.audioCtx && !this.audioCtx.paused);
		this._needResumeAudio = playing ? true : false;
		if (!playing) return;
		clearInterval(this.timers);
		if (this.audioCtx && typeof this.audioCtx.pause === 'function') {
			try {
				this.audioCtx.pause();
			} catch (e) {
				console.log('pauseAudioBeforeMediaPick', e);
			}
		}
		this.setData({
			isPlay: '2'
		});
	},
	// 选图结束(成功或取消):若进相册前在播,则继续播放
	resumeAudioAfterMediaPick() {
		if (!this._needResumeAudio) return;
		this._needResumeAudio = false;
		if (!this.audioCtx || typeof this.audioCtx.play !== 'function') return;
		try {
			this.audioCtx.play();
			this.setData({
				isPlay: '1'
			});
			if (typeof this.animation === 'function') {
				clearInterval(this.timers);
				this.animation();
			}
		} catch (e) {
			console.log('resumeAudioAfterMediaPick', e);
		}
	},
	// 保存图片:上传七牛 → 提交后端(后端接口先占位)
	onSaveBgPhoto() {
		if (this.data.bgSaved) {
			wx.showToast({
				title: '只能保存一次',
				icon: 'none'
			});
			return;
		}
		if (!this.data.customThemeImg) {
			wx.showToast({
				title: '请先更换照片',
				icon: 'none'
			});
			return;
		}
		if (this._savingBg) return;
		this._savingBg = true;
		wx.showLoading({
			title: '保存中',
			mask: true
		});
		App.Qiniu.GetUploadToken().then(res => {
			const token = res.data && res.data.token;
			if (!token) {
				return Promise.reject('token empty');
			}
			return util.uploadFile(this.data.customThemeImg, token, 'invitationNew');
		}).then(imageUrl => {
			console.log('七牛背景图地址', imageUrl);
			return this.saveInviteBgImage(imageUrl).then(() => imageUrl);
		}).then(imageUrl => {
			// 展示仍用本地图,避免切换七牛地址时重新加载黑一下
			this.setData({
				bgSaved: true,
				savedBgImageUrl: imageUrl,
			});
			wx.hideLoading();
			this._savingBg = false;
			wx.showToast({
				title: '保存成功',
				icon: 'success'
			});
		}).catch(err => {
			console.log('保存背景图失败', err);
			wx.hideLoading();
			this._savingBg = false;
			wx.showToast({
				title: '保存失败',
				icon: 'none'
			});
		});
	},
	// 上传背景图到后端(接口未就绪,先占位)
	saveInviteBgImage(imageUrl) {
		console.log('saveInviteBgImage 待接后端', {
			rid: this.id || (this.data.options && this.data.options.id),
			imageUrl,
		});
		// TODO: 后端接口就绪后改为真实请求,例如:
		// return App.Reserve.SaveInviteBgImage({
		//     rid: this.id || this.data.options.id,
		//     image: imageUrl,
		// });
		return Promise.resolve({
			ret: 200,
			data: {
				imageUrl
			}
		});
	},
	// scroll-view 滚动:控制「滑动查看更多」提示
	onScrollViewScroll(event) {
		const scrollTop = (event.detail && event.detail.scrollTop) || 0;
		const tipTop = scrollTop * 1 + this.screenHeight - 80;
		if (tipTop < this.screenHeight) {
			this.setData({
				showMoreTip: true
			});
		} else {
			this.setData({
				showMoreTip: false
			});
		}
	},
	// 去评价
	evaluateFun() {
		let url = util.http_build_query({
			sellerName: this.data.seller.name,
			sellerid: this.data.seller.sid,
			oid: this.data.detail.id,
			types: '1',
			previousPage: '1',
		}, '/pages/pinglun/createOpinion')
		wx.navigateTo({
			url
		})
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		if (this._skipOnShowRefresh) {
			// 部分机型 onShow 早于 complete,这里再补一次恢复
			setTimeout(() => {
				this.resumeAudioAfterMediaPick();
			}, 300);
			return;
		}
		this.getDetail()
		this.getText()
		this.getPaymentStatus()
		this.getCheckUserHavePhone()
		this.getreal()
	},
	// 获取包间图片列表
	getroomimage(sellerid) {
		App.Tables.GetTablesPhoto({
			sellerid,
			tableids: this.tablestr
		}).then((json) => {
			console.log('客户经理获取基本信息------', json.data)
			if (json.ret == 200) {
				var urlsArr = [];
				(json.data || []).forEach((v) => {
					if (v && v.url) urlsArr.push(v.url);
				})
				this.setData({
					roomimage: json.data || [],
					urlsArr,
				}, () => this.resolveThemeImg())
				console.log('包间图片地址urlsArr', urlsArr)
				console.log('包间信息roomimage', json.data)
			}
		})
	},
	// 获取店铺详情
	getDetail() {
		App.Reserve.Detail({
			rid: this.data.options.id
		}).then(res => {
			let tablesText = '', //桌子信息
				deskStr = '';
			const tables = (res.data.tables && Array.isArray(res.data.tables)) ? res.data.tables : [];
			tables.forEach((t, i) => {
				tablesText += t.rname + t.name + (i == (tables.length - 1) ? '' : '、');
				deskStr += t.name + (i == (tables.length - 1) ? '' : '、');
			})
			let tabaleids = [];
			tables.forEach(t => {
				tabaleids.push(t.id);
			})
			this.tablestr = tabaleids.toString();
			let reserev = RS.reserve(res.data)
			let dateSmart = formatInviteDate(reserev.ddate);
			let yearMonthDay = util.unixtoTime(reserev.ddate, 'YYYY年MM月DD日')
			let yearMonth = util.unixtoTime(reserev.ddate, 'MM月DD日')
			let dateStr = util.unixtoTime(reserev.ddate, 'HH点')
			let dateStrDivide = util.unixtoTime(reserev.ddate, 'II分')
			let detail = this.formatDatail(reserev, dateSmart)
			if (tables.length > 0) {
				detail.oneTableName = tables[0].name;
			}
			reserev.soltName = '';
			const sellerTel = (reserev.seller && reserev.seller.seller_tel) ? reserev.seller.seller_tel : '';
			this.setData({
				customersList: res.data.openid == getApp().openid ? (reserev.customers || []).slice(1) : [], //预订人返回,邀请人为空
				reserveOpenid: res.data.openid,
				detail,
				is_user_comments: res.data.is_user_comments,
				temp_ddate: this.data.temp_ddate ? this.data.temp_ddate : reserev.temp_ddate ? util.unixtoTime(reserev.temp_ddate, 'HH:II') : util.unixtoTime(reserev.ddate, 'HH:II'),
				seller: {
					daily: reserev.seller.daily,
					name: reserev.seller.sellername,
					sid: reserev.sid,
					date: dateSmart,
					tablesText,
					addr: reserev.seller.real_address || reserev.seller.map_address,
					image: reserev.image_url,
					hasOwner: true,
					type: reserev.type,
					is_set_ddate: reserev.is_set_ddate,
					hasUpTime: reserev.type == 1 && reserev.hasRunning && reserev.status != 2,
					tel: sellerTel ? sellerTel.split(',').filter(Boolean) : [],
					soltName: reserev.soltName || detail.mname,
					dateTime: util.unixtoTime(reserev.ddate, 'HH:II'),
					time: util.unixtoTime(reserev.ddate, '星期WW HH:II'),
					lat: reserev.seller.lat,
					long: reserev.seller.long,
					yearMonthDay,
					yearMonth,
					dateStr,
					deskStr,
					dateStrDivide: dateStrDivide == '00分' ? '' : dateStrDivide,
					seller_tel: sellerTel,
					phone: reserev.seller.phone,
				}
			})
			this.updateContactPhone();
			this.give_user = reserev.give_user ? reserev.give_user : '2';
			console.log('reserev信息', reserev);
			console.log('seller信息', this.data.seller);
			console.log('detail信息', this.data.detail);
			setTimeout(() => {
				this.getstaffinfo(res.data.uid, reserev.sid);
				this.getroomimage(reserev.sid)
				this.getSellerVersionFun(reserev.sid);
			}, 0);
		}).catch(res => {
			console.log(res, '详情请求失败');
		})
	},
	// 客户经理获取基本信息
	getstaffinfo(uid, sid) {
		console.log('sellerid', this.data.detail.seller.id);
		App.Activity.GetCustomerActivityBaseinfo({
			sellerid: this.data.detail.seller.id,
			uid
		}).then((json) => {
			if (json.ret == 200) {
				console.log('客户经理获取基本信息------', json.data)
				this.setData({
					staffinfo: json.data,
					couponArr: [],
				})
				this.updateContactPhone();
				this.getSellerTemplateConfFun(sid);
			}
		})
	},
	// 提前点餐
	cookbook() {
		const cookbooklist = this.data.detail.order && this.data.detail.order.cookbooklist;
		if (cookbooklist && cookbooklist.length > 0) {
			let data = {
				rid: this.id,
				oid: this.data.detail.order.id,
				sellerName: this.data.seller.name,
				sid: this.data.seller.sid,
				identity: '1',
				hasSuccess: '1',
			}
			wx.navigateTo({
				url: `/pack-cookbook/pages/success_new?hasSuccess=${data.hasSuccess}&identity=${data.identity}&oid=${data.oid}&rid=${data.rid}&sellerName=${data.sellerName}&sid=${data.sid}`,
			})
		} else {
			App.Advance.CreateOrder({
				rid: this.id,
			}).then(res => {
				if (res.ret != 200) {
					return util.toast(res.msg, 'none')
				}
				wx.navigateTo({
					url: util.http_build_query({
						rid: this.id,
						oid: res.data.id,
						sid: res.data.sellerid,
						sellerName: this.data.seller.name,
						identity: '1',
					}, '/pack-cookbook/pages/index_new')
				});
			})
		}
	},
	// 预订信息行:按 titleInfo 的 content 取对应字段(content 只配一个字段;未知字段/空值不显示该行)
	refreshTitleRows(tempDdate) {
		const info = this.data.titleInfo || [];
		const detail = this.data.detail || {};
		const seller = this.data.seller || {};
		const tables = (detail.tables && Array.isArray(detail.tables)) ? detail.tables : [];
		const ddateText = tempDdate || this.data.temp_ddate || '';
		const mealText = this.data.mealName || seller.soltName || '';
		const yearMonthDay = detail.ddate ? util.unixtoTime(detail.ddate, 'YYYY年MM月DD日') : '';
		const weekText = detail.ddate ? util.unixtoTime(detail.ddate, '星期WW') : '';
		const lunarText = getLunarText(detail.ddate);
		const regionText = tables.map(t => t.rname).filter((v, i, arr) => v && arr.indexOf(v) === i).join('、');
		const roomText = tables.map(t => t.name).filter((v, i, arr) => v && arr.indexOf(v) === i).join('、');
		let str = detail.sex == 1 ? '先生' : detail.sex == 2 ? '女士' : detail.sex == 4 ? '贵宾' : '';
		const valueMap = {
			'{姓名}': detail.rname || '',
			"{姓名+称呼}": detail.rname ? (detail.rname + str) : str == '贵宾' ? '贵宾' : '',
			'{公历}': yearMonthDay,
			'{公历+星期}': [yearMonthDay, weekText].filter(v => v).join(' '),
			'{公历+农历}': [yearMonthDay, lunarText].filter(v => v).join(' '),
			'{公历+星期+农历}': [yearMonthDay, weekText, lunarText].filter(v => v).join(' '),
			'{区域名}': regionText,
			'{包间名}': roomText,
			'{区域名+包间名}': seller.tablesText || '',
			'{餐段}': mealText,
			'{就餐时间}': ddateText,
			'{餐段+就餐时间}': [mealText, ddateText].filter(v => v).join(' '),
			'{前台电话}': (seller.tel && seller.tel.length) ? seller.tel.join(' ') : '',
		};
		const typeMap = {
			'{姓名}': 'name',
			'{姓名+称呼}': 'name',
			'{公历}': 'date',
			'{公历+星期}': 'date',
			'{公历+农历}': 'date',
			'{公历+星期+农历}': 'date',
			'{区域名}': 'place',
			'{包间名}': 'place',
			'{区域名+包间名}': 'place',
			'{餐段}': 'time',
			'{就餐时间}': 'time',
			'{餐段+就餐时间}': 'time',
			'{前台电话}': 'phone',
		};
		const rows = [];
		const rowMap = {};
		info.forEach(item => {
			if (!item || !item.content) return;
			const type = typeMap[item.content];
			if (!type) return;
			if (type === 'phone') {
				const values = (seller.tel || []).filter(v => v);
				if (!values.length || rowMap.phone) return;
				rowMap.phone = {
					text: item.text || '',
					content: item.content,
					type,
					value: values.join(' '),
					values,
				};
				return;
			}
			const value = valueMap[item.content] || '';
			if (!value) return;
			const row = {
				text: item.text || '',
				content: item.content,
				type,
				value,
			};
			if (!rowMap[type]) rowMap[type] = row;
			rows.push(row);
		});
		this.setData({
			titleRows: rows,
			titleRowMap: rowMap,
		});
	},

	// 改到店时间(同步 picker index)
	bindPickerChange(e) {
		this.setData({
			index: e.detail.value * 1
		});
		inviteBase.bindPickerChange.call(this, e);
		const timeList = this.data.timeList || [];
		this.refreshTitleRows(timeList[e.detail.value]);
	},
	// 去商家主页
	sharesettingShop() {
		wx.navigateTo({
			url: util.http_build_query({
				id: this.data.detail.seller.id
			}, '/pages/reserve/shopHome')
		});
	},
	// 分享
	sharesetting() {
		wx.reportMonitor('1017', 1)
		this.closeModal()
		if (this.data.options.isOrder == '1' && this.data.detail.status != '4') {
			let img = this.data.detail.seller.seller_image.replace(/^http:/, "https:");
			return {
				title: '推荐' + this.data.seller.name + ',点击可查看详情并导航到店',
				path: util.http_build_query({
					id: this.data.detail.seller.id
				}, '/pages/reserve/shopHome'),
				imageUrl: img || 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png',
			}
		} else {
			let parmdata = {
				id: this.id,
				fromid: getApp().openid,
				hasInvitation: 1,
				tplid: this.data.options.tplid
			}
			if (this.data.options.uid) {
				parmdata.uid = this.data.options.uid;
			}
			return {
				title: '我已订好' + this.data.seller.name + ',点击可查看详情并导航到店',
				path: util.http_build_query(parmdata, '/pages/customer/detail_owner_invitation_new'),
				imageUrl: this.data.imgSrc || 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png',
			}
		}
	},
	// 获取商家设置营销信息
	getSellerTemplateConfFun(sid) {
		console.log(sid, 'sidsidsidsid');
		App.Seller.GetSellerTemplateConf({
			sid
		}).then(res => {
			let data = res.data
			console.log('data', data);
			let couponList = []
			let StyleType, home, chef, marketing, coupon, coupon_data_pay, coupon_data_free, reserve, swich_phone, is_comments, signboard, store;
			chef = util.determine(data.chef);
			reserve = util.determine(data.reserve);
			marketing = this.normalizeMarketing(util.determine(data.marketing));
			signboard = util.determine(data.signboard);
			store = util.determine(data.store);
			home = util.determine(data.home);
			StyleType = data.type;
			swich_phone = reserve && reserve.swich_phone ? reserve.swich_phone : '0';
			if (store) store.content = (store.is_introduce_all == '1' && store.content) ? util.determine(store.content) : '';
			if (chef) chef.content = (chef.is_introduce_all == '1' && chef.content) ? util.determine(chef.content) : '';
			if (signboard) signboard.content = (signboard.is_introduce_all == '1' && signboard.content) ? util.determine(signboard.content) : '';
			if (reserve) reserve.content = (reserve.is_introduce_all == '1' && reserve.content) ? util.determine(reserve.content) : '';
			if (home) home.image = (home && home.image && (!home.id_first_image || home.id_first_image != '0')) ? home.image : '';
			if (marketing) {
				marketing.logo = (marketing.logo && (!marketing.is_logo || marketing.is_logo != '0')) ? marketing.logo : '';
				is_comments = marketing.is_comments ? marketing.is_comments : '';
				coupon = (marketing.coupon_data && marketing.is_coupon == '1') ? util.determine(marketing.coupon_data) : '';
				coupon_data_pay = (marketing.coupon_data_pay && marketing.is_coupon_pay == '1') ? util.determine(marketing.coupon_data_pay) : '';
				marketing.coupon_data_payList = coupon_data_pay
				coupon_data_free = (marketing.coupon_data_free && marketing.is_coupon_free == '1') ? util.determine(marketing.coupon_data_free) : '';
				marketing.coupon_data_freeList = coupon_data_free
				let info = marketing.coupon_data_comments ? util.determine(marketing.coupon_data_comments) : '';
				let couponDataId = info && info.length > 0 ? info[0].id : ''
				// 根据券ID获取评价赠送的券详情
				if (couponDataId) this.getEvaluateFun(couponDataId)
			}
			// is_cash 代金券  is_discount折扣券  is_dish菜品券 只有代金券有几折显示
			// 获取全部的优惠券(商家券、个人券、免费券、付费券)
			couponList = this.addCoupons(coupon, couponList);
			couponList = this.addCoupons(coupon_data_pay, couponList);
			couponList = this.addCoupons(coupon_data_free, couponList);
			// 根据券ID获取券详情(空列表不请求)
			if (couponList && couponList.length > 0) {
				this.getActivityByIdFun(couponList)
			}
			// 获取所有充值活动
			this.getRechargeDetail()
			if (store && store.images && store.images.length > 0) store.images = util.determine(store.images);
			if (reserve && reserve.park_info_images && reserve.park_info_images.length > 0) reserve.park_info_images = util.determine(reserve.park_info_images);
			if (signboard && signboard.images && signboard.images.length > 0) signboard.images = util.determine(signboard.images);
			// 与模板11 bookType=1 一致:重组文字/轮播图;content 的 type 兼容数字/字符串;无 content 图时回退 images
			if (store) {
				store = this.processInfo(store, '2');
				if (!store.imgsInfo || !store.imgsInfo.length) {
					if (store.images && store.images.length && (!store.is_images || store.is_images != '0')) {
						store.imgsInfo = store.images;
					} else {
						store.imgsInfo = [];
					}
				}
			}
			if (signboard) {
				signboard = this.processInfo(signboard, '3');
				if (!signboard.imgsInfo || !signboard.imgsInfo.length) {
					signboard.imgsInfo = (signboard.images && signboard.images.length) ? signboard.images : [];
				}
			}
			if (chef) {
				chef = this.processInfo(chef, '4');
				if (!chef.imgsInfo || !Array.isArray(chef.imgsInfo) || !chef.imgsInfo.length) {
					if ((!chef.is_images || chef.is_images != '0') && chef.image) {
						chef.imgsInfo = Array.isArray(chef.image) ? chef.image : [chef.image];
					} else {
						chef.imgsInfo = Array.isArray(chef.imgsInfo) ? chef.imgsInfo : (chef.imgsInfo ? [chef.imgsInfo] : []);
					}
				}
			}
			this.getLocalLunchTime(data.lite_style);
			data.is_custom = '0';
			// canChangeBg为1可更换背景图,0不可
			let isCustom = data.is_custom == '1' ? '1' : '0'; // 是否自定义:1 是,主题色:0
			let themeColor = isCustom == '1' ? 'pearlWhite' : data.lite_class ? data.lite_class : 'turmeric';
			let entranceIcon = 1;
			let actionIcon = 1;
			let StyleTypeNum = '1'; //样式类型1234
			let titleInfo = [
				// {
				// 	text:'贵宾1',
				// 	content:'{姓名}'
				// },
				{
					text: '姓名2',
					content: '{姓名+称呼}'
				},
				// {
				// 	text:'日期1',
				// 	content:'{公历}'
				// },
				// {
				// 	text:'日期2',
				// 	content:'{公历+星期}'
				// },
				// {
				// 	text:'日期3',
				// 	content:'{公历+农历}'
				// },
				{
					text: '日期4',
					content: '{公历+星期+农历}'
				},
				// {
				// 	text:'包间位置1',
				// 	content:'{区域名}'
				// },
				// {
				// 	text:'包间位置2',
				// 	content:'{包间名}'
				// },
				{
					text: '包间位置3',
					content: '{区域名+包间名}'
				},
				// {
				// 	text:'就餐时间1',
				// 	content:'{餐段}'
				// },
				// {
				// 	text:'就餐时间2',
				// 	content:'{就餐时间}'
				// },
				{
					text: '就餐时间3',
					content: '{餐段+就餐时间}'
				},
				{
					text: '前台电话',
					content: '{前台电话}'
				}
			]
			//大标题 — 可配字号/字体/颜色/文案;书法仅「预订安排|邀请函」;换文案时书法降为黑体
			let titleObj = {
				textColor: '#fff', //文字颜色
				textFont: '3', //文字字体1黑体 2宋体 3书法体(仅固定文案可用)
				textFontSize: '1', //文字大小 1大号 2中号 3小号
				textInfo: '邀请函11', //固定文案:预订安排 / 邀请函
			}
			//店铺名称 — 不可换字体,可换字号/颜色
			let shopObj = {
				textColor: '#fff',
				textFontSize: '2',
				textInfo: '长安大排档总店标题', //大号且>11字自动换行
			}
			// 商家有话说图片展示:0平铺 1轮播(餐厅介绍 / 招牌菜品 / 主厨介绍)
			let speakImgMode = '0';
			// 轮播时:餐厅介绍把首图、logo 一并并入 imgsInfo(去重,首图/logo 在前)
			if (speakImgMode == '1') {
				store = store || {};
				let headImgs = [];
				if (home && home.image) headImgs.push(home.image);
				if (marketing && marketing.logo) headImgs.push(marketing.logo);
				let rest = (store.imgsInfo || []).filter(url => url && headImgs.indexOf(url) < 0);
				store.imgsInfo = headImgs.concat(rest);
			}
			const titleShop = this.buildTitleShopStyle(StyleTypeNum, titleObj, shopObj);
			const titleCls = titleShop.titleCls;
			const shopCls = titleShop.shopCls;
			const titleStyle = titleShop.titleStyle;
			const shopStyle = titleShop.shopStyle;
			if (themeColor == 'pearlWhite') {
				entranceIcon = 1;
				actionIcon = 1;
			} else if (themeColor == 'turmeric') {
				entranceIcon = 4;
				actionIcon = 4;
			} else {
				entranceIcon = 3;
				actionIcon = 2;
			}
			let pageThemeClass = 'page' + themeColor;
			if (themeColor != 'pearlWhite' && themeColor != 'turmeric') {
				pageThemeClass = pageThemeClass + ' pagecolor';
			}
			let obj = {
				chef: chef || {},
				marketing: marketing || {},
				home: home || {},
				reserve: reserve || {},
				signboard: signboard || {},
				store: store || {},
				swich_phone: swich_phone || '0',
				is_comments: is_comments || '0',
				StyleType: StyleType || '',
				lite_style: data.lite_style || '',
				couponList: couponList || [],
				canChangeBg: isCustom,
				isCustom,
				themeColor,
				pageThemeClass,
				entranceIcon,
				actionIcon,
				StyleTypeNum,
				titleObj,
				shopObj,
				titleCls,
				shopCls,
				titleStyle,
				shopStyle,
				speakImgMode,
				titleInfo,
				isMoreBtn: marketing && marketing.is_online_book == '1' && this.data.options.onlineReserve == '1',
				isShareItem: this.data.options.isOrder != '1' && marketing && marketing.is_transpond == '1',
			}
			console.log('获取数据GetSellerTemplateConf--------------------', obj);
			this.setData(obj)
			this.refreshTitleRows();
			this.refreshActionBtn(obj)
			this.updateShowMerchantSpeak()
			this.resolveThemeImg();
			this.setData({
				heroBottomStripImage: (home && home.heroBottomStripImage) || (home && home.bottom_strip) || '',
			});
			// reserve为空 或 reserve里没有voice_info/swich_voice字段时,不开启商家自定义语音,走默认语音配置
			let i = (reserve == null || !reserve.voice_info || !reserve.swich_voice) ? '0' : reserve;
			this.textToSpeechFun(sid, i)
		})
	},
	// 根据充值ID获取充值详情
	getRechargeDetail() {
		App.Activity.GetNewRechargeList({
			sellerid: this.data.detail.seller.id,
		}).then(res => {
			if (res.data) {
				let arr = []
				res.data.forEach(i => {
					if (i.status != '1') {
						arr.push(i)
					}
				})
				let recharge_data = arr;
				recharge_data.forEach(item => {
					let recharge_list = {};
					try {
						if (typeof item.recharge_list === 'string' && item.recharge_list) {
							recharge_list = JSON.parse(item.recharge_list);
						} else if (item.recharge_list && typeof item.recharge_list === 'object') {
							recharge_list = item.recharge_list;
						}
					} catch (e) {
						recharge_list = {};
					}
					if (!recharge_list || typeof recharge_list !== 'object' || Array.isArray(recharge_list)) {
						recharge_list = {};
					}
					// 统一成字符串,兼容接口返回数字 0/1,保证 wxml 里 =='1' / =='0' 判断生效
					['is_price', 'is_score', 'is_coupons'].forEach(key => {
						if (recharge_list[key] == 1 || recharge_list[key] === '1') {
							recharge_list[key] = '1';
						} else if (recharge_list[key] == 0 || recharge_list[key] === '0') {
							recharge_list[key] = '0';
						}
					});
					item.recharge_list = recharge_list;
					item.priceInfo = '';
					item.scoreInfo = '';
					item.certificate = '';
					if (recharge_list.is_price == '1') {
						item.priceInfo = '会员充值满' + item.recharge_money + '元赠送' + recharge_list.price + '元余额';
					}
					if (recharge_list.is_score == '1') {
						item.scoreInfo = '会员充值满' + item.recharge_money + '元赠送' + recharge_list.score + '积分';
					}
					if (recharge_list.is_coupons == '1' && recharge_list.coupons_names && recharge_list.coupons_names.length > 0) {
						item.certificate = recharge_list.coupons_names.join('、');
					}
					item.timeStr = (item.timeStr && item.timeStr) ? util.unixtoTime(item.stime, 'YYYY-MM-DD') + ' - ' + util.unixtoTime(item.etime, 'YYYY-MM-DD') : '';
				})
				// 筛选出 未过期的 && 开启状态的充值活动
				recharge_data = recharge_data.filter(item => {
					return (this.data.dataStr < (item.etime * 1) || !item.etime) && item.is_open == '1'
				})
				console.log('邀请函--------------充值', recharge_data);
				this.setData({
					recharge_data,
				})
			} else {
				this.setData({
					recharge_data: [],
				})
			}
		})
	},
	// 点击充值活动:有手机号进充值页,无手机号进登录页
	gotoVipRecharge(e) {
		const id = e.currentTarget.dataset.id;
		if (!id) return;
		if (!this.data.purePhoneNumber) {
			this.gotoLogin('', '2');
			return;
		}
		const {
			seller,
			detail,
			StyleType
		} = this.data;
		const url = util.http_build_query({
			id,
			name: seller.name || '',
			sid: seller.sid || '',
			oid: detail.id || '',
			types: 1,
			StyleType: StyleType || '',
		}, '/pack-activity/pack/vipRecharge');
		wx.navigateTo({
			url
		});
	},
	// 获取评价赠送的券最新详情
	getEvaluateFun(id) {
		App.Activity.GetActivityById({
			id
		}).then(res => {
			if (res.data.length > 0) {
				let couponData = res.data[0]
				let data = couponData.expiration_date ? util.determine(couponData.expiration_date) : '';
				// showCoupon 代表赠送的券没过有效期 && 是开启状态
				couponData.showCoupon = (((data.valid_forever == '0' && this.data.dataStr < (data.etime * 1)) || data.valid_forever == '1') && couponData.is_open == '1') ? '1' : '0';
				console.log('邀请函--------------------评价赠送的优惠券', couponData);
				this.setData({
					couponData: res.data[0]
				})
			}
		})
	},
	// 根据券ID获取券详情
	getActivityByIdFun(obj, setcoupon) {
		App.Activity.GetActivityById({
			id: obj.map(item => item.id).join(','),
		}).then(res => {
			if (res.data.length > 0) {
				// valid_forever 1永久   0非永久
				let list = res.data.filter(item => {
					let data = item.expiration_date ? util.determine(item.expiration_date) : {};
					let validForever = data.valid_forever === '1';
					let isValid = item.is_type === '3' ?
						(validForever || (data.valid_forever === '0' && this.data.dataStr < (data.etime * 1))) :
						(this.data.dataStr < (item.etime * 1));

					return isValid && item.is_open === '1';
				});
				list.forEach(detail => {
					detail.stringifyUse = detail.use ? JSON.stringify(detail.use) : '';
					detail.exp_date = detail.exp_date ? util.determine(detail.exp_date) : '';
					detail.arule = detail.arule ? util.determine(detail.arule) : '';
					detail.use = detail.use ? util.determine(detail.use) : '';
					detail.expiration_date = detail.expiration_date ? util.determine(detail.expiration_date) : '';
					detail.aexpiration = detail.aexpiration ? util.determine(detail.aexpiration) : '';
					if ((detail.use && (!detail.use.is_cash || detail.use.is_cash == '1'))) {
						let cash = detail.use.cash * 1;
						let price = detail.price * 1;
						detail.discount = cash != 0 ? ((price / cash) * 10).toFixed(1) : '';
					}
					let num = detail.grant_num * 1 - detail.grant_last * 1;
					if (num > 0) {
						detail.receiveNumText = ''
						if (num >= 0 && num <= 100) {
							detail.receiveNumText = num.toString();
						} else if (num >= 101 && num <= 199) {
							detail.receiveNumText = '100+';
						} else if (num >= 200 && num <= 299) {
							detail.receiveNumText = '200+';
						} else {
							detail.receiveNumText = Math.floor(num / 100) * 100 + '+';
						}
					}
					if (num == 0) {
						let str = detail.grant_num * 1
						detail.receiveNumText = ''
						if (str >= 0 && str <= 100) {
							detail.receiveNumText = str.toString();
						} else if (str >= 101 && str <= 199) {
							detail.receiveNumText = '100+';
						} else if (str >= 200 && str <= 299) {
							detail.receiveNumText = '200+';
						} else {
							detail.receiveNumText = Math.floor(str / 100) * 100 + '+';
						}
					}
					if (detail.exp_date && detail.exp_date.week_data) {
						let mor = this.hasConsecutiveSelect(detail.exp_date.week_data, '1').rArr.join('、')
						let noon = this.hasConsecutiveSelect(detail.exp_date.week_data, '2').rArr.join('、')
						let nig = this.hasConsecutiveSelect(detail.exp_date.week_data, '3').rArr.join('、')
						if (mor) mor = '早餐:' + mor
						if (noon) noon = '午餐:' + noon
						if (nig) nig = '晚餐:' + nig
						detail.morText = mor;
						detail.noonText = noon;
						detail.nigText = nig;
					}
				})
				let freeCoupons = list.filter(item => {
					return item.is_type == '3'
				})
				let give = this.give_user;
				let couponShow = false;
				switch (give) {
					case '1':
						couponShow = this.data.options.hasSellerShare == '1' ? true : false;
						break;
					case '2':
						couponShow = true;
						break;
					case '3':
						couponShow = this.data.options.hasSellerShare != '1' ? true : false;
						break;
				}
				// 免费券判断是否领取,弹框领取
				if (freeCoupons.length > 0 && couponShow) {
					this.getCoupon(freeCoupons, obj, setcoupon)
				} else {
					if (setcoupon != '1') {
						this.setData({
							isFrame: '1',
						})
					}
				}
				console.log('邀请函--------------------优惠券', list);
				this.setData({
					coupon_dataList: list,
				})
			}
		})
	},
	// 弹框领取免费券
	setcouponFun() {
		let arr = this.data.couponArr;
		console.log('弹框领取免费券数组-----', arr);
		let str = arr.flatMap(item => Array(item.number).fill(item.id)).join(',');
		console.log('弹框领取免费券id', str);
		App.Activity.SetActivityAsReserve({
			aid: str,
			rid: this.id,
			phone: this.data.purePhoneNumber,
		}).then((json) => {
			if (json.ret != 200) {
				wx.showToast({
					title: json.msg,
					duration: 2000,
					mask: true
				})
			} else {
				wx.showToast({
					title: '领取成功!',
					duration: 2000,
					mask: true
				})
				this.closeCouponModal()
			}
		})
	},
	// 免费券  0未领取 1已领取 获取未领取的组成数组couponArr
	getCoupon(arr, info, setcoupon) {
		let str = arr.flatMap(item => Array(item.number).fill(item.id)).join(',');
		App.Activity.ActivityListByOpenid({
			aid: str,
			sellerid: this.data.seller.sid,
		}).then(res => {
			if (res.ret == 200) {
				let couponArr = [];
				let totalPrice = 0;
				let coupon_dataList = this.data.coupon_dataList;
				let list = res.data;
				if (setcoupon != '1') {
					list.forEach(item => {
						item.cdate = item.cdate * 1;
						item.useStime = '';
						item.useEtime = '';
						let condition = item.aexpiration ? util.determine(item.aexpiration) : '';
						if (condition.valid_forever === '0' && condition.stime && condition.etime) {
							item.useStime = util.unixtoTime(condition.stime, 'YYYY-MM-DD');
							item.useEtime = util.unixtoTime(condition.etime, 'YYYY-MM-DD');
						}
						if (condition.valid_forever === '1') {
							item.foreverText = '永久有效';
						}
						if (condition.valid_forever === '0' && condition.today) {
							let obj = this.setTimeRange(item.cdate, 0, parseInt(condition.today) - 1);
							item.useStime = obj.useStimeNum;
							item.useEtime = obj.useEtimeNum;
						}
						if (condition.valid_forever === '0' && condition.tomorrow) {
							let obj = this.setTimeRange(item.cdate, 1, condition.tomorrow * 1);
							item.useStime = obj.useStimeNum;
							item.useEtime = obj.useEtimeNum;
						}
						if (condition.valid_forever === '0' && condition.sday && condition.eday) {
							let obj = this.setTimeRange(item.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
							item.useStime = obj.useStimeNum;
							item.useEtime = obj.useEtimeNum;
						}
					})
					list = list.filter(item => {
						let condition = item.aexpiration ? util.determine(item.aexpiration) : '';
						return (item.useEtime >= this.data.dataStr) || (item.foreverText == '永久有效') || (condition.valid_forever === '0' && condition.stime && condition.etime)
					});
				}
				list.sort((a, b) => b.cdate - a.cdate);
				list = list.reduce((accumulator, current) => {
					if (!accumulator.some(item => item.aid === current.aid)) {
						accumulator.push(current);
					}
					return accumulator;
				}, []);
				const strArray = str.split(',');
				const result = strArray.filter(num => {
					return !list.some(item => item.id === num);
				});
				console.log('待领取的券id', result);
				if (result.length > 0) {
					result.forEach(item => {
						let match = arr.find(b => b.id === item);
						let obj = info.find(b => b.id === item);
						console.log('待领取的券详情', match);
						let record = {
							id: '',
							number: '',
							grant_last: '',
							price: '',
							desc: '',
						}
						if (obj) {
							record.number = obj.number;
						}
						if (match) {
							record.grant_last = match.grant_last * 1 * 1;
							record.id = match.id;
							record.desc = match.desc;
							record.price = match.price;
						}
						if (record.number > record.grant_last && record.grant_last > 0) {
							record.number = record.grant_last
						}
						// 只留下可领取数量大于0的
						if (record.grant_last > 0 && record.number) {
							console.log('可领取的券', {
								...record
							});
							couponArr.push({
								...record
							})
						}
					})
					if (couponArr.length > 0 && setcoupon != '1' && this.one == '0') {
						totalPrice = couponArr.reduce((sum, item) => sum + item.price * item.number, 0);
						this.one = '1'
						setTimeout(() => {
							this.setData({
								couponArr,
								totalPrice: parseFloat(totalPrice.toFixed(2)),
							})
							this.showCouponModal()
						}, 3000);
					} else {
						if (setcoupon != '1') {
							this.setData({
								isFrame: '1',
							})
						}
					}
				} else {
					if (setcoupon != '1') {
						this.setData({
							isFrame: '1',
						})
					}
				}
				list.forEach(item => {
					let idx = coupon_dataList.findIndex(b => b.id === item.id);
					if (idx !== null && idx !== undefined && coupon_dataList[idx]) {
						const detail = coupon_dataList[idx];
						detail.resultCoupon = '1'; // 显示已领取
						detail.cdate = item.cdate * 1;
						detail.useStime = '';
						detail.useEtime = '';
						let condition = detail.aexpiration
						if (condition.valid_forever === '0' && condition.stime && condition.etime) {
							detail.useStime = util.unixtoTime(condition.stime, 'YYYY-MM-DD');
							detail.useEtime = util.unixtoTime(condition.etime, 'YYYY-MM-DD');
						}
						if (condition.valid_forever === '1') {
							detail.foreverText = '永久有效';
						}
						if (condition.valid_forever === '0' && condition.today) {
							let obj = this.setTimeRange(detail.cdate, 0, parseInt(condition.today) - 1);
							detail.useStime = obj.useStime;
							detail.useEtime = obj.useEtime;
						}
						if (condition.valid_forever === '0' && condition.tomorrow) {
							let obj = this.setTimeRange(detail.cdate, 1, condition.tomorrow * 1);
							detail.useStime = obj.useStime;
							detail.useEtime = obj.useEtime;
						}
						if (condition.valid_forever === '0' && condition.sday && condition.eday) {
							let obj = this.setTimeRange(detail.cdate, parseInt(condition.sday) - 1, parseInt(condition.eday) - 1);
							detail.useStime = obj.useStime;
							detail.useEtime = obj.useEtime;
						}
					}
				})
				console.log('未领取的券列表-----------', couponArr);
				this.setData({
					coupon_dataList,
				})
			}
		})
	},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {
		// 选相册时也会 onHide:不清定时器、不销毁音频,回来后继续播
		if (this._skipOnShowRefresh) return;
		clearInterval(this.timers)
		if (this.data.timer) {
			clearInterval(this.data.timer);
		}
		this.destroyAudioCtx();
	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {
		clearInterval(this.timers)
		if (this.data.timer) {
			clearInterval(this.data.timer);
		}
		if (this._onUserCaptureScreen && wx.offUserCaptureScreen) {
			wx.offUserCaptureScreen(this._onUserCaptureScreen);
		}
		this.destroyAudioCtx();
	},
	destroyAudioCtx() {
		const ctx = this.audioCtx;
		if (!ctx || typeof ctx.destroy !== 'function') {
			this.audioCtx = null;
			return;
		}
		try {
			ctx.destroy();
		} catch (e) {
			console.log('destroyAudioCtx', e);
		}
		this.audioCtx = null;
	},
	// 点击关闭领券弹框后,出现图片缩小到商家有礼的位置消失动画
	startAnimation() {
		const animation = wx.createAnimation({
			duration: 800,
			timingFunction: 'ease',
		});
		animation.translateY('-60%')
			.translateX('34%')
			.scale(0)
			.step();
		this.setData({
			animationData: animation.export(),
		});
		setTimeout(() => {
			this.startSecondAnimation();
		}, 800);
	},

	// 商家有话说:自定义图文 / 餐厅介绍 / 特色菜品 / 主厨介绍 任一有内容则显示
	updateShowMerchantSpeak() {
		const {
			reserveData,
			marketing,
			home,
			store,
			signboard,
			chef
		} = this.data;

		let hasReserveText = false;
		if (reserveData) {
			if (reserveData.title) {
				hasReserveText = true;
			} else if (reserveData.content && reserveData.content.length > 0) {
				hasReserveText = true;
			}
		}

		let hasStoreContent = false;
		if (store) {
			if (store.introduce && (!store.is_introduce || store.is_introduce != '0')) {
				hasStoreContent = true;
			} else if (store.images && store.images.length > 0 && (!store.is_images || store.is_images != '0')) {
				hasStoreContent = true;
			} else if (store.content && store.content.length > 0) {
				hasStoreContent = true;
			}
		}
		let hasLogoOrHome = false;
		if ((marketing && marketing.logo) || (home && home.image)) {
			hasLogoOrHome = true;
		}
		const hasStore = hasLogoOrHome || hasStoreContent;

		let hasSignboard = false;
		if (signboard) {
			if (signboard.swich == '1' && signboard.images && signboard.images.length > 0) {
				hasSignboard = true;
			} else if (signboard.content && signboard.content.length > 0) {
				hasSignboard = true;
			}
		}

		let hasChef = false;
		if (chef) {
			if (chef.introduce && (!chef.is_introduce || chef.is_introduce != '0')) {
				hasChef = true;
			} else if (chef.image && (!chef.is_images || chef.is_images != '0')) {
				hasChef = true;
			} else if (chef.content && chef.content.length > 0) {
				hasChef = true;
			}
		}

		const showMerchantSpeak = hasReserveText || hasStore || hasSignboard || hasChef;
		if (showMerchantSpeak !== this.data.showMerchantSpeak) {
			this.setData({
				showMerchantSpeak
			});
		}
	},
	getText() {
		App.Reserve.GetReserveImgText({
			rid: this.data.options.id
		}).then(res => {
			if (res.ret == 200 && res.data) {
				let data = res.data;
				let content = util.determine(data.content)
				this.setData({
					reserveData: {
						title: data.title || '',
						content,
					}
				}, () => this.updateShowMerchantSpeak())
			}
		})
	},
	updateContactPhone() {
		const sellerTel = this.data.seller && this.data.seller.tel;
		const staffPhone = this.data.staffinfo && this.data.staffinfo.phone;
		const contactPhone = staffPhone || (sellerTel && sellerTel.length && sellerTel[0]) || '';
		if (contactPhone !== this.data.contactPhone) {
			this.setData({
				contactPhone
			});
		}
	},
	onHeroImageError() {
		const failed = this.data.themeImg;
		if (!failed) return;
		if (!this._failedThemeImgs) this._failedThemeImgs = {};
		// hero + 模糊底共用 themeImg,失败可能连触发两次,已处理过则跳过
		if (this._failedThemeImgs[failed]) return;
		this._failedThemeImgs[failed] = true;
		const defaultImg = 'https://qn.colorcun.com/testImg/img4.png';
		if (failed === defaultImg) return;
		const next = this.getThemeImgCandidates().find(url => !this._failedThemeImgs[url]) || defaultImg;
		this.setData({
			themeImg: next,
			heroBottomStripImage: '',
		});
	},
	onBackdropImageError() {
		// 后台色带加载失败时,自动切回直接裁切主图底部的方案。
		if (this.data.heroBottomStripImage) {
			this.setData({
				heroBottomStripImage: ''
			});
		}
	},
})