cmy 2 gadi atpakaļ
vecāks
revīzija
d8ef1ed8f1
2 mainītis faili ar 258 papildinājumiem un 14 dzēšanām
  1. 94 14
      pages/user/model/modelrz.vue
  2. 164 0
      utils/twelve.js

+ 94 - 14
pages/user/model/modelrz.vue

@@ -228,7 +228,14 @@
 				</view>
 			</view>
 		</view>
-		<view class="base-buttom" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">提交</view>
+		<view class="base-buttom flex">
+			<view class="updata flex flex-center" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">
+				提交
+			</view>
+			<view class="ylan flex flex-center" @click="look">
+				预览
+			</view>
+		</view>
 	</view>
 </template>
 
@@ -240,10 +247,14 @@
 		getUserWorkTypeList,
 		getUserCardInfo
 	} from '@/api/model.js';
-
 	import {
 		isCardNo
 	} from '@/utils/rocessor.js';
+	import {
+		getAstro,
+		getShengXiao,
+		IdCard
+	} from '@/utils/twelve.js';
 	import {
 		mapState
 	} from "vuex"
@@ -289,15 +300,18 @@
 				timeTypeList: [], //时间类型
 				workTypeList: [], //工作类型
 				loding: false, //是否载入中
-				type: 0, //0为新增,1为修改
-				userModelData: {} //保存获取的用户模板
-
+				type: 0, //0为新增,1为修改2为商品页进入注册
+				userModelData: {}, //保存获取的用户模板
+				modelid: '', //保存要预览的模板id
 			};
 		},
 		async onLoad(options) {
 			if (options.type == 1) {
 				this.type = 1;
 				await this.getUserCardInfo()
+			} else if (options.type == 2) {
+				this.type = 2
+				this.modelid = options.modelid
 			}
 			this.init()
 		},
@@ -338,16 +352,16 @@
 					(res) => {
 						that.typeList = res.data.list
 						if (that.type == 1) {
-							console.log(that.userModelData.service_project_ar,'that.userModelData.service_project');
 							for (let i = 0; i < that.userModelData.service_project_ar.length; i++) {
 								for (let a = 0; a < that.typeList.length; a++) {
 									if (+that.typeList[a].id == +that.userModelData.service_project_ar[i].id) {
 										that.typeList[a].checked = true;
+										that.updata.checkedType.push(''+that.typeList[a].id)
 									}
 								}
 							}
 						}
-						console.log(res,'服务');
+						console.log(res, '服务');
 					}
 				).catch(
 					(res) => {
@@ -360,10 +374,9 @@
 						that.workTypeList = res.data.list
 						if (that.type == 0) {
 							that.updata.word = that.workTypeList[0];
-
 						} else if (that.type == 1) {
 							for (let i = 0; i < that.workTypeList.length; i++) {
-								console.log(that.userModelData.user_work_type_id,'word',that.workTypeList[i].id);
+								console.log(that.userModelData.user_work_type_id, 'word', that.workTypeList[i].id);
 								if (that.workTypeList[i].id == that.userModelData.user_work_type_id) {
 									that.updata.word = that.workTypeList[i];
 									break
@@ -377,9 +390,60 @@
 					}
 				)
 			},
+			// 跳转查看预览页面
+			look() {
+				const that = this;
+				const birthday = IdCard('' + that.updata.cardId, 1);
+				// 复制选中的服务数组
+				let arr = [...that.updata.checkedType]
+				let pushar=[];
+				that.typeList.forEach(
+					(re) => {
+						for (let i = 0; i < arr.length; i++) {
+							console.log(arr[i],'循环');
+							if (+arr[i] == +re.id) {
+								// 删除已选中的对象
+								arr.splice(i, 1)
+								pushar.push(re)
+								break
+							}
+						}
+					}
+				)
+				
+				let data = {
+					name: that.updata.name,
+					avatar: that.updata.avatar,
+					age: IdCard(that.updata.cardId, 3),
+					twelve: getShengXiao(birthday),
+					work_year: that.updata.work_year,
+					constellation: getAstro(...(birthday.split('-'))),
+					ancestral_place: that.updata.ancestral_place,
+					minority: that.updata.minority,
+					education: that.updata.education,
+					service_area_all: that.updata.onCity.map(
+						(item) => {
+							return item.province + item.city + item.district
+						}
+					),
+					service_min_price: that.updata.minMoney,
+					service_max_price: that.updata.maxMoney,
+					service_time_type_title: that.updata.timetype.title,
+					service_intro_content: that.updata.mymask,
+					service_intro_imgs: that.updata.service_imgs,
+					service_audit_imgs: that.updata.service_audit_imgs,
+					service_project_ar: pushar,
+					is_type_audit: 1
+				}
+				uni.setStorageSync('modeldata',data)
+				uni.navigateTo({
+					url: '/pages/user/model/model?mtype=' + that.user.show_template_id + '&look=2'
+				})
+			},
+			// 获取用户提交数据
 			getUserCardInfo() {
 				const that = this;
-				return new Promise((resolve,reject) => {
+				return new Promise((resolve, reject) => {
 					getUserCardInfo().then(
 						(data) => {
 							const res = data.data;
@@ -405,12 +469,12 @@
 								ancestral_place: res.ancestral_place, //籍贯
 								education: res.education, //学历
 								minority: res.minority, //民族
-					
+
 								work_year: res.work_year, //从业时长
 								service_audit_imgs: res.service_audit_imgs, //我的证书
 								service_imgs: res.service_imgs, //服务展示
 							})
-							console.log(that.updata,'that.updata');
+							console.log(that.updata, 'that.updata');
 							resolve('初始化数据成功')
 						}
 					).catch(
@@ -419,7 +483,7 @@
 						}
 					)
 				})
-				
+
 			},
 			// 选中的服务类型
 			checkTypeChange(type) {
@@ -819,8 +883,24 @@
 
 	.base-buttom {
 		position: fixed;
-		bottom: 30rpx;
+		bottom: 0rpx;
 		right: 0rpx;
 		left: 0rpx;
+		margin: 0;
+		padding: 0;
+		height: 100rpx;
+		border-radius: 0;
+
+		.updata,
+		.ylan {
+			width: 50%;
+			height: 100%;
+			justify-content: center;
+		}
+
+		.ylan {
+			background-color: #FFF;
+			color: $font-color-dark;
+		}
 	}
 </style>

+ 164 - 0
utils/twelve.js

@@ -0,0 +1,164 @@
+/***************************************************************************
+ * 计算生肖
+ * 
+ * 支持简写生日,比如01,转换为2001,89转换为1989; 支持任何可以进行时间转换的格式,比如'1989/01/01','1989 01'等
+ * 
+ */
+export function getShengXiao(birth) {
+	birth += '';
+	var len = birth.length;
+	if (len < 4 && len != 2) {
+		return "";
+	}
+	if (len == 2) {
+		birth - 0 > 30 ? birth = '19' + birth : birth = '20' + birth;
+	}
+	var year = (new Date(birth)).getFullYear();
+	var arr = ['猴', '鸡', '狗', '猪', '鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊'];
+	return /^\d{4}$/.test(year) ? arr[year % 12] : "";
+}
+
+/***************************************************************************
+ * 计算星座
+ * 
+ * 
+ */
+export function getAstro(y, m, d) {
+	var constellations = [{
+		"Start": 121,
+		"End": 220,
+		"Name": "水平座"
+	}, {
+		"Start": 221,
+		"End": 320,
+		"Name": "双鱼座"
+	}, {
+		"Start": 321,
+		"End": 420,
+		"Name": "白羊座"
+	}, {
+		"Start": 421,
+		"End": 520,
+		"Name": "金牛座"
+	}, {
+		"Start": 521,
+		"End": 620,
+		"Name": "双子座"
+	}, {
+		"Start": 621,
+		"End": 720,
+		"Name": "巨蟹座"
+	}, {
+		"Start": 721,
+		"End": 820,
+		"Name": "狮子座"
+	}, {
+		"Start": 821,
+		"End": 920,
+		"Name": "处女座"
+	}, {
+		"Start": 921,
+		"End": 1020,
+		"Name": "天秤座"
+	}, {
+		"Start": 1021,
+		"End": 1120,
+		"Name": "天蝎座"
+	}, {
+		"Start": 1121,
+		"End": 1220,
+		"Name": "射手座"
+	}];
+	/*
+	 * 判断日期有效性 1,3,5,7,8,10,12为31天 2月润年29,非润年28 4,6,9,11为30天
+	 */
+	var daysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+
+	// 检测年份
+	if (y < 1970 || y > 2099)
+		return "";
+
+	// 检测月份
+	if (m < 1 || m > 12)
+		return "";
+
+	// 检测日期
+	var mDays = daysInMonth[m - 1];
+	// 如果是二月,要根据年份计算天数,不是二月时略过此计算
+	if (m == 2) {
+		mDays = GetSpecialDays(y)
+	}
+
+	// 判断日数据是不是在月份的有效天范围
+	if (d < 0 || d > mDays)
+		return "";
+
+	// 好了,走到这一步,说明上面的验证都TM过了。
+	// 这才判断是哪一个星座
+	// 星座座标等于m*100 + d
+	var pos = parseInt(m * 100) + parseInt(d);
+	for (var i in constellations) {
+		if (pos >= constellations[i].Start && pos <= constellations[i].End) {
+			return constellations[i].Name;
+		}
+	}
+}
+// 根据年份计算二月天数
+export function GetSpecialDays(y) {
+	if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
+		return 29;
+	return 28;
+}
+
+/***************************************************************************
+ * 计算年龄
+ * 
+ * 支持传递["yyyy-MM-dd"]等格式的字符串
+ * 
+ */
+export function getAge(str) {
+	var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
+	if (r == null)
+		return false;
+	var d = new Date(r[1], r[3] - 1, r[4]);
+	if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] &&
+		d.getDate() == r[4]) {
+		var Y = new Date().getFullYear();
+		return (Y - r[1]);
+	}
+	return "";
+}
+
+ 
+ /*
+    * 当type=1时获取出生日期,type=2时获取性别,type=3时获取年龄
+    * */
+export  function IdCard(IdCard, type) {
+        if (type === 1) {
+            //获取出生日期
+            let birthday = IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14)
+            return birthday
+        }
+        if (type === 2) {
+            //获取性别
+            if (parseInt(IdCard.substr(16, 1)) % 2 === 1) {
+                return "男"
+            } else {
+                return "女"
+            }
+        }
+        if (type === 3) {
+            //获取年龄
+            var ageDate = new Date()
+            var month = ageDate.getMonth() + 1
+            var day = ageDate.getDate()
+            var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
+            if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day) {
+                age++
+            }
+            if (age <= 0) {
+                age = 1
+            }
+            return age
+        }
+    }