<template>
    <view>
        <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">动火审批表</block>
        </cu-custom>
        <view class="form">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">申请单位：</view>
                    {{ form.APPLY_DEPARTMENT_NAME }}
                </view>
                <view class="cu-form-group">
                    <view class="title">申请办理人：</view>
                    {{ form.APPLY_USER_NAME }}
                </view>
                <view class="cu-form-group">
                    <view class="title">作业编号：</view>
                    {{form.JOB_NUMBER}}
                </view>
                <view class="cu-form-group">
                    <view class="title">申请日期：</view>
                    {{ form.APPLICATION_DATE }}
                </view>
                <view class="cu-form-group">
                    <view class="title">作业类型：</view>
                    {{ form.JOB_TYPE_NAME }}
                </view>
                <view class="cu-form-group">
                    <view class="title">动火部位：</view>
                    {{form.HOT_WORK_POSITION}}
                </view>
                <view class="cu-form-group">
                    <view class="title">动火方法：</view>
                    {{ form.HOT_WORK_METHOD_NAME}}
                </view>
                <view class="cu-form-group">
                    <view class="title">动火等级：</view>
                    {{ form.HOT_WORK_LEVEL_NAME}}
                </view>
                <view class="cu-form-group">
                    <view class="title">动火开始时间：</view>
                    {{ form.HOT_WORK_TIME_START }}
                </view>
                <view class="cu-form-group">
                    <view class="title">动火结束时间：</view>
                    {{ form.HOT_WORK_TIME_END }}
                </view>
                <view class="cu-form-group" v-if="form.WORK_LONGITUDE">
                    <view class="title">作业地点经度：</view>
                    <view>{{form.WORK_LONGITUDE}}</view>
                </view>
                <view class="cu-form-group" v-if="form.WORK_LATITUDE">
                    <view class="title">作业地点纬度：</view>
                    <view>{{form.WORK_LATITUDE}}</view>
                </view>
                <view class="cu-form-group">
                    <view class="title">作业内容：</view>
                    {{form.JOB_CONTENT}}
                </view>
            </view>
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">现场负责人部门：</view>
                    {{form.SITE_LEADER_DEPARTMENT_NAME}}
                </view>
                <view class="cu-form-group">
                    <view class="title">现场负责人：</view>
                    {{form.SITE_LEADER_NAME}}
                </view>
                <view class="cu-form-group">
                    <view class="title">现场负责人手机号：</view>
                    {{form.SITE_LEADER_PHONE}}
                </view>
            </view>
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">动火操作人：</view>
                    <uni-table border stripe emptyText="暂无更多数据" style="flex:1;margin: 20upx 0">
                        <uni-tr></uni-tr>
                        <uni-tr v-for="item in form.HOT_WORK_OPERATOR_NAME" :key="item">
                            <uni-td>{{ item }}</uni-td>
                        </uni-tr>
                    </uni-table>
                </view>
                <view class="cu-form-group">
                    <view class="title">动火监火人：</view>
                    {{form.SUPERVISOR_OF_HOT_WORK_UNIT}}
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view style="padding: 20upx">
                <uni-table border stripe emptyText="暂无更多数据">
                    <uni-tr>
                        <uni-th align="center" style="font-weight: bold;width: 100upx">序号</uni-th>
                        <uni-th align="center" style="font-weight: bold">主要安全措施</uni-th>
                        <uni-th align="center" style="font-weight: bold;width: 180upx">操作</uni-th>
                    </uni-tr>
                    <uni-tr v-for="(item,index) in measureList" :key="item.PROTECTIVE_MEASURES">
                        <uni-td>{{ index + 1 }}</uni-td>

                        <uni-td>
                            <view style="margin-bottom: 20upx;">
                                {{item.PROTECTIVE_MEASURES}}
                            </view>
                            <view class="wui-border"
                                  v-if="item.QUESTION1 || item.QUESTION2 || item.QUESTION3 || item.QUESTION4">
                                <view class="cu-form-group" v-if="item.QUESTION1">
                                    <view class="title">{{item.QUESTION1}}</view>
                                    <input name="input" disabled v-model="item.ANSWER1" placeholder="请输入"></input>
                                </view>
                                <view class="cu-form-group" v-if="item.QUESTION2">
                                    <view class="title">{{item.QUESTION2}}</view>
                                    <input name="input" disabled v-model="item.ANSWER2" placeholder="请输入"></input>
                                </view>
                                <view class="cu-form-group" v-if="item.QUESTION3">
                                    <view class="title">{{item.QUESTION3}}</view>
                                    <input name="input" disabled v-model="item.ANSWER3" placeholder="请输入"></input>
                                </view>
                                <view class="cu-form-group" v-if="item.QUESTION4">
                                    <view class="title">{{item.QUESTION4}}</view>
                                    <input name="input" disabled v-model="item.ANSWER4" placeholder="请输入"></input>
                                </view>
                            </view>
                        </uni-td>
                        <uni-td>符合</uni-td>
                    </uni-tr>
                </uni-table>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="cu-form-group">
                <view class="title">其他安全措施：</view>
                <!-- <button class="cu-btn round bg-blue" @click="addOther">添加</button> -->
            </view>
            <view class="ace-content" v-show="oldOtherMeasure && oldOtherMeasure.length > 0">
                <view class="add_pard_item" v-for="(item,index) of oldOtherMeasure">
                    <!-- <view v-if="!forbidEdit" class="add_pard_del" @click="removeOldMeasure(index)">
                      <text class="cuIcon-roundclosefill text-red f40"></text>
                    </view> -->
                    <view class="cu-form-textarea">
                        <textarea disabled="true" placeholder="请输入其他安全措施..." v-model="item.CONTENT"></textarea>
                    </view>
                </view>
            </view>
            <!-- <view class="ace-content" v-show="otherMeasure && otherMeasure.length > 0">
                <view class="add_pard_item" v-for="(item,index) of otherMeasure">
                  <view class="add_pard_del" @click="removeMeasure(index)">
                    <text class="cuIcon-roundclosefill text-red f40"></text>
                  </view>
                  <view class="cu-form-textarea">
                    <textarea placeholder="请输入其他安全措施..." v-model="otherMeasure[index]"></textarea>
                  </view>
                </view>
            </view> -->
        </view>
        <view class="wui-form-list" v-if="form.IS_GAS_TESTING =='1'">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">气体分析人：</view>
                    {{form.GAS_TESTING_USER_NAME}}
                    <button class="cu-btn bg-blue margin-tb-sm sm"
                            @click.stop="$noMultipleClicks(goToGasDelay,form.HOTWORKAPPLICATION_ID)">气体检测信息
                    </button>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">动火单位负责人：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.HOT_WORK_USER_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.HOT_WORK_USER_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list" v-if="form.JOB_TYPE_INDEX =='1'">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">项目发包单位：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.PROJECT_UNIT_LEADER_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.PROJECT_UNIT_LEADER_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>

        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">现场管辖单位负责人：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.UNIT_LEADER_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.UNIT_LEADER_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">动火许可签发单位负责人：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.ISSUING_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.ISSUING_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list" v-if="form.IS_SAFETY_DIRECTOR =='1'">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">安全总监负责人：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.SAFETY_DIRECTOR_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.SAFETY_DIRECTOR_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">现场负责人接收负责人：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.SITE_DIRECTOR_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.SITE_DIRECTOR_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">动火前现场管辖单位确认：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.HOT_WORK_PERSON_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.HOT_WORK_PERSON_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">现场负责人确认：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.PERSON_CONFIRM_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.PERSON_CONFIRM_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="wui-form-list">
                <view class="cu-form-group">
                    <view class="title">动火后现场管辖人：</view>
                    <view>
                        <view>
                            <image :src="baseImgPath + form.HOT_WORK_AFTER_PRINCIPAL"
                                   style="width: 330upx;height: 260upx"></image>
                        </view>
                        <view style="text-align: center">{{form.HOT_WORK_AFTER_PRINCIPAL_TIME}}</view>
                    </view>
                </view>
            </view>
        </view>
        <view class="wui-form-list">
            <view class="cu-form-group">
                <view class="title">延时监火</view>
                <button class="cu-btn bg-blue margin-tb-sm lg"
                        @click="$noMultipleClicks(goToDelay,form.HOTWORKAPPLICATION_ID)">记录
                </button>
            </view>
        </view>

        <view class="cu-bar btn-group" style="margin-top: 30upx;">
            <!--      <button class="cu-btn bg-grey margin-tb-sm lg" @click="confirmType(1)">确认打回</button>-->
            <button class="cu-btn bg-grey margin-tb-sm lg" @click="goback">取消</button>
        </view>
        <view class="padding flex flex-direction"></view>
    </view>
</template>

<script>
    import {
        basePath,
        loginUserId,
        loginSession,
        corpinfoId,
        baseImgPath
    } from '@/common/tool.js';
    import sign from '@/components/sign/sign.vue';
    import tkiTree from "@/components/select-tree/select-tree.vue"

    export default {
        components: {
            sign,
            tkiTree
        },
        data() {
            return {
                baseImgPath,
                noClick: true,
                form: {
                    HOTWORKAPPLICATION_ID: '',
                    APPLY_DEPARTMENT_NAME: '',
                    APPLY_USER_NAME: '',
                    JOB_NUMBER: '',
                    APPLICATION_DATE: '',
                    JOB_TYPE_INDEX: '',
                    JOB_TYPE_ID: '',
                    JOB_TYPE_NAME: '',
                    HOT_WORK_POSITION: '',
                    HOT_WORK_METHOD_ID: '',
                    HOT_WORK_METHOD_NAME: '',
                    HOT_WORK_LEVEL_INDEX: '',
                    HOT_WORK_LEVEL_ID: '',
                    HOT_WORK_LEVEL_NAME: '',
                    HOT_WORK_APPLICATION_DEPARTMENT_ID: '',
                    HOT_WORK_APPLICATION_DEPARTMENT_NAME: '',
                    DEPARTMENT_PERSONNEL_ID: '',
                    DEPARTMENT_PERSONNEL_NAME: '',
                    JOB_CONTENT: '',
                    SITE_LEADER_ID: '',
                    SITE_LEADER_NAME: '',
                    SITE_LEADER_PHONE: '',
                    SUPERVISOR_OF_HOT_WORK_UNIT: '',
                    HOT_WORK_TIME: '',
                    WORK_LONGITUDE: '',
                    WORK_LATITUDE: '',
                    HOT_WORK_UNIT_LEADER_ID: '',
                    HOT_WORK_UNIT_LEADER_NAME: '',
                    UNIT_LEADER_ID: '',
                    UNIT_LEADER_NAME: '',
                    PROJECT_UNIT_LEADER_ID: '',
                    PROJECT_UNIT_LEADER_NAME: '',
                    HOT_WORK_PERMIT_ISSUING_UNIT: '',
                    HOT_WORK_OPERATOR_NAME: [],
                    OPINION: '',
                    UNIT_PRINCIPAL: '',
                    UNIT_PRINCIPAL_TIME: '',
                    CONTRACTING_UNIT: '',
                    CONTRACTING_UNIT_TIME: '',
                    ON_SITE_JURISDICTION: '',
                    ON_SITE_JURISDICTION_TIME: '',
                    HOT_WORK_BEFORE_UNIT_LEADER: '',
                    HOT_WORK_BEFORE_UNIT_LEADER_TIME: '',
                    HOT_WORK_AFTER_UNIT_LEADER_DEPARTMENT_ID: '',
                    HOT_WORK_AFTER_UNIT_LEADER_DEPARTMENT_NAME: '',
                    HOT_WORK_AFTER_UNIT_LEADER_INDEX: '',
                    HOT_WORK_AFTER_UNIT_LEADER_ID: '',
                    HOT_WORK_AFTER_UNIT_LEADER_NAME: '',
                },
                measureList: [],
                imgList: [],
                modalShow: false,
                submitType: '',
                timeLapseFiremanList: [],
                treeNode: [],
                // 其他安全措施

                oldOtherMeasure: [],
            }
        },
        onLoad(event) {
            this.form.HOTWORKAPPLICATION_ID = event.id
            this.getData();
            loginSession();
            this.getMeasureList();
            this.getDept();
        },
        methods: {
            getData() {
                var _this = this;
                uni.showLoading({
                    title: '请稍候'
                })
                uni.request({
                    url: basePath + '/app/hotworkapplication/goEdit',
                    method: 'POST',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        HOTWORKAPPLICATION_ID: _this.form.HOTWORKAPPLICATION_ID,
                    },
                    success: (res) => {
                        if ("success" == res.data.result) {
                            this.form = res.data.pd;
                            this.oldOtherMeasure = res.data.safetymethodrecordList
                            let HOT_WORK_OPERATOR_NAME = res.data.pd.HOT_WORK_OPERATOR_NAME
                            this.form.HOT_WORK_OPERATOR_NAME = HOT_WORK_OPERATOR_NAME.substring(0, HOT_WORK_OPERATOR_NAME.length - 1).split(',');
                            uni.hideLoading();
                        } else if ("exception" == res.data.result) {
                            uni.showToast({
                                title: '错误',
                                duration: 2000
                            });
                        }
                    }
                });
            },
            getMeasureList() {
                var _this = this
                uni.request({
                    url: basePath + '/app/hotworkapplication/listAllMeasures',
                    method: 'POST',
                    dataType: 'json',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        HOTWORKAPPLICATION_ID: _this.form.HOTWORKAPPLICATION_ID
                    },
                    success: (res) => {
                        this.measureList = res.data.varList
                    }
                })
            },
            getDept() {
                let _this = this;
                uni.request({
                    url: basePath + '/app/sys/listTree', //部门下拉接口
                    method: 'POST',
                    dataType: 'json',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        CORPINFO_ID: corpinfoId,
                    },
                    success: (res) => {
                        if ("success" == res.data.result) {
                            _this.treeNode = eval(res.data.zTreeNodes);
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                duration: 2000
                            });
                        }
                    }
                });
            },
            confirmType(submitType) {
                this.imgList = [];
                this.submitType = submitType;
                this.modalShow = true
            },
            subCanvas(e) {
                this.imgList.push(e);
                this.modalShow = false;
                this.$nextTick(() => {
                    this.$noMultipleClicks(this.goSubmit);
                });
            },
            showZgTree() {
                this.$refs.tkiTree._show();
            },
            zgtreeConfirm(e) {
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_DEPARTMENT_ID', e[0].id)
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_DEPARTMENT_NAME', e[0].name)
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_INDEX', '')
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_ID', '')
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_NAME', '')
                this.getUserList(e[0].id);
            },
            timeLapseFiremanChange(e) {
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_INDEX', e.detail.value)
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_ID', this.timeLapseFiremanList[e.detail.value].USER_ID)
                this.$set(this.form, 'TIME_LAPSE_FIREMAN_NAME', this.timeLapseFiremanList[e.detail.value].NAME)
            },
            zgtreeCancel(e) {
                this.isUps = false;
            },
            getUserList(DEPARTMENT_ID) {
                //发送 post 请求
                var _this = this;
                uni.request({
                    method: 'POST',
                    dataType: 'json',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    url: basePath + '/app/sys/listUser',
                    data: {
                        DEPARTMENT_ID, NOMAIN: '1',
                        tm: new Date().getTime()
                    },
                    success: function (res) {
                        if ("success" == res.data.result) {
                            _this.timeLapseFiremanList = res.data.userList;
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                duration: 2000
                            });
                        }
                    }
                })
            },
            goToDelay(id) {
                uni.navigateTo({
                    url: '/pages/application/eight-assignments/hotwork/delay-fire-monitoring/delay?id=' + id + '&state=' + this.form.STATE
                });
            },
            goToGasDelay(id) {
                uni.navigateTo({
                    url: '/pages/application/eight-assignments/hotwork/gasAnalysis/delay?id=' + id
                });
            },
            goback() {
                uni.navigateBack({
                    delta: 1
                });
                uni.hideLoading();
            },
        }
    }
</script>

<style>
</style>
