<template>
    <view :loading="loading">
        <!-- <uni-nav-bar left-icon="left" right-icon="cart" title="标题" /> -->
        <uni-nav-bar dark :fixed="true" status-bar left-icon="left" :rightIcon="userInfo.authorities === 'app_vip_user' || userInfo.authorities === 'engineering_user'
            ? 'plusempty'
            : ''
            " background-color="#fff" color="#111" title="工程管理" @clickLeft="back" @clickRight="add" />
        <uni-search-bar v-model="store.params.name" clearButton="none" bgColor="#fff" placeholder="请输入关键词"
            @input="store.search()"></uni-search-bar>
        <view class="message">



            <view v-for="(item, index) in store.data" :key="index" style="margin: 0px 8px 8px;">
                <!-- extra="🔍" -->
                <uni-card class="boxClick" :title="item.name" @click="jump(item)">
                    <view class="term-list-bottom">
                        <view class="term-list-bottom-item">
                            <view>区域</view>
                            <view>{{ item.provinceName + item.cityName }}</view>
                        </view>
                        <view class="term-list-bottom-item">
                            <view>创建时间</view>
                            <view>{{ item.createTime }}</view>
                        </view>
                    </view>
                   
                </uni-card>
                </view>




                <Cn-empty v-if="store.empty" style="padding-top: 400rpx"></Cn-empty>
                <uni-load-more v-if="store.status == 'loading' || (store.data && store.data.length > 0)"
                    :status="store.status"></uni-load-more>
            </view>
        </view>
</template>

<script>
import list from '../../common/js/list'
import { engineeringPinToTop } from '@/common/api/device'

export default {
    mixins: [list],
    data() {
        return {
            loading: true,
            userInfo: {},
            options1: [
                {
                    text: '置顶',
                    style: {
                        backgroundColor: '#376cf3',
                    },
                },
            ],
            options12: [
                {
                    text: '取消',
                    style: {
                        backgroundColor: '#ccc',
                    },
                },
            ],
        }
    },
    methods: {
        bindClick(e, item) {
            engineeringPinToTop({
                targetId: item.id,
                targetType: 2,
                userId: uni.getStorageSync(this.$cacheKey.userInfo).userIndex,
            }).then((res) => {
                if (res.code == 'A0000') {
                    this.$util.toast('操作成功!')
                    this.store.search()
                } else {
                    this.$util.toast(res.message)
                }
            })
        },
        init() {
            this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
            this.store = this.DataSource('/cs-device-boot/engineering/queryEngineeringPage')
            this.store.params.name = ''
            this.store.reload()
            this.store.firstCallBack = (res) => {
                let engineering = uni.getStorageSync('engineering')
                if (!engineering) {
                    uni.setStorageSync('engineering', this.store.data[0])
                } else {
                    this.store.data.forEach((item) => {
                        if (item.id == engineering.id) {
                            uni.setStorageSync('engineering', item)
                        }
                    })
                }
            }
        },
        back() {
            uni.navigateBack()
        },
        add() {
            if (this.userInfo.authorities === 'app_vip_user' || this.userInfo.authorities === 'engineering_user') {
                uni.navigateTo({
                    url: `/pages/engineering/new`,
                })
            }
        },
        upgrade(code) {
            console.log(code)
            uni.showToast({
                title: '升级成功',
                icon: 'none',
            })
        },
        jump(engineering) {
            uni.navigateTo({
                url: `/pages/engineering/detail?engineering=${encodeURIComponent(JSON.stringify(engineering))}`,
            })
        },
    },

    onLoad() {
        this.init()
    },
}
</script>

<style lang="scss">
.message {
    .message-header {
        padding: 200rpx 34rpx 34rpx;
        display: flex;
        align-items: center;
        background: $uni-theme-white;
        margin-bottom: 20rpx;
        box-shadow: 0 4rpx 8rpx #e7e7e74c;

        .message-header-head {
            margin-right: 30rpx;
            height: 128rpx;
            width: 128rpx;
            border-radius: $uni-theme-radius;
            overflow: hidden;
        }

        .message-header-name {
            margin-right: 30rpx;
            flex: 1;
            font-size: 36rpx;
            color: #111;
            font-weight: 700;

            .tag {
                margin-top: 10rpx;
                font-size: 24rpx;
                color: #aaa;
            }
        }
    }

    .message-nav {
        padding: 34rpx;
        display: flex;
        align-items: center;
        background: $uni-theme-white;
        border-bottom: 1rpx solid #e8e8e8;

        &-icon {
            margin-right: 30rpx;
            height: 44rpx;
            width: 44rpx;
            border-radius: $uni-theme-radius;
            overflow: hidden;
        }

        &-label {
            margin-right: 30rpx;
            flex: 1;
            font-size: 28rpx;
            color: #111;
        }
    }
}

.term-list-bottom {
    .term-list-bottom-item {
        font-size: 28rpx;
        // margin-bottom: 20rpx;
        display: flex;
        justify-content: space-between;
        // view:first-of-type{
        //     color: #111;
        // }
    }

    .term-list-bottom-item:last-of-type {
        margin-bottom: 0;
    }
}

/deep/ .uni-card--border {
    margin: 0 0px !important;
    padding-bottom: 10px;
}

/deep/ .uni-swipe {

    margin-bottom: 10px;
}

.pinToTop {
    background-color: $uni-theme-color;
    width: 100rpx;
    height: 60rpx;
    line-height: 90rpx;
    text-align: center;
    color: #fff;
    font-size: 20rpx;
    position: absolute;
    top: 0rpx;
    right: 0rpx;
    position: absolute;
    top: 0;
    right: 0;

    /* 核心：旋转成斜三角效果 */
    transform: rotate(45deg) translate(50rpx, -10rpx);
    transform-origin: top right;
}

/deep/ .uni-card__content {
    padding: 5px 10px 10px !important;
}

/deep/ .uni-card__header-content-title {
    font-weight: 700;
}
</style>
