Commit 2a3a18b3 by 李伟康

feat(OrderScreen): 新增订单筛选功能

- 添加转化人员、销售顾问、订单时间、支付时间、订单状态、支付方式等筛选条件
- 实现筛选条件的动态加载和展开收起功能
- 优化筛选界面样式,增加全选和自定义日期选项
- 重构部分组件,提高代码复用性和可维护性
1 parent a7d2adb2
...@@ -63,4 +63,23 @@ module.exports = { ...@@ -63,4 +63,23 @@ module.exports = {
...data ...data
}) })
}, },
/**获取订单列表筛选转化人员&销售顾问 */
getOrderScreenEmployeeList (data) {
return http.post({
method: 'dj.api.smartcarlife.employee.getByMerchantId',
projectName: 'boutique',
...data
})
},
/**
* 获取园区店配置
*/
getYqStoreConfig(data){
return http.get({
method: 'dj.api.smarcarlife.yqMerchantConfig.detail',
projectName: 'boutique',
...data
})
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -25,8 +25,7 @@ export default { ...@@ -25,8 +25,7 @@ export default {
}, },
props: { props: {
params: Object, params: Object,
data: Object, data: Object
cacheData: Array
}, },
mounted () { mounted () {
}, },
......
...@@ -37,7 +37,6 @@ export default { ...@@ -37,7 +37,6 @@ export default {
props: { props: {
params: Object, params: Object,
data: [Object, Array], data: [Object, Array],
cacheData: Array,
dataKey: String dataKey: String
}, },
mounted () { mounted () {
......
...@@ -54,7 +54,6 @@ export default { ...@@ -54,7 +54,6 @@ export default {
props: { props: {
params: Object, params: Object,
data: [Object, Array], data: [Object, Array],
cacheData: Array,
dataKey: String dataKey: String
}, },
mounted () { mounted () {
......
...@@ -101,7 +101,6 @@ export default { ...@@ -101,7 +101,6 @@ export default {
props: { props: {
params: Object, params: Object,
data: [Object, Array], data: [Object, Array],
cacheData: Array,
dataKey: String dataKey: String
}, },
mounted () { mounted () {
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
</template> </template>
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import Popup from './Popup.vue' import Popup from '@/components/Popup.vue'
export default { export default {
components: { components: {
Popup, Popup,
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</template> </template>
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import Popup from './components/Popup.vue' import Popup from '@/components/Popup.vue'
import config from './config' import config from './config'
import EmployeeList from './components/EmployeeList.vue' import EmployeeList from './components/EmployeeList.vue'
import DiversionMerchant from './components/DiversionMerchant.vue' import DiversionMerchant from './components/DiversionMerchant.vue'
...@@ -193,7 +193,7 @@ export default { ...@@ -193,7 +193,7 @@ export default {
confirm () { confirm () {
try { try {
let { chooseContent, popupType, componentObject } = this let { chooseContent, popupType, componentObject } = this
if (popupType === 13) { if (popupType == 13) {
chooseContent = this.componentRef().getResult() chooseContent = this.componentRef().getResult()
} }
if (chooseContent) { if (chooseContent) {
......
<template>
<view class="employee-list">
<view
@click="currentIds = []"
:class="['item flex',{active:!currentIds.length}]"
>
<view class="sprite-icon icon-tag-checked"></view>
全部
</view>
<template v-for="(i, index) in list">
<view
:key="index"
@click="choose(i)"
:class="['item flex',{active:checkActive(i)}]"
>
<view class="sprite-icon icon-tag-checked"></view>
{{i.staffName}}
</view>
</template>
</view>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'EmployeeList',
inject: ['userInfo'],
data () {
return {
list: [],
currentIds: []
}
},
props: {
params: Object,
data: [Array, Object],
},
watch: {
currentIds: {
handler (val) {
let { params: { idKey } } = this
this.$emit('choose', {
key: idKey,
value: val.length ? val : null
})
},
deep: true
}
},
mounted () {
this.getList()
},
methods: {
async getList () {
const { userInfo, params } = this,
{ cacheData } = params
if (cacheData && cacheData.length) {
this.initList(cacheData)
return
}
const { shopMerchantId, sceneType, merchantId } = userInfo,
data = await uni.$api.popupApi.getOrderScreenEmployeeList({
merchantId: params.idKey == 'sellerUserIdList' ? merchantId : shopMerchantId,
sceneList: params.idKey == 'sellerUserIdList' ? '' : [sceneType]
})
if (data && data.length) {
this.initList(data)
params.cacheData = data
this.$emit('update:params', params)
}
},
initList (list) {
let { data, params: {idKey} } = this
this.list = list
let paramsData = idKey ? data[idKey] : data
if (paramsData && paramsData.length) paramsData.map(e => {
this.currentIds.push(e)
})
this.$emit('onComplete')
},
choose (i) {
if (i) {
let { uuid } = i,
{ currentIds } = this,
index = currentIds.indexOf(uuid)
if (index == -1) this.currentIds.push(uuid)
else this.currentIds.splice(index, 1)
}
},
checkActive (i) {
let { currentIds } = this,
active = false
if (currentIds.length) active = currentIds.includes(i.uuid)
return active
// return this.currentIds.includes(i.uuid)
},
}
}
</script>
<style scoped lang='scss'>
.employee-list {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 32rpx;
margin: 0 48rpx;
.item {
justify-content: center;
height: 72rpx;
border-radius: 8rpx;
border: 2rpx solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: 32rpx;
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<view class="list">
<view
@click="currentId = ''"
:class="['item flex',{active:!currentId}]"
>
<view class="sprite-icon icon-tag-checked"></view>
全部
</view>
<template v-for="(i, index) in list">
<view
:key="index"
@click="currentId = i.id"
:class="['item flex',{active:currentId == i.id}]"
>
<view class="sprite-icon icon-tag-checked"></view>
{{i.name}}
</view>
</template>
</view>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'OrderStatusList',
inject: ['userInfo'],
data () {
return {
list: Object.freeze([
{
name: '待跟进',
value: [1],
id: 1
},
{
name: '已支付',
value: [4],
id: 2
},
{
name: '待支付',
value: [3],
id: 3
},
{
name: '已撤销',
value: [9],
id: 4
},
{
name: '战败',
value: [2],
id: 5
},
{
name: '已评价',
value: [6],
id: 6
},
{
name: '已关闭',
value: [10],
id: 7
},
{
name: '已失效',
value: [11],
id: 8
},
{
name: '未施工',
value: ['N'],
id: 9
},
{
name: '已施工',
value: ['Y'],
id: 10
},
{
name: '已退款',
value: [5, 12],
id: 11
}
]),
currentId: '',
}
},
props: {
params: Object,
data: [Array, Object],
},
watch: {
currentId: {
handler (val) {
let { params: { idKey } } = this,
{ list } = this,
item = list.find(item => item.id == val)
this.$emit('choose', {
key: idKey,
value: item ? item.value : null
})
},
deep: true
}
},
mounted () {
this.initList()
},
methods: {
initList () {
let { data, params: { idKey } } = this
this.currentId = data[idKey]
this.$emit('onComplete')
}
}
}
</script>
<style scoped lang='scss'>
.list {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 32rpx;
margin: 0 48rpx;
.item {
justify-content: center;
height: 72rpx;
border-radius: 8rpx;
border: 2rpx solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: 32rpx;
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
.splice {
color: #333333;
font-size: 32rpx;
margin: 0 8rpx;
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<view class="list">
<view
@click="currentId = ''"
:class="['item flex',{active:!currentId}]"
>
<view class="sprite-icon icon-tag-checked"></view>
全部
</view>
<template v-for="(i, index) in list">
<view
:key="index"
@click="currentId = i.value"
:class="['item flex',{active:currentId == i.value}]"
>
<view class="sprite-icon icon-tag-checked"></view>
{{i.name}}
</view>
</template>
</view>
</template>
<script type='text/ecmascript-6'>
const payTypeList = [{
name: '门店收款',
value: 2
},
{
name: '微信支付',
value: 1
},
{
name: 'POS机支付',
value: 3
},
{
name: '支付宝支付',
value: 4
},
{
name: '嘀加收款',
value: 5
}
]
export default {
name: 'PayList',
inject: ['userInfo'],
data () {
return {
list: [],
currentId: '',
}
},
props: {
params: Object,
data: [Object, Array],
},
watch: {
currentId: {
handler (value) {
let { params: { idKey } } = this
this.$emit('choose', {
key: idKey,
value
})
},
deep: true
}
},
mounted () {
this.getList()
},
methods: {
async getList () {
const { userInfo, params } = this,
{ cacheData } = params
if (cacheData && cacheData.length) {
this.initList(cacheData)
return
}
const { merchantId } = userInfo,
data = await uni.$api.popupApi.getYqStoreConfig({
yqMerchantId: merchantId
})
if (data) {
let obj = data || {}
let m = obj.supportPayTypes || []
let n = JSON.parse(JSON.stringify(payTypeList))
let payList = n.filter(k => {
let idx = m.find(j => j == k.value)
return idx >= 0
})
payList = [
...payList,
{
name: '对公转账',
value: '6'
},
{
name: '其它收款',
value: '7'
}
]
this.initList(payList)
params.cacheData = payList
this.$emit('update:params', params)
}
},
initList (list) {
this.list = list
let { data, params: { idKey } } = this
this.currentId = data[idKey]
this.$emit('onComplete')
},
}
}
</script>
<style scoped lang='scss'>
.list {
display: grid;
grid-template-columns: repeat(6, 1fr);
gap: 32rpx;
margin: 0 48rpx;
.item {
justify-content: center;
height: 72rpx;
border-radius: 8rpx;
border: 2rpx solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: 32rpx;
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
.splice {
color: #333333;
font-size: 32rpx;
margin: 0 8rpx;
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
<template>
<view class="list">
<view
@click="currentId = ''"
:class="['item flex',{active:!currentId}]"
>
<view class="sprite-icon icon-tag-checked"></view>
全部
</view>
<template v-for="(i, index) in list">
<view
:key="index"
@click="choose(i.id)"
:class="['item flex',{active:currentId == i.id}]"
>
<view class="sprite-icon icon-tag-checked"></view>
{{i.name}}
</view>
</template>
<template v-if="currentId == 3 && customDate.startDate && customDate.endDate">
<view
class="calendar flex"
@click="$refs.calendar.open()"
>
<view class="item flex active">
{{customDate.startDate}}
</view>
<view class="splice">-</view>
<view class="item flex active">
{{customDate.endDate}}
</view>
</view>
</template>
<template v-else>
<view
@click="$refs.calendar.open()"
:class="['item flex']"
>
自定义
</view>
</template>
<uni-calendar
ref="calendar"
:insert="false"
range
:clearDate="false"
startDate="2020-10-01"
:endDate="endDate"
@confirm="confirmCalendar"
:rangeValue="rangeValue"
/>
</view>
</template>
<script type='text/ecmascript-6'>
import dayjs from 'dayjs'
export default {
name: 'TimeList',
inject: ['userInfo'],
data () {
return {
list: Object.freeze([
{
name: '今日',
startDate: dayjs().format('YYYY-MM-DD'),
endDate: dayjs().format('YYYY-MM-DD'),
id: 1
}, {
name: '本月',
startDate: dayjs().startOf('month').format('YYYY-MM-DD'),
endDate: dayjs().format('YYYY-MM-DD'),
id: 2
}
]),
currentId: '',
endDate: dayjs().format('YYYY-MM-DD'),
customDate: {
startDate: '',
endDate: ''
},
rangeValue: {}
}
},
props: {
params: Object,
data: [Array, Object],
},
watch: {
currentId: {
handler (val) {
let { params: { idKey, currentIdKey } } = this
let { list } = this,
value = {}
if (val) {
let [startDateName, endDateName] = idKey
if (val == 3) {
value = {
[startDateName]: this.customDate.startDate,
[endDateName]: this.customDate.endDate
}
} else {
let item = list.find(e => e.id == val)
value = {
[startDateName]: item.startDate,
[endDateName]: item.endDate
}
}
}
this.$emit('choose', {
currentIdKey,
currentId: val,
keys: idKey,
value
})
},
deep: true
}
},
mounted () {
this.initList()
},
methods: {
async initList () {
let { data, params: { idKey, currentIdKey } } = this
if (data[currentIdKey] == 3) {
this.customDate = {
startDate: data[idKey[0]],
endDate: data[idKey[1]]
}
this.rangeValue = {
before: data[idKey[0]],
after: data[idKey[1]]
}
}
this.currentId = data[currentIdKey]
this.$emit('onComplete')
},
choose (i) {
this.currentId = i
},
confirmCalendar ({range}) {
let { data } = range
this.customDate = {
startDate: data[0] || dayjs().format('YYYY-MM-DD'),
endDate: data[data.length - 1] || dayjs().format('YYYY-MM-DD')
}
this.rangeValue = range
if (this.currentId == 3) {
let { params: { idKey } } = this,
[startDateName, endDateName] = idKey
this.$emit('choose', {
currentId: 3,
keys: idKey,
value: {
[startDateName]: this.customDate.startDate,
[endDateName]: this.customDate.endDate
}
})
} else this.currentId = 3
}
}
}
</script>
<style scoped lang='scss'>
.list {
display: flex;
gap: 32rpx;
margin: 0 48rpx;
.item {
justify-content: center;
width: 348rpx;
height: 72rpx;
border-radius: 8rpx;
border: 2rpx solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: 32rpx;
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
.splice {
color: #333333;
font-size: 32rpx;
margin: 0 8rpx;
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
const screenList = [
{
title: '转化人员',
suffix: 'merchantName',
componentName: 'EmployeeList',
params: {
cacheData: [],
idKey: 'sellerUserIdList'
},
hasToggle: true,
toggle: false
},
{
title: '销售顾问',
suffix: 'shopMerchantName',
componentName: 'EmployeeList',
params: {
cacheData: [],
idKey: 'userIdList'
},
hasToggle: true,
toggle: false
},
{
title: '订单时间',
componentName: 'TimeList',
params: {
idKey: ['orderStartDate', 'orderEndDate'],
currentIdKey: 'orderTimeId',
},
},
{
title: '支付时间',
componentName: 'TimeList',
params: {
idKey: ['payStartDate', 'payEndDate'],
currentIdKey: 'payTimeId',
},
},
{
title: '订单状态',
componentName: 'OrderStatusList',
params: {
idKey: 'statusList'
}
},
{
title: '支付方式',
componentName: 'PayList',
params: {
idKey: 'payType'
}
},
]
export default { screenList }
\ No newline at end of file \ No newline at end of file
<template>
<popup
ref="popup"
@onConfirm="confirm"
@onCancel="clear"
cancelText="清除"
>
<view class="popup-title flex">
工单筛选
<view
class="popup-close flex"
@click="close"
>
<uni-icons
type="closeempty"
size="16"
></uni-icons>
</view>
</view>
<view class="popup-body">
<scroll-view
scroll-y
:class="['popup-scroll-view',{show:loadComplete}]"
>
<template v-for="(i, index) in screenList">
<view
class="item-box"
:key="index"
>
<view class="title flex">
{{i.title}}
<template v-if="i.suffix">
({{userInfo[i.suffix]}})
</template>
<template v-if="i.hasToggle">
<view class="toggle-btn" @click="i.toggle = !i.toggle">{{i.toggle ? '收起' : '展开'}}</view>
</template>
</view>
<view :class="['box',{'fold':i.hasToggle},{'show':i.toggle}]">
<component
:ref="`${i.componentName}_${index}`"
:is="i.componentName"
:params.sync="i.params"
@choose="choose"
:data="chooseContent"
/>
</view>
</view>
</template>
</scroll-view>
<image
v-if="!loadComplete"
class="loading"
src="../../assets/images/common/loadding.gif"
/>
</view>
</popup>
</template>
<script type='text/ecmascript-6'>
import Popup from '@/components/Popup.vue'
import config from './config'
import EmployeeList from './components/EmployeeList.vue'
import TimeList from './components/TimeList.vue'
import OrderStatusList from './components/OrderStatusList.vue'
import PayList from './components/PayList.vue'
export default {
components: {
Popup,
EmployeeList,
TimeList,
OrderStatusList,
PayList
},
name: 'OrderScreen',
props: {
},
data () {
return {
screenList: config.screenList,
loadComplete: true,
chooseContent: {},
}
},
provide () {
return {
userInfo: this.userInfo,
}
},
computed: {
userInfo () {
return uni.$storage.get("userInfo")
},
},
mounted () {
},
methods: {
open (data) {
this.$refs.popup.open()
},
clear () {
},
close () {
this.$refs.popup.close()
},
choose (i) {
let { key, value, keys, currentIdKey, currentId } = i,
{ chooseContent } = this
if (keys) {
if (currentIdKey) chooseContent[currentIdKey] = currentId || ''
keys.map(e => {
if (value[e]) chooseContent[e] = value[e]
else delete chooseContent[e]
})
} else {
if (value) chooseContent[key] = value
else delete chooseContent[key]
}
},
confirm () {
let chooseContent = JSON.parse(JSON.stringify(this.chooseContent))
delete chooseContent.payTimeId
delete chooseContent.orderTimeId
Object.keys(chooseContent).map(e => {
if (e == 'orderStartDate' || e == 'payStartDate') chooseContent[e] = `${chooseContent[e]} 00:00:00`
if (e == 'orderEndDate' || e == 'payEndDate') chooseContent[e] = `${chooseContent[e]} 23:59:59`
})
this.$emit('onConfirm', chooseContent)
this.close()
},
}
}
</script>
<style scoped lang='scss'>
.popup-box {
border-radius: 32rpx 32rpx 0 0;
background: #ffffff;
height: 70vh;
.popup-title {
height: 104rpx;
justify-content: center;
position: relative;
color: #333333;
font-size: 36rpx;
font-weight: 500;
.popup-close {
position: absolute;
height: 100%;
top: 0;
right: 0;
padding: 0 48rpx;
font-weight: 400;
color: #1a1a1a;
}
}
.popup-tips {
color: #999ea8;
font-size: 28rpx;
padding-left: 48rpx;
}
.popup-body {
height: calc(100% - 312rpx);
position: relative;
.popup-scroll-view {
height: 100%;
padding-top: 8rpx;
.item-box {
margin-bottom: 32rpx;
.title {
color: #888888;
font-size: 28rpx;
height: 40rpx;
background: #f5f7fa;
padding-left: 48rpx;
margin-bottom: 16rpx;
line-height: 40rpx;
.toggle-btn {
margin-left: auto;
padding: 0 48rpx;
color: #4673ff;
font-size: 24rpx;
}
}
.box{
overflow: hidden;
}
.fold{
height: 72rpx;
}
.show{
height: auto !important;
}
}
}
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: toRpx(64);
height: toRpx(64);
}
.show {
opacity: 1;
}
}
}
</style>
\ No newline at end of file \ No newline at end of file
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
<view <view
class="popup-btn popup-cancel" class="popup-btn popup-cancel"
@click="cancel" @click="cancel"
>取消</view> >{{cancelText}}</view>
<view <view
class="popup-btn popup-confirm" class="popup-btn popup-confirm"
@click="confirm" @click="confirm"
>确定</view> >{{confirmText}}</view>
</view> </view>
</view> </view>
...@@ -38,7 +38,16 @@ export default { ...@@ -38,7 +38,16 @@ export default {
position:{ position:{
type: String, type: String,
default: 'bottom' default: 'bottom'
},
cancelText: {
type: String,
default: '取消'
},
confirmText:{
type: String,
default: '确定'
} }
}, },
data () { data () {
...@@ -54,7 +63,6 @@ export default { ...@@ -54,7 +63,6 @@ export default {
this.$refs.popup.open() this.$refs.popup.open()
}, },
cancel () { cancel () {
this.$refs.popup.close()
this.$emit('onCancel') this.$emit('onCancel')
}, },
close () { close () {
......
<template> <template>
<view class="uni-calendar"> <view class="uni-calendar">
<view v-if="!insert&&show" class="uni-calendar__mask" :class="{'uni-calendar--mask-show':aniMaskShow}" @click="clean"></view> <view
<view v-if="insert || show" class="uni-calendar__content" :class="{'uni-calendar--fixed':!insert,'uni-calendar--ani-show':aniMaskShow}"> v-if="!insert&&show"
<view v-if="!insert" class="uni-calendar__header uni-calendar--fixed-top"> class="uni-calendar__mask"
<view class="uni-calendar__header-btn-box" @click="close"> :class="{'uni-calendar--mask-show':aniMaskShow}"
<text class="uni-calendar__header-text uni-calendar--fixed-width">{{cancelText}}</text> @click="clean"
</view> ></view>
<view class="uni-calendar__header-btn-box" @click="confirm"> <view
<text class="uni-calendar__header-text uni-calendar--fixed-width">{{okText}}</text> v-if="insert || show"
</view> class="uni-calendar__content"
</view> :class="{'uni-calendar--fixed':!insert,'uni-calendar--ani-show':aniMaskShow}"
<view class="uni-calendar__header"> >
<view class="uni-calendar__header-btn-box" @click.stop="pre"> <view
<view class="uni-calendar__header-btn uni-calendar--left"></view> v-if="!insert"
</view> class="uni-calendar__header uni-calendar--fixed-top"
<picker mode="date" :value="date" fields="month" @change="bindDateChange"> >
<text class="uni-calendar__header-text">{{ (nowDate.year||'') +' / '+( nowDate.month||'')}}</text> <view
</picker> class="uni-calendar__header-btn-box"
<view class="uni-calendar__header-btn-box" @click.stop="next"> @click="close"
<view class="uni-calendar__header-btn uni-calendar--right"></view> >
</view> <text class="uni-calendar__header-text uni-calendar--fixed-width">{{cancelText}}</text>
<text class="uni-calendar__backtoday" @click="backToday">{{todayText}}</text> </view>
<view
</view> class="uni-calendar__header-btn-box"
<view class="uni-calendar__box"> @click="confirm"
<view v-if="showMonth" class="uni-calendar__box-bg"> >
<text class="uni-calendar__box-bg-text">{{nowDate.month}}</text> <text class="uni-calendar__header-text uni-calendar--fixed-width">{{okText}}</text>
</view> </view>
<view class="uni-calendar__weeks"> </view>
<view class="uni-calendar__weeks-day"> <view class="uni-calendar__header">
<text class="uni-calendar__weeks-day-text">{{SUNText}}</text> <view
</view> class="uni-calendar__header-btn-box"
<view class="uni-calendar__weeks-day"> @click.stop="pre"
<text class="uni-calendar__weeks-day-text">{{monText}}</text> >
</view> <view class="uni-calendar__header-btn uni-calendar--left"></view>
<view class="uni-calendar__weeks-day"> </view>
<text class="uni-calendar__weeks-day-text">{{TUEText}}</text> <picker
</view> mode="date"
<view class="uni-calendar__weeks-day"> :value="date"
<text class="uni-calendar__weeks-day-text">{{WEDText}}</text> fields="month"
</view> @change="bindDateChange"
<view class="uni-calendar__weeks-day"> >
<text class="uni-calendar__weeks-day-text">{{THUText}}</text> <text class="uni-calendar__header-text">{{ (nowDate.year||'') +' / '+( nowDate.month||'')}}</text>
</view> </picker>
<view class="uni-calendar__weeks-day"> <view
<text class="uni-calendar__weeks-day-text">{{FRIText}}</text> class="uni-calendar__header-btn-box"
</view> @click.stop="next"
<view class="uni-calendar__weeks-day"> >
<text class="uni-calendar__weeks-day-text">{{SATText}}</text> <view class="uni-calendar__header-btn uni-calendar--right"></view>
</view> </view>
</view> <!-- <text class="uni-calendar__backtoday" @click="backToday">{{todayText}}</text> -->
<view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex">
<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex"> </view>
<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate"></calendar-item> <view class="uni-calendar__box">
</view> <view
</view> v-if="showMonth"
</view> class="uni-calendar__box-bg"
</view> >
</view> <text class="uni-calendar__box-bg-text">{{nowDate.month}}</text>
</view>
<view class="uni-calendar__weeks">
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{SUNText}}</text>
</view>
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{monText}}</text>
</view>
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{TUEText}}</text>
</view>
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{WEDText}}</text>
</view>
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{THUText}}</text>
</view>
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{FRIText}}</text>
</view>
<view class="uni-calendar__weeks-day">
<text class="uni-calendar__weeks-day-text">{{SATText}}</text>
</view>
</view>
<view
class="uni-calendar__weeks"
v-for="(item,weekIndex) in weeks"
:key="weekIndex"
>
<view
class="uni-calendar__weeks-item"
v-for="(weeks,weeksIndex) in item"
:key="weeksIndex"
>
<calendar-item
class="uni-calendar-item--hook"
:weeks="weeks"
:calendar="calendar"
:selected="selected"
:lunar="lunar"
@change="choiceDate"
></calendar-item>
</view>
</view>
</view>
</view>
</view>
</template> </template>
<script> <script>
import Calendar from './util.js'; import Calendar from './util.js';
import CalendarItem from './uni-calendar-item.vue' import CalendarItem from './uni-calendar-item.vue'
import { initVueI18n } from '@dcloudio/uni-i18n' import { initVueI18n } from '@dcloudio/uni-i18n'
import i18nMessages from './i18n/index.js' import i18nMessages from './i18n/index.js'
const { t } = initVueI18n(i18nMessages) const { t } = initVueI18n(i18nMessages)
/** /**
* Calendar 日历 * Calendar 日历
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等 * @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
* @tutorial https://ext.dcloud.net.cn/plugin?id=56 * @tutorial https://ext.dcloud.net.cn/plugin?id=56
* @property {String} date 自定义当前时间,默认为今天 * @property {String} date 自定义当前时间,默认为今天
* @property {Boolean} lunar 显示农历 * @property {Boolean} lunar 显示农历
* @property {String} startDate 日期选择范围-开始日期 * @property {String} startDate 日期选择范围-开始日期
* @property {String} endDate 日期选择范围-结束日期 * @property {String} endDate 日期选择范围-结束日期
* @property {Boolean} range 范围选择 * @property {Boolean} range 范围选择
* @property {Boolean} insert = [true|false] 插入模式,默认为false * @property {Boolean} insert = [true|false] 插入模式,默认为false
* @value true 弹窗模式 * @value true 弹窗模式
* @value false 插入模式 * @value false 插入模式
* @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容 * @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}] * @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
* @property {Boolean} showMonth 是否选择月份为背景 * @property {Boolean} showMonth 是否选择月份为背景
* @event {Function} change 日期改变,`insert :ture` 时生效 * @event {Function} change 日期改变,`insert :ture` 时生效
* @event {Function} confirm 确认选择`insert :false` 时生效 * @event {Function} confirm 确认选择`insert :false` 时生效
* @event {Function} monthSwitch 切换月份时触发 * @event {Function} monthSwitch 切换月份时触发
* @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" /> * @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
*/ */
export default { export default {
components: { components: {
CalendarItem CalendarItem
}, },
emits:['close','confirm','change','monthSwitch'], emits: ['close', 'confirm', 'change', 'monthSwitch'],
props: { props: {
date: { date: {
type: String, type: String,
default: '' default: ''
}, },
selected: { selected: {
type: Array, type: Array,
default () { default () {
return [] return []
} }
}, },
lunar: { lunar: {
type: Boolean, type: Boolean,
default: false default: false
}, },
startDate: { startDate: {
type: String, type: String,
default: '' default: ''
}, },
endDate: { endDate: {
type: String, type: String,
default: '' default: ''
}, },
range: { range: {
type: Boolean, type: Boolean,
default: false default: false
}, },
insert: { insert: {
type: Boolean, type: Boolean,
default: true default: true
}, },
showMonth: { showMonth: {
type: Boolean, type: Boolean,
default: true default: true
}, },
clearDate: { clearDate: {
type: Boolean, type: Boolean,
default: true default: true
} },
}, rangeValue: {
data() { type: Object,
return { default: () => { { } }
show: false, }
weeks: [], },
calendar: {}, data () {
nowDate: '', return {
aniMaskShow: false show: false,
} weeks: [],
}, calendar: {},
computed:{ nowDate: '',
/** aniMaskShow: false
* for i18n }
*/ },
computed: {
okText() { /**
return t("uni-calender.ok") * for i18n
}, */
cancelText() {
return t("uni-calender.cancel") okText () {
}, return t("uni-calender.ok")
todayText() { },
return t("uni-calender.today") cancelText () {
}, return t("uni-calender.cancel")
monText() { },
return t("uni-calender.MON") todayText () {
}, return t("uni-calender.today")
TUEText() { },
return t("uni-calender.TUE") monText () {
}, return t("uni-calender.MON")
WEDText() { },
return t("uni-calender.WED") TUEText () {
}, return t("uni-calender.TUE")
THUText() { },
return t("uni-calender.THU") WEDText () {
}, return t("uni-calender.WED")
FRIText() { },
return t("uni-calender.FRI") THUText () {
}, return t("uni-calender.THU")
SATText() { },
return t("uni-calender.SAT") FRIText () {
}, return t("uni-calender.FRI")
SUNText() { },
return t("uni-calender.SUN") SATText () {
}, return t("uni-calender.SAT")
}, },
watch: { SUNText () {
date(newVal) { return t("uni-calender.SUN")
// this.cale.setDate(newVal) },
this.init(newVal) },
}, watch: {
startDate(val){ date (newVal) {
this.cale.resetSatrtDate(val) // this.cale.setDate(newVal)
this.cale.setDate(this.nowDate.fullDate) this.init(newVal)
this.weeks = this.cale.weeks },
}, startDate (val) {
endDate(val){ this.cale.resetSatrtDate(val)
this.cale.resetEndDate(val) this.cale.setDate(this.nowDate.fullDate)
this.cale.setDate(this.nowDate.fullDate) this.weeks = this.cale.weeks
this.weeks = this.cale.weeks },
}, endDate (val) {
selected(newVal) { this.cale.resetEndDate(val)
this.cale.setSelectInfo(this.nowDate.fullDate, newVal) this.cale.setDate(this.nowDate.fullDate)
this.weeks = this.cale.weeks this.weeks = this.cale.weeks
} },
}, selected (newVal) {
created() { this.cale.setSelectInfo(this.nowDate.fullDate, newVal)
this.cale = new Calendar({ this.weeks = this.cale.weeks
selected: this.selected, }
startDate: this.startDate, },
endDate: this.endDate, created () {
range: this.range, this.cale = new Calendar({
}) selected: this.selected,
this.init(this.date) startDate: this.startDate,
}, endDate: this.endDate,
methods: { range: this.range,
// 取消穿透 })
clean() {}, this.init(this.date)
bindDateChange(e) { },
const value = e.detail.value + '-1' methods: {
this.setDate(value) // 取消穿透
clean () { },
const { year,month } = this.cale.getDate(value) bindDateChange (e) {
this.$emit('monthSwitch', { const value = e.detail.value + '-1'
year, this.setDate(value)
month
const { year, month } = this.cale.getDate(value)
this.$emit('monthSwitch', {
year,
month
})
},
/**
* 初始化日期显示
* @param {Object} date
*/
init (date) {
this.cale.setDate(date)
this.weeks = this.cale.weeks
this.nowDate = this.calendar = this.cale.getInfo(date)
},
/**
* 打开日历弹窗
*/
open () {
// 弹窗模式并且清理数据
if (this.clearDate && !this.insert) {
this.cale.cleanMultipleStatus()
// this.cale.setDate(this.date)
this.init(this.date)
}
let { rangeValue } = this
if (Object.keys(rangeValue).length) {
uni.showLoading({
mask: true
}) })
}, let before = {
/** fullDate: rangeValue.before
* 初始化日期显示 },
* @param {Object} date after = {
*/ fullDate: rangeValue.after
init(date) { }
this.cale.setDate(date) this.choiceDate(before)
this.weeks = this.cale.weeks setTimeout(() => {
this.nowDate = this.calendar = this.cale.getInfo(date) uni.hideLoading()
}, this.choiceDate(after)
/** }, 100)
* 打开日历弹窗 }
*/ this.show = true
open() { this.$nextTick(() => {
// 弹窗模式并且清理数据 setTimeout(() => {
if (this.clearDate && !this.insert) { this.aniMaskShow = true
this.cale.cleanMultipleStatus() }, 50)
// this.cale.setDate(this.date) })
this.init(this.date) },
} /**
this.show = true * 关闭日历弹窗
this.$nextTick(() => { */
setTimeout(() => { close () {
this.aniMaskShow = true this.aniMaskShow = false
}, 50) this.$nextTick(() => {
}) setTimeout(() => {
}, this.show = false
/** this.$emit('close')
* 关闭日历弹窗 }, 300)
*/ })
close() { },
this.aniMaskShow = false /**
this.$nextTick(() => { * 确认按钮
setTimeout(() => { */
this.show = false confirm () {
this.$emit('close') this.setEmit('confirm')
}, 300) this.close()
}) },
}, /**
/** * 变化触发
* 确认按钮 */
*/ change () {
confirm() { if (!this.insert) return
this.setEmit('confirm') this.setEmit('change')
this.close() },
}, /**
/** * 选择月份触发
* 变化触发 */
*/ monthSwitch () {
change() { let {
if (!this.insert) return year,
this.setEmit('change') month
}, } = this.nowDate
/** this.$emit('monthSwitch', {
* 选择月份触发 year,
*/ month: Number(month)
monthSwitch() { })
let { },
year, /**
month * 派发事件
} = this.nowDate * @param {Object} name
this.$emit('monthSwitch', { */
year, setEmit (name) {
month: Number(month) let {
}) year,
}, month,
/** date,
* 派发事件 fullDate,
* @param {Object} name lunar,
*/ extraInfo
setEmit(name) { } = this.calendar
let { this.$emit(name, {
year, range: this.cale.multipleStatus,
month, year,
date, month,
fullDate, date,
lunar, fulldate: fullDate,
extraInfo lunar,
} = this.calendar extraInfo: extraInfo || {}
this.$emit(name, { })
range: this.cale.multipleStatus, },
year, /**
month, * 选择天触发
date, * @param {Object} weeks
fulldate: fullDate, */
lunar, choiceDate (weeks) {
extraInfo: extraInfo || {} if (weeks.disable) return
}) this.calendar = weeks
}, // 设置多选
/** this.cale.setMultiple(this.calendar.fullDate)
* 选择天触发 this.weeks = this.cale.weeks
* @param {Object} weeks this.change()
*/ },
choiceDate(weeks) { /**
if (weeks.disable) return * 回到今天
this.calendar = weeks */
// 设置多选 backToday () {
this.cale.setMultiple(this.calendar.fullDate) const nowYearMonth = `${this.nowDate.year}-${this.nowDate.month}`
this.weeks = this.cale.weeks const date = this.cale.getDate(new Date())
this.change() const todayYearMonth = `${date.year}-${date.month}`
},
/** this.init(date.fullDate)
* 回到今天
*/ if (nowYearMonth !== todayYearMonth) {
backToday() { this.monthSwitch()
const nowYearMonth = `${this.nowDate.year}-${this.nowDate.month}` }
const date = this.cale.getDate(new Date())
const todayYearMonth = `${date.year}-${date.month}` this.change()
},
this.init(date.fullDate) /**
* 上个月
if(nowYearMonth !== todayYearMonth) { */
this.monthSwitch() pre () {
} const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate
this.setDate(preDate)
this.change() this.monthSwitch()
},
/** },
* 上个月 /**
*/ * 下个月
pre() { */
const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate next () {
this.setDate(preDate) const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate
this.monthSwitch() this.setDate(nextDate)
this.monthSwitch()
}, },
/** /**
* 下个月 * 设置日期
*/ * @param {Object} date
next() { */
const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate setDate (date) {
this.setDate(nextDate) this.cale.setDate(date)
this.monthSwitch() this.weeks = this.cale.weeks
}, this.nowDate = this.cale.getInfo(date)
/** }
* 设置日期 }
* @param {Object} date }
*/
setDate(date) {
this.cale.setDate(date)
this.weeks = this.cale.weeks
this.nowDate = this.cale.getInfo(date)
}
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
$uni-bg-color-mask: rgba($color: #000000, $alpha: 0.4); $uni-bg-color-mask: rgba(
$uni-border-color: #EDEDED; $color: #000000,
$uni-text-color: #333; $alpha: 0.4
$uni-bg-color-hover:#f1f1f1; );
$uni-font-size-base:14px; $uni-border-color: #ededed;
$uni-text-color-placeholder: #808080; $uni-text-color: #333;
$uni-color-subtitle: #555555; $uni-bg-color-hover: #f1f1f1;
$uni-text-color-grey:#999; $uni-font-size-base: 14px;
.uni-calendar { $uni-text-color-placeholder: #808080;
/* #ifndef APP-NVUE */ $uni-color-subtitle: #555555;
display: flex; $uni-text-color-grey: #999;
/* #endif */ .uni-calendar {
flex-direction: column; /* #ifndef APP-NVUE */
} display: flex;
/* #endif */
.uni-calendar__mask { flex-direction: column;
position: fixed; }
bottom: 0;
top: 0; .uni-calendar__mask {
left: 0; position: fixed;
right: 0; bottom: 0;
background-color: $uni-bg-color-mask; top: 0;
transition-property: opacity; left: 0;
transition-duration: 0.3s; right: 0;
opacity: 0; background-color: $uni-bg-color-mask;
/* #ifndef APP-NVUE */ transition-property: opacity;
z-index: 99; transition-duration: 0.3s;
/* #endif */ opacity: 0;
} /* #ifndef APP-NVUE */
z-index: 99;
.uni-calendar--mask-show { /* #endif */
opacity: 1 }
}
.uni-calendar--mask-show {
.uni-calendar--fixed { opacity: 1;
position: fixed; }
/* #ifdef APP-NVUE */
bottom: 0; .uni-calendar--fixed {
/* #endif */ position: fixed;
left: 0; /* #ifdef APP-NVUE */
right: 0; bottom: 0;
transition-property: transform; /* #endif */
transition-duration: 0.3s; left: 0;
transform: translateY(460px); right: 0;
/* #ifndef APP-NVUE */ transition-property: transform;
bottom: calc(var(--window-bottom)); transition-duration: 0.3s;
z-index: 99; transform: translateY(460px);
/* #endif */ /* #ifndef APP-NVUE */
} bottom: calc(var(--window-bottom));
z-index: 99;
.uni-calendar--ani-show { /* #endif */
transform: translateY(0); }
}
.uni-calendar--ani-show {
.uni-calendar__content { transform: translateY(0);
background-color: #fff; }
}
.uni-calendar__content {
.uni-calendar__header { background-color: #fff;
position: relative; }
/* #ifndef APP-NVUE */
display: flex; .uni-calendar__header {
/* #endif */ position: relative;
flex-direction: row; /* #ifndef APP-NVUE */
justify-content: center; display: flex;
align-items: center; /* #endif */
height: 50px; flex-direction: row;
border-bottom-color: $uni-border-color; justify-content: center;
border-bottom-style: solid; align-items: center;
border-bottom-width: 1px; height: 50px;
} border-bottom-color: $uni-border-color;
border-bottom-style: solid;
.uni-calendar--fixed-top { border-bottom-width: 1px;
/* #ifndef APP-NVUE */ }
display: flex;
/* #endif */ .uni-calendar--fixed-top {
flex-direction: row; /* #ifndef APP-NVUE */
justify-content: space-between; display: flex;
border-top-color: $uni-border-color; /* #endif */
border-top-style: solid; flex-direction: row;
border-top-width: 1px; justify-content: space-between;
} border-top-color: $uni-border-color;
border-top-style: solid;
.uni-calendar--fixed-width { border-top-width: 1px;
width: 50px; }
}
.uni-calendar--fixed-width {
.uni-calendar__backtoday { width: 50px;
position: absolute; }
right: 0;
top: 25rpx; .uni-calendar__backtoday {
padding: 0 5px; position: absolute;
padding-left: 10px; right: 0;
height: 25px; top: 25rpx;
line-height: 25px; padding: 0 5px;
font-size: 12px; padding-left: 10px;
border-top-left-radius: 25px; height: 25px;
border-bottom-left-radius: 25px; line-height: 25px;
color: $uni-text-color; font-size: 12px;
background-color: $uni-bg-color-hover; border-top-left-radius: 25px;
} border-bottom-left-radius: 25px;
color: $uni-text-color;
.uni-calendar__header-text { background-color: $uni-bg-color-hover;
text-align: center; }
width: 100px;
font-size: $uni-font-size-base; .uni-calendar__header-text {
color: $uni-text-color; text-align: center;
} width: 100px;
font-size: $uni-font-size-base;
.uni-calendar__header-btn-box { color: $uni-text-color;
/* #ifndef APP-NVUE */ }
display: flex;
/* #endif */ .uni-calendar__header-btn-box {
flex-direction: row; /* #ifndef APP-NVUE */
align-items: center; display: flex;
justify-content: center; /* #endif */
width: 50px; flex-direction: row;
height: 50px; align-items: center;
} justify-content: center;
width: 50px;
.uni-calendar__header-btn { height: 50px;
width: 10px; }
height: 10px;
border-left-color: $uni-text-color-placeholder; .uni-calendar__header-btn {
border-left-style: solid; width: 10px;
border-left-width: 2px; height: 10px;
border-top-color: $uni-color-subtitle; border-left-color: $uni-text-color-placeholder;
border-top-style: solid; border-left-style: solid;
border-top-width: 2px; border-left-width: 2px;
} border-top-color: $uni-color-subtitle;
border-top-style: solid;
.uni-calendar--left { border-top-width: 2px;
transform: rotate(-45deg); }
}
.uni-calendar--left {
.uni-calendar--right { transform: rotate(-45deg);
transform: rotate(135deg); }
}
.uni-calendar--right {
transform: rotate(135deg);
.uni-calendar__weeks { }
position: relative;
/* #ifndef APP-NVUE */ .uni-calendar__weeks {
display: flex; position: relative;
/* #endif */ /* #ifndef APP-NVUE */
flex-direction: row; display: flex;
} /* #endif */
flex-direction: row;
.uni-calendar__weeks-item { }
flex: 1;
} .uni-calendar__weeks-item {
flex: 1;
.uni-calendar__weeks-day { }
flex: 1;
/* #ifndef APP-NVUE */ .uni-calendar__weeks-day {
display: flex; flex: 1;
/* #endif */ /* #ifndef APP-NVUE */
flex-direction: column; display: flex;
justify-content: center; /* #endif */
align-items: center; flex-direction: column;
height: 45px; justify-content: center;
border-bottom-color: #F5F5F5; align-items: center;
border-bottom-style: solid; height: 45px;
border-bottom-width: 1px; border-bottom-color: #f5f5f5;
} border-bottom-style: solid;
border-bottom-width: 1px;
.uni-calendar__weeks-day-text { }
font-size: 14px;
} .uni-calendar__weeks-day-text {
font-size: 14px;
.uni-calendar__box { }
position: relative;
} .uni-calendar__box {
position: relative;
.uni-calendar__box-bg { }
/* #ifndef APP-NVUE */
display: flex; .uni-calendar__box-bg {
/* #endif */ /* #ifndef APP-NVUE */
justify-content: center; display: flex;
align-items: center; /* #endif */
position: absolute; justify-content: center;
top: 0; align-items: center;
left: 0; position: absolute;
right: 0; top: 0;
bottom: 0; left: 0;
} right: 0;
bottom: 0;
.uni-calendar__box-bg-text { }
font-size: 200px;
font-weight: bold; .uni-calendar__box-bg-text {
color: $uni-text-color-grey; font-size: 200px;
opacity: 0.1; font-weight: bold;
text-align: center; color: $uni-text-color-grey;
/* #ifndef APP-NVUE */ opacity: 0.1;
line-height: 1; text-align: center;
/* #endif */ /* #ifndef APP-NVUE */
} line-height: 1;
/* #endif */
}
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!