<!--
 * @Title: 
 * @Description: 应急人员
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <el-row>
            <el-col :span="24">
                <basic-container>
                    <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page"
                        :before-open="beforeOpen" ref="crud" v-model="form" :permission="permissionList"
                        @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
                        @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
                        @on-load="onLoad" @before-open="beforeOpen" @select-change="selectChange">
                        <template slot-scope="{ row, index }" slot="menu">
                            <el-button type="text" size="small" @click="toCheckInfo(row)">查看图片
                            </el-button>
                        </template>
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
        <el-drawer :visible.sync="yjdangerareacheckdetailDialog" v-if="yjdangerareacheckdetailDialog" title="图片"
            direction="rtl" size="60%" append-to-body="true">
            <yjdangerareacheckdetail ref="yjdangerareacheckdetailView" :id="id">
            </yjdangerareacheckdetail>
        </el-drawer>
    </div>
</template>

<script>


import { getPage, getDetail } from "@/api/business/yj/yjdangerareacheck.js";
import { mapGetters } from "vuex";
import yjdangerareacheckdetail from './yjdangerareacheckdetail.vue'

export default {
    components: {
        yjdangerareacheckdetail
    },
    data() {
        return {
            id: "",
            editForm: {},
            editDialog: false,
            yjdangerareacheckdetailDialog: false,
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 140,
                viewLabelWidth: 140,
                searchlabelWidth: 140,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                border: true,
                index: true,
                selection: false,
                viewBtn: false,
                viewTitle: "现场巡检",
                editBtn: true,
                delBtn: true,
                menuWidth: 220,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                menu: true,
                column: [
                    {
                        label: "巡查类型",
                        prop: "checkType",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            let htmltext = '';
                            if (val.isHouseholder === 1) {
                                htmltext = '<b style="color:blue">独立巡查</b>';
                            } else {
                                htmltext = '<b style="color:blue">应急发起巡查</b>';
                            }
                            return htmltext;
                        }
                    },
                    {
                        label: "经度",
                        prop: "longitude",
                        span: 24,
                    },
                    {
                        label: "纬度",
                        prop: "latitude",
                        span: 24,
                    },
                    {
                        label: "定位地址",
                        prop: "address",
                        span: 24,
                    },
                    {
                        label: "是否有山洪",
                        prop: "isFlood",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            let htmltext = '';
                            if (val.isFlood === 0) {
                                htmltext = '<b style="color:blue">否</b>';
                            } else {
                                htmltext = '<b style="color:red">是</b>';
                            }
                            return htmltext;
                        }
                    },
                    {
                        label: "是否成灾",
                        prop: "isDamage",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            let htmltext = '';
                            if (val.isDamage === 0) {
                                htmltext = '<b style="color:blue">否</b>';
                            } else {
                                htmltext = '<b style="color:red">是</b>';
                            }
                            return htmltext;
                        }
                    },
                    {
                        label: "巡查说明",
                        prop: "remark",
                        span: 24,
                    },
                    {
                        label: "巡查时间",
                        prop: "createTime",
                        span: 24,
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                addBtn: this.vaildData(this.permission.yjxt_service_person_add, false),
                viewBtn: this.vaildData(this.permission.yjxt_service_person_view, false),
                delBtn: this.vaildData(this.permission.yjxt_service_person_del, false),
                editBtn: this.vaildData(this.permission.yjxt_service_person_edit, false),
            };
        },
        ids() {
            let ids = [];
            this.selectionList.forEach((ele) => {
                ids.push(ele.id);
            });
            return ids.join(",");
        },
    },
    mounted() { },
    created() {
    },
    methods: {
        toCheckInfo(row) {
            this.id = row.id;
            this.yjdangerareacheckdetailDialog = true;
            this.$nextTick(() => {
                this.$refs["yjdangerareacheckdetailView"].initData();
            });
        },
        searchReset() {
            this.query = {};
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
        },
        selectionChange(list) {
            this.selectionList = list;
        },
        selectChange(item) {
            console.log(item)
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },

        beforeOpen(done, type) {
            if (["edit", "view"].includes(type)) {
                getDetail(this.form.id).then((res) => {
                    this.form = res.data.data;
                });
            }
            done();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            getPage(
                page.currentPage,
                page.pageSize,
                Object.assign(params, this.query)
            ).then((res) => {
                const data = res.data.data;
                this.page.total = data.total;
                this.data = data.records;
                this.loading = false;
                this.selectionClear();
            });
        },
    },
};
</script>
