This commit is contained in:
Ankkaya 2024-09-19 16:23:19 +08:00
parent 6f0d928fb2
commit 4f7b20b257
8 changed files with 596 additions and 454 deletions

View File

@ -17,18 +17,21 @@
<view class="statistic ss-m-t-24">
<view class="title ss-font-24 ss-m-b-20">
{{ `今日收款金额(成功收款${state.statistic?.todayPaymentCount || 0}笔)` }}
{{ `今日收款金额` }}
</view>
<view class="income flex justify-between align-center">
<view class="left flex align-center">
<view class="unit self-start"></view>
<view class="sincome ss-font-60">{{ fen2yuan(state.statistic.todayPaymentAmount || 0) }}</view>
<view class="sincome ss-font-60">{{ fen2yuan(state.statistic.todaySales || 0) }}</view>
</view>
<!-- <button class="right-btn ss-reset-button">查看详情</button> -->
</view>
<view class="des ss-m-t-20">
总销售额 {{ fen2yuan(state.statistic.totalSalesAmount) }} | 成功退款 {{ state.statistic.refundCount }} |
退款金额 {{ fen2yuan(state.statistic.refundAmount) }}
总订单数 {{ state.statistic.total }} | 已完成订单 {{ state.statistic.countCompleted }} | 总付款额
{{ fen2yuan(state.statistic.totalPayPrice) }}
</view>
<view class="des ss-m-t-20">
取消订单 {{ state.statistic.countCanceled }} | 退款金额 {{ fen2yuan(state.statistic.totalRefundPrice) }}
</view>
</view>
@ -37,13 +40,13 @@
<view class="items">
<view class="item" v-for="(item, index) in state.now" :key="item.name">
<view class="label">{{ item.name }}</view>
<view class="value">{{ index !== 0 ? item.value : fen2yuan(item.value) }}</view>
<view class="value">{{ index.name?.includes('金额') ? fen2yuan(item.value) : item.value }}</view>
<!-- <view class="last"> 昨日 {{ index === 0 ? fen2yuan(item.last) : item.last ? item.last : 0 }} </view> -->
</view>
</view>
</view>
<view class="more ss-m-t-40">
<view class="more ss-m-t-40" style="margin-bottom: 40rpx">
<view class="title ss-m-b-30">昨日数据</view>
<view class="items">
<view class="item" v-for="(item, index) in state.yesterday" :key="item.name">
@ -75,43 +78,59 @@ const bgStyle = {
const state = ref({
statistic: {
todayPaymentCount: 0,
todayPaymentAmount: 0,
totalSalesAmount: 0,
refundCount: 0,
refundAmount: 0,
todaySales: 0,
countCompleted: 0, //
total: 0, //
totalPayPrice: 0, //
countCanceled: 0, //
totalRefundPrice: 0, // 退
},
now: [
{
name: '销售金额',
key: 'Amount',
key: 'todaySales',
value: 0,
},
{
name: '订单数',
key: 'orderCount',
key: 'todayOrders',
value: 0,
},
{
name: '待支付订单',
key: 'countPayTodo',
value: 0,
},
{
name: '待核销',
key: 'verificationOrderCount',
key: 'countTodoUnverified',
value: 0,
},
{
name: '待配送',
key: 'deliveryOrderCount',
key: 'countTodoWaitingDelivery',
value: 0,
},
{
name: '退款笔数',
key: 'todayRefunds',
value: 0,
},
],
yesterday: [
{
name: '销售金额',
key: 'Amount',
key: 'yesterdaySales',
value: 0,
},
{
name: '订单数',
key: 'orderCount',
key: 'yesterdayOrders',
value: 0,
},
{
name: '退款金额',
key: 'yesterdayRefunds',
value: 0,
},
],
@ -129,12 +148,13 @@ async function getStatistic() {
state.value.statistic[key] = res.data[key]
}
state.value.now[0].value = res.data.todayPaymentAmount ?? 0
state.value.yesterday[0].value = res.data.yesterdaySalesAmount ?? 0
state.value.now[1].value = res.data.orderCount
state.value.yesterday[1].value = res.data.yesterdayOrderCount
state.value.now[2].value = res.data.verificationOrderCount
state.value.now[3].value = res.data.deliveryOrderCount
for (let obj of state.value.now) {
obj.value = res.data[obj.key] ?? 0
}
for (let obj of state.value.yesterday) {
obj.value = res.data[obj.key] ?? 0
}
}
/**
@ -200,7 +220,7 @@ onShow(() => {
}
.statistic {
height: 200rpx;
// height: 200rpx;
background-color: #fffefe;
opacity: 0.9;
border-radius: 26rpx;

View File

@ -9,7 +9,21 @@
:leftIcon="''"
>
<pb-sticky bgColor="#fff">
<pb-tabs :list="tabMaps" :scrollable="false" @change="onTabsChange" :current="state.currentTab" />
<pb-tabs :list="tabMaps" :scrollable="false" @change="onTabsChange" :current="state.currentTab">
<template #right>
<uni-icons
type="search"
size="20"
:color="state.searchStatus ? '#ff3000' : '#000'"
:style="{
position: 'relative',
top: '2px',
'margin-right': '20rpx',
}"
@click="onSearch"
></uni-icons>
</template>
</pb-tabs>
</pb-sticky>
<p-empty v-if="state.pagination.total === 0" icon="/static/order-empty.png" text="暂无订单" bgColor="transparent" />
<view v-if="state.pagination.total > 0">
@ -25,6 +39,11 @@
{{ formatOrderStatus(order) }}
</view>
</view>
<view class="ss-p-x-20">
<view class="order-no">收货人{{ order?.user.nickname }}</view>
<view class="order-no">联系电话{{ order?.user.mobile }}</view>
<view class="order-no">下单时间{{ formatDate(order.createTime) }}</view>
</view>
<view class="border-bottom" v-for="item in order.items" :key="item.id">
<p-goods-item
:img="item.picUrl"
@ -112,6 +131,29 @@
:status="state.loadStatus"
:content-text="{ contentdown: '上拉加载更多' }"
/>
<uni-popup type="right" ref="filterPopupRef" background-color="#fff">
<view class="query-form">
<uni-forms v-model="state.queryForm">
<uni-forms-item name="userNickname" label="昵称">
<uni-easyinput type="text" v-model="state.queryForm.userNickname" placeholder="请输入昵称" clearable />
</uni-forms-item>
<uni-forms-item label="联系电话" name="userMobile">
<uni-easyinput type="number" v-model="state.queryForm.userMobile" placeholder="请输入联系电话" />
</uni-forms-item>
<uni-forms-item name="no" label="订单号">
<uni-easyinput type="text" v-model="state.queryForm.no" placeholder="请输入订单号" clearable />
</uni-forms-item>
<uni-forms-item name="createTime" label="创建时间">
<uni-datetime-picker v-model="state.queryForm.createTime" type="daterange" />
</uni-forms-item>
</uni-forms>
<view class="btns">
<button class="ss-reset-button query-btn shadow" @tap="onSubmit">查询</button>
<button class="ss-reset-button reset-btn shadow" @tap="reset">重置</button>
</view>
</view>
</uni-popup>
</pb-layout>
</template>
@ -122,7 +164,7 @@ import { onLoad, onShow, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-
import { fen2yuan, formatOrderColor, formatOrderStatus, handleOrderButtons } from '@/peach/hooks/useGoods'
import peach from '@/peach'
import _, { isEmpty } from 'lodash'
import { resetPagination } from '@/peach/utils'
import { resetPagination, formatDate } from '@/peach/utils'
const bgStyle = {
backgroundColor: 'var(--ui-BG-1)',
@ -138,8 +180,17 @@ const state = ref({
pageSize: 6,
},
loadStatus: '',
queryForm: {
userNickname: '',
userMobile: '',
no: '',
createTime: [],
},
searchStatus: false,
})
const filterPopupRef = ref(null)
const tabMaps = [
{
name: '全部',
@ -192,6 +243,34 @@ function totalPricePerOrder(order) {
}
}
function onSearch() {
filterPopupRef.value.open()
}
function onSubmit() {
state.value.pagination.list = []
filterPopupRef.value.close()
state.value.searchStatus = true
getOrderList()
}
function resetFields() {
state.value.queryForm = {
userNickname: '',
userMobile: '',
no: '',
createTime: [],
}
}
function reset() {
state.value.pagination.list = []
state.value.searchStatus = false
filterPopupRef.value.close()
resetFields()
getOrderList()
}
//
function onTabsChange(e) {
if (state.value.currentTab === e.index) {
@ -224,6 +303,7 @@ async function getOrderList() {
? false
: true
: undefined,
...state.value.queryForm,
})
data.list.forEach((item) => {
@ -263,6 +343,8 @@ onReachBottom(() => {
//
onPullDownRefresh(() => {
resetPagination(state.value.pagination)
state.value.searchStatus = false
resetFields()
getOrderList()
setTimeout(function () {
uni.stopPullDownRefresh()
@ -311,8 +393,7 @@ onPullDownRefresh(() => {
.order-list-card-box {
.order-card-header {
height: 80rpx;
padding-top: 20rpx;
.order-no {
font-size: 26rpx;
font-weight: 500;
@ -370,6 +451,29 @@ onPullDownRefresh(() => {
}
}
.query-form {
width: 600rpx;
margin-top: 230rpx;
padding: 0 20rpx;
.btns {
display: flex;
gap: 20px;
.query-btn {
flex: 1;
height: 80rpx;
border-radius: 40rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
color: $white;
}
.reset-btn {
flex: 1;
height: 80rpx;
border-radius: 40rpx;
border: 1px solid #000;
}
}
}
:deep(.uni-tooltip-popup) {
background: var(--ui-BG);
}

View File

@ -364,8 +364,9 @@ function getProduct(id) {
richValues.value = res.data.description ? res.data.description + '<p><br/></p>' : ''
// categoryList formData.value.categoryId
let tempCategory = categoryList.value.find((item) => {
return item.children.find((child) => {
return item.children?.find((child) => {
return child.id === formData.value.categoryId
})
})
@ -378,6 +379,7 @@ function getProduct(id) {
}).name
// brandList, formData.value.brandId
let tempBrand = brandList.value.find((item) => {
return item.id === formData.value.brandId
})

View File

@ -135,7 +135,7 @@
<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import sheep from '@/peach'
import peach from '@/peach'
import $store from '@/peach/store'
import UserApi from '@/peach/api/member/user'
import { mobile, idCard, bankName, bankCode } from '@/peach/validate/form'
@ -292,7 +292,7 @@ const rules = {
},
}
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2
const statusBarHeight = peach.$platform.device.statusBarHeight * 2
const timeSlotRef = ref(null)
const formRef = ref(null)

View File

@ -56,6 +56,10 @@ const UserUtil = {
url: '/shop/particulars/update',
method: 'PUT',
data,
custom: {
successMsg: '修改成功',
auth: true,
},
})
},

View File

@ -1,49 +1,66 @@
import request from '@/peach/request'
const OrderUtil = {
// 获取订单列表
getOrderPage: (data) => {
return request({
url: '/trade/order/page',
method: 'GET',
params: data,
})
},
// 获取订单列表
getOrderPage: (data) => {
for (let key in data) {
if (!data[key]) {
delete data[key]
}
}
// 订单详情
getOrderDetail: (data) => {
return request({
url: '/trade/order/get-detail',
method: 'GET',
params: data,
})
},
let temp = JSON.parse(JSON.stringify(data))
// 商品核销
orderVerification: (data) => {
return request({
url: '/trade/order/verify-code',
method: 'POST',
data: data,
})
},
if (temp.createTime.length > 0) {
temp['createTime[0]'] = data.createTime[0] + ' 00:00:00'
temp['createTime[1]'] = data.createTime[1] + ' 00:00:00'
}
delete temp.createTime
// 完成订单
orderComplete: (data) => {
return request({
url: '/trade/order/completed-order',
method: 'POST',
data: data,
})
},
const queryString = Object.keys(temp)
.map((key) => encodeURIComponent(key) + '=' + temp[key])
.join('&')
// 订单商品评论
orderComment: (id) => {
return request({
url: '/product/comment/get-by-order-id/' + id,
method: 'GET',
})
},
return request({
url: `/trade/order/page?${queryString}`,
method: 'GET',
})
},
// 订单详情
getOrderDetail: (data) => {
return request({
url: '/trade/order/get-detail',
method: 'GET',
params: data,
})
},
// 商品核销
orderVerification: (data) => {
return request({
url: '/trade/order/verify-code',
method: 'POST',
data: data,
})
},
// 完成订单
orderComplete: (data) => {
return request({
url: '/trade/order/completed-order',
method: 'POST',
data: data,
})
},
// 订单商品评论
orderComment: (id) => {
return request({
url: '/product/comment/get-by-order-id/' + id,
method: 'GET',
})
},
}
export default OrderUtil

View File

@ -64,7 +64,7 @@ const http = new Request({
http.interceptors.request.use(
(config) => {
console.log(config)
// console.log(config)
// 自定义处理【auth 授权】:必须登录的接口,否则提示登录
if (config.custom.auth && !$store('user').isLogin) {
// 处理登录

View File

@ -1,74 +1,71 @@
<template>
<view class="u-tabs">
<view class="u-tabs__wrapper">
<slot name="left" />
<view class="u-tabs__wrapper__scroll-view-wrapper">
<scroll-view
:scroll-x="scrollable"
:scroll-left="scrollLeft"
scroll-with-animation
enable-flex
class="u-tabs__wrapper__scroll-view white-space"
:show-scrollbar="false"
ref="u-tabs__wrapper__scroll-view"
>
<view class="u-tabs__wrapper__nav" ref="u-tabs__wrapper__nav">
<view
class="u-tabs__wrapper__nav__item"
v-for="(item, index) in list"
:key="index"
@tap="clickHandler(item, index)"
:ref="`u-tabs__wrapper__nav__item-${index}`"
:style="[addStyle(itemStyle), { flex: scrollable ? '' : 1 }]"
:class="[
`u-tabs__wrapper__nav__item-${index}`,
item.disabled && 'u-tabs__wrapper__nav__item--disabled',
]"
>
<text
:class="[item.disabled && 'u-tabs__wrapper__nav__item__text--disabled']"
class="u-tabs__wrapper__nav__item__text"
:style="[textStyle(index)]"
>{{ item[keyName] }}</text
>
</view>
<!-- #ifdef APP-NVUE -->
<view
class="u-tabs__wrapper__nav__line"
ref="u-tabs__wrapper__nav__line"
:style="[
{
width: addUnit(lineWidth),
height: addUnit(lineHeight),
background: lineColor ? lineColor : 'var(--ui-BG-Main)',
backgroundSize: lineBgSize,
},
]"
></view>
<!-- #endif -->
<!-- #ifndef APP-NVUE -->
<view
class="u-tabs__wrapper__nav__line"
ref="u-tabs__wrapper__nav__line"
:style="[
{
width: addUnit(lineWidth),
transform: `translate(${lineOffsetLeft}px)`,
transitionDuration: `${firstTime ? 0 : duration}ms`,
height: addUnit(lineHeight),
background: lineColor ? lineColor : 'var(--ui-BG-Main)',
backgroundSize: lineBgSize,
},
]"
>
</view>
<!-- #endif -->
</view>
</scroll-view>
<view class="u-tabs">
<view class="u-tabs__wrapper">
<slot name="left" />
<view class="u-tabs__wrapper__scroll-view-wrapper">
<scroll-view
:scroll-x="scrollable"
:scroll-left="scrollLeft"
scroll-with-animation
enable-flex
class="u-tabs__wrapper__scroll-view white-space"
:show-scrollbar="false"
ref="u-tabs__wrapper__scroll-view"
>
<view class="u-tabs__wrapper__nav" ref="u-tabs__wrapper__nav">
<view
class="u-tabs__wrapper__nav__item"
v-for="(item, index) in list"
:key="index"
@tap="clickHandler(item, index)"
:ref="`u-tabs__wrapper__nav__item-${index}`"
:style="[addStyle(itemStyle), { flex: scrollable ? '' : 1 }]"
:class="[`u-tabs__wrapper__nav__item-${index}`, item.disabled && 'u-tabs__wrapper__nav__item--disabled']"
>
<text
:class="[item.disabled && 'u-tabs__wrapper__nav__item__text--disabled']"
class="u-tabs__wrapper__nav__item__text"
:style="[textStyle(index)]"
>{{ item[keyName] }}</text
>
</view>
<slot name="right" />
</view>
<!-- #ifdef APP-NVUE -->
<view
class="u-tabs__wrapper__nav__line"
ref="u-tabs__wrapper__nav__line"
:style="[
{
width: addUnit(lineWidth),
height: addUnit(lineHeight),
background: lineColor ? lineColor : 'var(--ui-BG-Main)',
backgroundSize: lineBgSize,
},
]"
></view>
<!-- #endif -->
<!-- #ifndef APP-NVUE -->
<view
class="u-tabs__wrapper__nav__line"
ref="u-tabs__wrapper__nav__line"
:style="[
{
width: addUnit(lineWidth),
transform: `translate(${lineOffsetLeft}px)`,
transitionDuration: `${firstTime ? 0 : duration}ms`,
height: addUnit(lineHeight),
background: lineColor ? lineColor : 'var(--ui-BG-Main)',
backgroundSize: lineBgSize,
},
]"
>
</view>
<!-- #endif -->
</view>
</scroll-view>
</view>
<slot name="right" />
</view>
</view>
</template>
<script>
@ -90,343 +87,341 @@ const dom = uni.requireNativePlugin('dom')
* @example <u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
*/
export default {
name: 'pb-tabs',
data() {
name: 'pb-tabs',
data() {
return {
addStyle,
addUnit,
firstTime: true,
scrollLeft: 0,
scrollViewWidth: 0,
lineOffsetLeft: 0,
tabsRect: {
left: 0,
},
innerCurrent: 0,
moving: false,
}
},
props: {
// ms
duration: {
type: Number,
default: 300,
},
// tabs
list: {
type: Array,
default: [],
},
//
lineColor: {
type: String,
default: '',
},
//
activeStyle: {
type: [String, Object],
default() {
return {
addStyle,
addUnit,
firstTime: true,
scrollLeft: 0,
scrollViewWidth: 0,
lineOffsetLeft: 0,
tabsRect: {
left: 0,
},
innerCurrent: 0,
moving: false,
color: '#303133',
}
},
},
props: {
// ms
duration: {
type: Number,
default: 300,
},
// tabs
list: {
type: Array,
default: [],
},
//
lineColor: {
type: String,
default: '',
},
//
activeStyle: {
type: [String, Object],
default() {
return {
color: '#303133',
}
},
},
//
inactiveStyle: {
type: [String, Object],
default() {
return {
color: '#606266',
}
},
},
//
lineWidth: {
type: [String, Number],
default: 20,
},
//
lineHeight: {
type: [String, Number],
default: 3,
},
// 使
lineBgSize: {
type: String,
default: 'cover',
},
// item
itemStyle: {
type: [String, Object],
default() {
return {
height: '44px',
}
},
},
//
scrollable: {
type: Boolean,
default: true,
},
//
current: {
type: [Number, String],
default: 0,
},
//
keyName: {
type: String,
default: 'name',
},
//
inactiveStyle: {
type: [String, Object],
default() {
return {
color: '#606266',
}
},
},
watch: {
current: {
immediate: true,
handler(newValue, oldValue) {
//
if (newValue !== this.innerCurrent) {
this.innerCurrent = newValue
this.$nextTick(() => {
this.resize()
})
}
},
},
// listlist
list() {
this.$nextTick(() => {
this.resize()
})
},
//
lineWidth: {
type: [String, Number],
default: 20,
},
computed: {
textStyle() {
return (index) => {
const style = {}
//
const customeStyle =
index === this.innerCurrent ? addStyle(this.activeStyle) : addStyle(this.inactiveStyle)
// nvuestyle!import
if (this.list[index].disabled) {
style.color = '#c8c9cc'
}
return deepMerge(customeStyle, style)
}
},
//
lineHeight: {
type: [String, Number],
default: 3,
},
async mounted() {
this.init()
// 使
lineBgSize: {
type: String,
default: 'cover',
},
methods: {
$uGetRect(selector, all) {
return new Promise((resolve) => {
uni.createSelectorQuery()
.in(this)
[all ? 'selectAll' : 'select'](selector)
.boundingClientRect((rect) => {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect)
}
if (!all && rect) {
resolve(rect)
}
})
.exec()
})
},
setLineLeft() {
const tabItem = this.list[this.innerCurrent]
if (!tabItem) {
return
}
//
let lineOffsetLeft = this.list
.slice(0, this.innerCurrent)
.reduce((total, curr) => total + curr.rect.width, 0)
// 线px
const lineWidth = getPx(this.lineWidth)
this.lineOffsetLeft = lineOffsetLeft + (tabItem.rect.width - lineWidth) / 2
// #ifdef APP-NVUE
//
this.animation(this.lineOffsetLeft, this.firstTime ? 0 : parseInt(this.duration))
// #endif
// tab item
// nvuestylefalse()
if (this.firstTime) {
setTimeout(() => {
this.firstTime = false
}, 10)
}
},
// nvue
animation(x, duration = 0) {
// #ifdef APP-NVUE
const ref = this.$refs['u-tabs__wrapper__nav__line']
animation.transition(ref, {
styles: {
transform: `translateX(${x}px)`,
},
duration,
})
// #endif
},
//
clickHandler(item, index) {
// disabledclickchange
this.$emit('click', {
...item,
index,
})
// disabled
if (item.disabled) return
this.innerCurrent = index
// item
itemStyle: {
type: [String, Object],
default() {
return {
height: '44px',
}
},
},
//
scrollable: {
type: Boolean,
default: true,
},
//
current: {
type: [Number, String],
default: 0,
},
//
keyName: {
type: String,
default: 'name',
},
},
watch: {
current: {
immediate: true,
handler(newValue, oldValue) {
//
if (newValue !== this.innerCurrent) {
this.innerCurrent = newValue
this.$nextTick(() => {
this.resize()
this.$emit('change', {
...item,
index,
})
},
init() {
sleep().then(() => {
this.resize()
})
},
setScrollLeft() {
// tabtabwidthleft()
const tabRect = this.list[this.innerCurrent]
// item
const offsetLeft = this.list.slice(0, this.innerCurrent).reduce((total, curr) => {
return total + curr.rect.width
}, 0)
//
const windowWidth = sys().windowWidth
// tabs-itemscroll-view
let scrollLeft =
offsetLeft -
(this.tabsRect.width - tabRect.rect.width) / 2 -
(windowWidth - this.tabsRect.right) / 2 +
this.tabsRect.left / 2
// scrollLeftscroll-viewtabs
scrollLeft = Math.min(scrollLeft, this.scrollViewWidth - this.tabsRect.width)
this.scrollLeft = Math.max(0, scrollLeft)
},
//
resize() {
// list
if (this.list.length === 0) {
return
}
Promise.all([this.getTabsRect(), this.getAllItemRect()]).then(([tabsRect, itemRect = []]) => {
this.tabsRect = tabsRect
this.scrollViewWidth = 0
itemRect.map((item, index) => {
// scroll-view
this.scrollViewWidth += item.width
// itemX
this.list[index].rect = item
})
// tabs
this.setLineLeft()
this.setScrollLeft()
})
},
//
getTabsRect() {
return new Promise((resolve) => {
this.queryRect('u-tabs__wrapper__scroll-view').then((size) => resolve(size))
})
},
//
getAllItemRect() {
return new Promise((resolve) => {
const promiseAllArr = this.list.map((item, index) =>
this.queryRect(`u-tabs__wrapper__nav__item-${index}`, true)
)
Promise.all(promiseAllArr).then((sizes) => resolve(sizes))
})
},
//
queryRect(el, item) {
// #ifndef APP-NVUE
// $uGetRectuViewhttps://www.uviewui.com/js/getRect.html
// this.$uGetRectuni.$u.getRect
return new Promise((resolve) => {
this.$uGetRect(`.${el}`).then((size) => {
resolve(size)
})
})
// #endif
// #ifdef APP-NVUE
// nvue使dom
// promise使then
return new Promise((resolve) => {
dom.getComponentRect(item ? this.$refs[el][0] : this.$refs[el], (res) => {
resolve(res.size)
})
})
// #endif
},
})
}
},
},
// listlist
list() {
this.$nextTick(() => {
this.resize()
})
},
},
computed: {
textStyle() {
return (index) => {
const style = {}
//
const customeStyle = index === this.innerCurrent ? addStyle(this.activeStyle) : addStyle(this.inactiveStyle)
// nvuestyle!import
if (this.list[index].disabled) {
style.color = '#c8c9cc'
}
return deepMerge(customeStyle, style)
}
},
},
async mounted() {
this.init()
},
methods: {
$uGetRect(selector, all) {
return new Promise((resolve) => {
uni
.createSelectorQuery()
.in(this)
[all ? 'selectAll' : 'select'](selector)
.boundingClientRect((rect) => {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect)
}
if (!all && rect) {
resolve(rect)
}
})
.exec()
})
},
setLineLeft() {
const tabItem = this.list[this.innerCurrent]
if (!tabItem) {
return
}
//
let lineOffsetLeft = this.list.slice(0, this.innerCurrent).reduce((total, curr) => total + curr.rect.width, 0)
// 线px
const lineWidth = getPx(this.lineWidth)
this.lineOffsetLeft = lineOffsetLeft + (tabItem.rect.width - lineWidth) / 2
// #ifdef APP-NVUE
//
this.animation(this.lineOffsetLeft, this.firstTime ? 0 : parseInt(this.duration))
// #endif
// tab item
// nvuestylefalse()
if (this.firstTime) {
setTimeout(() => {
this.firstTime = false
}, 10)
}
},
// nvue
animation(x, duration = 0) {
// #ifdef APP-NVUE
const ref = this.$refs['u-tabs__wrapper__nav__line']
animation.transition(ref, {
styles: {
transform: `translateX(${x}px)`,
},
duration,
})
// #endif
},
//
clickHandler(item, index) {
// disabledclickchange
this.$emit('click', {
...item,
index,
})
// disabled
if (item.disabled) return
this.innerCurrent = index
this.resize()
this.$emit('change', {
...item,
index,
})
},
init() {
sleep().then(() => {
this.resize()
})
},
setScrollLeft() {
// tabtabwidthleft()
const tabRect = this.list[this.innerCurrent]
// item
const offsetLeft = this.list.slice(0, this.innerCurrent).reduce((total, curr) => {
return total + curr.rect.width
}, 0)
//
const windowWidth = sys().windowWidth
// tabs-itemscroll-view
let scrollLeft =
offsetLeft -
(this.tabsRect.width - tabRect.rect.width) / 2 -
(windowWidth - this.tabsRect.right) / 2 +
this.tabsRect.left / 2
// scrollLeftscroll-viewtabs
scrollLeft = Math.min(scrollLeft, this.scrollViewWidth - this.tabsRect.width)
this.scrollLeft = Math.max(0, scrollLeft)
},
//
resize() {
// list
if (this.list.length === 0) {
return
}
Promise.all([this.getTabsRect(), this.getAllItemRect()]).then(([tabsRect, itemRect = []]) => {
this.tabsRect = tabsRect
this.scrollViewWidth = 0
itemRect.map((item, index) => {
// scroll-view
this.scrollViewWidth += item.width
// itemX
this.list[index].rect = item
})
// tabs
this.setLineLeft()
this.setScrollLeft()
})
},
//
getTabsRect() {
return new Promise((resolve) => {
this.queryRect('u-tabs__wrapper__scroll-view').then((size) => resolve(size))
})
},
//
getAllItemRect() {
return new Promise((resolve) => {
const promiseAllArr = this.list.map((item, index) =>
this.queryRect(`u-tabs__wrapper__nav__item-${index}`, true)
)
Promise.all(promiseAllArr).then((sizes) => resolve(sizes))
})
},
//
queryRect(el, item) {
// #ifndef APP-NVUE
// $uGetRectuViewhttps://www.uviewui.com/js/getRect.html
// this.$uGetRectuni.$u.getRect
return new Promise((resolve) => {
this.$uGetRect(`.${el}`).then((size) => {
resolve(size)
})
})
// #endif
// #ifdef APP-NVUE
// nvue使dom
// promise使then
return new Promise((resolve) => {
dom.getComponentRect(item ? this.$refs[el][0] : this.$refs[el], (res) => {
resolve(res.size)
})
})
// #endif
},
},
}
</script>
<style lang="scss" scoped>
.u-tabs {
background: #fff;
border-bottom: 2rpx solid #eee;
background: #fff;
border-bottom: 2rpx solid #eee;
&__wrapper {
&__wrapper {
@include flex;
align-items: center;
&__scroll-view-wrapper {
flex: 1;
/* #ifndef APP-NVUE */
overflow: auto hidden;
/* #endif */
}
&__nav {
@include flex;
position: relative;
&__item {
padding: 0 11px;
@include flex;
align-items: center;
justify-content: center;
&__scroll-view-wrapper {
flex: 1;
/* #ifndef APP-NVUE */
overflow: auto hidden;
/* #endif */
&--disabled {
/* #ifndef APP-NVUE */
cursor: not-allowed;
/* #endif */
}
&__nav {
@include flex;
position: relative;
&__text {
font-size: 14px;
color: #606266;
white-space: nowrap !important;
&__item {
padding: 0 11px;
@include flex;
align-items: center;
justify-content: center;
&--disabled {
/* #ifndef APP-NVUE */
cursor: not-allowed;
/* #endif */
}
&__text {
font-size: 14px;
color: #606266;
white-space: nowrap !important;
&--disabled {
color: #c8c9cc !important;
}
}
}
&__line {
height: 3px;
background: #3c9cff;
width: 30px;
position: absolute;
bottom: 2px;
border-radius: 100px;
transition-property: transform;
transition-duration: 300ms;
}
&--disabled {
color: #c8c9cc !important;
}
}
}
&__line {
height: 3px;
background: #3c9cff;
width: 30px;
position: absolute;
bottom: 2px;
border-radius: 100px;
transition-property: transform;
transition-duration: 300ms;
}
}
}
}
</style>