<template>
    <view class="container">
        <view class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
            <view class="searchBox_add" @click="addCommunity">
                <image class="top-image" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/workOrder_community.png" mode="aspectFill"></image>
                <view class="emptyCommunity">
                    {{ communityVal }}
                </view>
            </view>
        </view>
        <!-- 背景图片区域 -->
        <view class="bg-image-container">
            <image class="bg-image" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/workOrderDashboardImg.png" mode=""></image>
        </view>
        <view class="work-order-section">
            <view v-for="(item, index) in 9" :key="index">
                <view class="work-order-card" v-if="index == 0 && showWorkOrderSection"
                    @click="navigateToWorkOrderDashboard">
                    <image class="work-order-icon" src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/workOrder.png" mode="aspectFill" />
                    <text class="work-order-text">工单台</text>
                </view>
                <view class="work-order-card" v-else></view>
            </view>
        </view>
    </view>
</template>

<script>
import {
    request,
    picUrl,
    uniqueByField,
    menuButtonInfo,
    NavgateTo,
} from "../../../utils";

import { apiArr } from "../../../api/community";

export default {
    data() {
        return {
            communityVal: "添加我的房产",
            showWorkOrderSection: false
        }
    },
    onLoad() {
        const workOrderPermission = uni.getStorageSync('work_order_permission');
        const orderDispatchPermission = uni.getStorageSync('order_dispatch_permission');
        this.showWorkOrderSection = !(workOrderPermission === false && orderDispatchPermission === false);
    },
    async onShow() {
        this.communityVal = uni.getStorageSync('changeCommData').name;
        const params = {
            community_id: uni.getStorageSync('changeCommData').id,
        }
        const res = await request(apiArr.communityInfo, "POST", params);
        uni.setStorageSync('allow_grab_order', res.allow_grab_order == 1 ? true : false);
    },
    methods: {
        addCommunity() {
            NavgateTo("/packages/workOrderDashboard/myCommunity/index");
        },

        // 跳转到工单台
        navigateToWorkOrderDashboard() {
            uni.navigateTo({
                url: '/packages/workOrderDashboard/index/index?communityId=' + uni.getStorageSync('changeCommData').id
            });
        }
    }
}
</script>

<style scoped>
/* 引入外部CSS文件 */
@import url("./index.css");
</style>