chenkainan 7 months ago
parent
commit
fd2ded67f2
  1. 191
      components/Base.vue
  2. 2
      components/SearchHeader.vue
  3. 2
      components/TitleHeader.vue
  4. 174
      static/js/CommonFunction.js

191
components/Base.vue

@ -1,191 +0,0 @@
<template></template>
<script>
import store from '@/store/index.js'; //store
export default {
name: "Base",
data() {
return {
}
},
methods: {
//
showDiscount(discount) {
if (discount && discount != 0) return (discount / 10).toFixed(1) + '折'
},
//
showPrice(price) {
return (price && price != 0) ? (price / 100).toFixed(2) : '0.00'
},
//
goBack() {
getCurrentPages().length > 1 ? uni.navigateBack({}) : uni.switchTab({
url: '/pages/index/index'
})
},
//
mobileValid(val) {
return /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(val);
},
//
idNumberValid(val) {
return /^\d{17}(\d{1}|[X|x])$/.test(val);
},
//
passportValid(val) {
return /^([a-zA-z]|[0-9]){5,17}$/.test(val);
},
//
taiwanValid(val) {
return /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/.test(val);
},
//
gangaoValid(val) {
return /^([A-Z]\d{6,10}(\(\w{1}\))?)$/.test(val);
},
//
foreignerValid(val) {
return /(^[A-Za-z]{3})([0-9]{12}$)/.test(val);
},
//
officerValid(val) {
return /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/.test(val);
},
//
emailValid(val){
return /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(val)
},
//
clickPhone(phone) {
uni.makePhoneCall({
phoneNumber:phone
})
},
//
showImg(img) {
if (img.indexOf('https://') != -1 || img.indexOf('http://') != -1) {
return img;
} else {
return this.NEWAPIURL + img;
}
},
//
gotoPath(path) {
uni.navigateTo({
url: path
})
},
//
getLocation() {
uni.startLocationUpdate({
success: res => {
console.log(res)
uni.onLocationChange(data => {
console.log(data)
store.commit('changeLoationInfo', {
lat: data.latitude,
lon: data.longitude
})
})
}
})
},
// mkm
getDistance(distance){
return (distance / 1000).toFixed(2) + 'km'
},
//
openLocation(lat,lon){
uni.openLocation({
latitude: Number(lat),
longitude: Number(lon),
success: function () {
console.log('success');
}
});
},
//
goPhone(phone){
uni.showModal({
title:'温馨提示',
content:`确定拨打电话?`,
success: res => {
if(res.confirm){
uni.makePhoneCall({
phoneNumber: phone, //
success(){
console.log('拨打成功')
},
fail(){
console.log('拨打失败')
}
})
}else{
console.log('失败')
}
}
})
},
// goods_tag_id,type_id
gotoDetails(item){
if(item.goods){
var ids = item.goods.goods_tag_id.split(',')
var type_id = item.goods.type_id
var id = item.goods.id
}else{
var ids = item.goods_tag_id.split(',')
var type_id = item.type_id
var id = item.id
}
if(ids.includes("2")){
//
uni.navigateTo({
url: '/subPackages1/hotel/hotelDetails?id='+id
});
}else if(ids.includes("16")){
// 宿
}else if(type_id == 3){
//
if(ids.includes("12")){
//
uni.navigateTo({
url: '/subPackages/details/eateryDetails?id='+id
});
}else if(ids.includes("6")){
//
uni.navigateTo({
url: '/subPackages/details/goodDetails?type=1&id='+id
});
}else if(ids.includes("7")){
//
uni.navigateTo({
url: '/subPackages/details/goodDetails?type=0&id='+id
});
}
}else if(type_id == 5){
//
if(ids.includes("6")){
//
uni.navigateTo({
url: '/subPackages/details/goodDetails?type=1&id='+id
});
}else if(ids.includes("7")){
//
uni.navigateTo({
url: '/subPackages/details/goodDetails?type=0&id='+id
});
}
}else if(type_id == 1){
uni.navigateTo({
url: '/subPackages/details/scenicDetails?id='+id
});
}
}
}
}
</script>
<style scoped>
</style>

2
components/SearchHeader.vue

@ -12,10 +12,8 @@
</template> </template>
<script> <script>
import Base from "./Base";
export default { export default {
name: "SearchHeader", name: "SearchHeader",
extends: Base,
props: ['bgColor'], props: ['bgColor'],
data() { data() {
return { return {

2
components/TitleHeader.vue

@ -9,11 +9,9 @@
</template> </template>
<script> <script>
import Base from "./Base";
export default { export default {
name: "SearchHeader", name: "SearchHeader",
props: ['title', 'icon'], props: ['title', 'icon'],
extends: Base,
watch: { watch: {
'title'(newVal, oldVal) { 'title'(newVal, oldVal) {
this.title = newVal this.title = newVal

174
static/js/CommonFunction.js

@ -36,9 +36,39 @@ Vue.prototype.idCardNumber = (val) => {
return pattern.test(val); return pattern.test(val);
} }
// 护照验证正则
Vue.prototype.passportValid = (val) => {
return /^([a-zA-z]|[0-9]){5,17}$/.test(val);
}
// 台胞证正则
Vue.prototype.taiwanValid = (val) => {
return /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/.test(val);
}
// 港澳通行证正则
Vue.prototype.gangaoValid = (val) => {
return /^([A-Z]\d{6,10}(\(\w{1}\))?)$/.test(val);
}
// 外国人永久居留证正则
Vue.prototype.foreignerValid = (val) => {
return /(^[A-Za-z]{3})([0-9]{12}$)/.test(val);
}
// 军官证正则
Vue.prototype.officerValid = (val) => {
return /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/.test(val);
}
// 邮箱验证正则
Vue.prototype.emailValid = (val) => {
return /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(val)
}
//判断电话号码格式 //判断电话号码格式
Vue.prototype.IsTel = tel => { Vue.prototype.IsTel = tel => {
var pattern = /^1\d{10}$/; var pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
return pattern.test(tel); return pattern.test(tel);
} }
@ -54,8 +84,142 @@ Vue.prototype.IsCode = code => {
return pattern.test(code); return pattern.test(code);
} }
//判断邮箱 // 图片显示判断
Vue.prototype.IsMail = code => { Vue.prototype.showImg = img => {
var pattern = /^\w+@[a-z0-9]+\.[a-z]+$/i; if (!img) return;
return pattern.test(code); if (img.indexOf('https://') != -1 || img.indexOf('http://') != -1) {
return img;
} else {
return this.NEWAPIURL + img;
}
}
// 获取经纬度
Vue.prototype.getLocation = () => {
uni.startLocationUpdate({
success: res => {
uni.onLocationChange(data => {
uni.setStorageSync('location', {
lat: data.latitude,
lon: data.longitude
});
})
}
})
} }
// 路由页面跳转
Vue.prototype.gotoPath = path => {
uni.navigateTo({
url: path
})
}
// 返回上一页
Vue.prototype.goBack = () => {
getCurrentPages().length > 1 ? uni.navigateBack({}) : uni.switchTab({
url: '/pages/index/index'
})
}
// 打开地图
Vue.prototype.openLocation = (lat, lon) => {
uni.openLocation({
latitude: Number(lat),
longitude: Number(lon),
success: function() {
console.log('success');
}
});
}
// 拨打电话
Vue.prototype.clickPhone = (phone) => {
uni.makePhoneCall({
phoneNumber: phone
})
}
//周几
Vue.prototype.ShowDateDay = day => {
let stateTxt = "";
switch (day) {
case 0:
stateTxt = '周日'
break;
case 1:
stateTxt = '周一'
break;
case 2:
stateTxt = '周二'
break;
case 3:
stateTxt = '周三'
break;
case 4:
stateTxt = '周四'
break;
case 5:
stateTxt = '周五'
break;
case 6:
stateTxt = '周六'
break;
}
return stateTxt
}
Date.prototype.Format = function(fmt) { //author: meizz
var o = {
"Y+": this.getFullYear(), //月份
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
.length)));
return fmt;
}
// 是否接收订阅消息
Vue.prototype.getSubscribeMessage = () => {
const templateIds = [
// 退款成功通知
'hRZoiEES2BWtKb6Xgsnn8khLQH9un5j_11qu0bwlhfE',
// 订单核销通知
// '7D-JP7o0nQ_NiQk2w8mBs8jdT1_7ofvyBN-G9NLY2Zk',
// 订单支付成功通知
// '6cHez9KDlCDp1_nWUlUSV7qEaahIQWmYVlOCE-J6ODQ',
// 出票失败提醒
// 'G-N85zK2gPwgTRZWQrtHZo_-5TFcdAqBxSk4qsqcvVc',
// 出票结果通知
'YyTCUIYBnrj9CyKks8cOjNX_Rk8a4yVdswMP-zXVbhc'
]
uni.requestSubscribeMessage({
tmplIds: templateIds,
complete(res) {
uni.navigateTo({
url: '/subPackages/order/trades'
})
}
})
}
// 金刚区头图
Vue.prototype.getHeadImg = type => {
return Vue.prototype.Post({
type,
},
'/api/public_service/getKumgangHeadImgList'
).then(res => {
return res.data[0].image
});
}
Loading…
Cancel
Save