<template>
    <view >
        <cu-custom bgColor="bg-gradual-blueness" :isBack="true" >
            <block slot="backText">返回</block>
            <block slot="content">安全承诺</block>
        </cu-custom>

        <scroll-view scroll-y="false" >
            <view>
                <view class="wui-sub-title">
                    <text>企业状态</text>
                </view>
                <view class="wui-form-list" style="margin-top: 0;">
                    <view class="de-title">
						<text class="cuIcon-title text-blue"></text>
                        <text>高危生产活动及作业的安全风险可控状态</text>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">特殊作业：</view>
                        <input type="number" name="input" ref="INPUT1" v-model="pd.INPUT1" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">风险辨识、作业许可及管控措施的落实情况</view>
                        <radio-group  class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO1','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO1','1')">
								<text class="wui-pl10">是</text></radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">动火作业：</view>
                        <input type="number" name="input" ref="INPUT2" v-model="pd.INPUT2" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">其中特级：</view>
                        <input type="number" name="input" ref="INPUT3" v-model="pd.INPUT3" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">一级：</view>
                        <input type="number" name="input" ref="INPUT4" v-model="pd.INPUT4" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">二级：</view>
                        <input type="number" name="input" ref="INPUT5" v-model="pd.INPUT5" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">高处作业：</view>
                        <input type="number" name="input" ref="INPUT6" v-model="pd.INPUT6" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">受限空间作业：</view>
                        <input type="number" name="input" ref="INPUT7" v-model="pd.INPUT7" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">吊装作业：</view>
                        <input type="number" name="input" ref="INPUT8" v-model="pd.INPUT8" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">临时用电作业：</view>
                        <input type="number" name="input" ref="INPUT9" v-model="pd.INPUT9" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">盲板抽堵作业：</view>
                        <input type="number" name="input" ref="INPUT10" v-model="pd.INPUT10" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">动土作业：</view>
                        <input type="number" name="input" ref="INPUT11" v-model="pd.INPUT11" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">断路作业：</view>
                        <input type="number" name="input" ref="INPUT12" v-model="pd.INPUT12" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">检维修作业：</view>
                        <input type="number" name="input" ref="INPUT13" v-model="pd.INPUT13" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">处于试生产情况</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO2','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO2','1')">
								<text class="wui-pl10">是</text></radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">处于开停车情况</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO3','-1')">
								<text class="wui-pl10">停</text></radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO3','1')">
								<text class="wui-pl10">开</text></radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">承包商作业：</view>
                        <input type="number" name="input" ref="INPUT14" v-model="pd.INPUT14" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">管控情况</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO4','-1')">
								<text class="wui-pl10">非受控</text></radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO4','1')">
								<text class="wui-pl10">受控</text></radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">变更情况</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO5','-1')">
								<text class="wui-pl10">没有</text></radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO5','1')">
								<text class="wui-pl10">有</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">落实审批程序情况</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO6','-1')">
								<text class="wui-pl10">否</text></radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO6','1')">
								<text class="wui-pl10">是</text></radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">罐区、仓库等危险源是否处于安全状态</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO7','-1')">
							<text class="wui-pl10">否</text></radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO7','1')">
								<text class="wui-pl10">是</text></radio>
                        </radio-group>
                    </view>
                </view>

                <view class="wui-form-list">
                    <view class="de-title">
						<text class="cuIcon-title text-blue"></text>
                        <text>车间安全状态</text>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">车间岗位：</view>
                        <input type="number" name="input" ref="INPUT15" v-model="pd.INPUT15" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">其中运行：</view>
                        <input type="number" name="input" ref="INPUT16" v-model="pd.INPUT16" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">停产：</view>
                        <input type="number" name="input" ref="INPUT17" v-model="pd.INPUT17" placeholder="请输入..."></input>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">检修：</view>
                        <input type="number" name="input" ref="INPUT18" v-model="pd.INPUT18" placeholder="请输入..."></input>
                    </view>
                </view>

                <view class="wui-form-list">
                    <view class="de-title">
						<text class="cuIcon-title text-blue"></text>
                        <text class="text-semi">生产装置的安全运行状态</text>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;line-height: 1.4;">生产装置的温度、压力、组分液位、流量等主要工艺参数是否处于指标范围</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO8','-1')">
								<text class="wui-pl10">否</text>
								</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO8','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group"style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">压力容器、压力管道等特种设备处于安全运行状态</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO9','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO9','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" >
                        <view class="title">设备设施的静动密封完好无泄漏</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO10','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO10','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;line-height: 1.4;">超限报警、紧急切断、联锁等各类安全设施配备完好投用，并可靠运行</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO11','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO11','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                </view>

                <view class="wui-form-list">
                    <view class="de-title">
						<text class="cuIcon-title text-blue"></text>
                        <text class="text-semi">危险化学品罐区、仓库等重大危险源安全运行状态</text>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">储罐、管道、机泵、阀门及仪表系统完好无泄漏</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO12','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO12','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">储罐的液位、温度、压力、气柜钟罩无超限运行</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO13','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO13','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">手动放脱水、装卸车时确保人员在岗</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO14','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO14','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-group" style="height: 160upx;">
                        <view class="title" style="height: auto;padding-right: 0; width: 380upx;">可燃及有毒气体报警和联锁处于可靠运行状态</view>
                        <radio-group class="wui-radio-group">
                            <radio class='radio'  value="-1" @click="changeRadio('RADIO15','-1')">
								<text class="wui-pl10">否</text>
							</radio>
                            <radio class='radio' value="1" @click="changeRadio('RADIO15','1')">
								<text class="wui-pl10">是</text>
							</radio>
                        </radio-group>
                    </view>
                    <view class="cu-form-textarea" style="border-top: 1px solid #eee;">
                        <view class="cu-form-title">仓库是否按照国家标准分区分类储存危险化学品，是否超量、超品种储存，相互禁配物质是否混放混存。</view>
                        <textarea maxlength="255" v-model="pd.INPUT19" placeholder="请输入..."></textarea>
                    </view>
                </view>

                <view class="wui-sub-title">
                    <text>企业承诺</text>
                </view>
                <view class="wui-form-list" style="margin-top: 0;">
                    <view class="cu-form-group ">
                        <view class="title">今日</view>
                        <ruiDatePicker
                                       fields="minute"
                                       :start="todayDate"
                                       :value="pd.START_TIME?pd.START_TIME:''"
                                       @change="changeStartDate"
                        ></ruiDatePicker>
                    </view>
                    <view class="cu-form-group">
                        <view class="title">至</view>
                        <ruiDatePicker
                                       fields="minute"
                                       :value="pd.END_TIME?pd.END_TIME:''"
                                       @change="changeEndDate"
                        ></ruiDatePicker>
                    </view>
					<view class="sure-p p20"  style="border-bottom: 1px solid #eee;border-top: 1px solid #eee;">
                    我车间已进行安全风险研判，各项安全风险防控措施已落实到位。我承诺本生产装置/业务活动处于安全运行状态，涉及罐区、仓库等危险源安全风险得到有效管控。
                    </view>
					<view class="wui-sign">
                        <view class="title">承诺人</view>
                        <button class="cu-btn bg-green shadow" @tap="showModal" data-target="Modal">手写签字</button>
                    </view>

                    <view class="wui-sign-box"  v-show="imgList && imgList.length > 0">
						<view class="sign-title">
						      签字照片：
						    </view>
                        <view class="wui-sign-cotent">
                            <view class="sign-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"  data-type="0" :data-url="imgList[index].filePath">
                                <image :src="imgList[index].filePath" mode="aspectFit"></image>
                            </view>
                        </view>
                    </view>
                    <view class="cu-modal" :class="modalName=='Modal'?'show':''">
                        <writing-board  @confirm="subCanvas" @cancel="hideModal"></writing-board>
                    </view>
                </view>
            </view>
            <view class="cu-bar btn-group" style="margin-top: 30upx;">
                <button :loading="buttonloading" class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goSubmit)">提 交</button>
            </view>
            <view class="padding flex flex-direction">
            </view>
        </scroll-view>
    </view>
</template>

<script>
    import {
        basePath,corpinfoId,deptId,loginUser,formatDate,loginSession,baseImgPath
    } from '@/common/tool.js';
    import tkiTree from "@/components/select-tree/select-tree.vue"
    import writingBoard from "@/components/writing-board/writing-board.vue"
    import gcoord from '@/common/gcoord.js'
    import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue';
    import {decryptAes} from "../../../common/aesUtil";
    export default {
        components: {
            tkiTree, ruiDatePicker, writingBoard
        },
        data() {
            return {
                baseImgPath: baseImgPath,
                buttonloading: false,
                isUps: false,
                forbidEdit: true,// 禁止修改
                msg: 'add',
                noClick: true,
                pd: {},// 数据
                measuresList: [],
                gasList: [],
                rules: [
                    {name: 'INPUT1', message: '请输入特殊作业数'},
                    {name: 'INPUT2', message: '请输入动火作业数'},
                    {name: 'INPUT3', message: '请输入特级动火作业数'},
                    {name: 'INPUT4', message: '请输入一级动火作业数'},
                    {name: 'INPUT5', message: '请输入二级动火作业数'},
                    {name: 'INPUT6', message: '请输入高处作业数'},
                    {name: 'INPUT7', message: '请输入受限空间作业数'},
                    {name: 'INPUT8', message: '请输入吊装作业数'},
                    {name: 'INPUT9', message: '请输入临时用电作业数'},
                    {name: 'INPUT10', message: '请输入盲板抽堵作业数'},
                    {name: 'INPUT11', message: '请输入动土作业数'},
                    {name: 'INPUT12', message: '请输入断路作业数'},
                    {name: 'INPUT13', message: '请输入检维修作业数'},
                    {name: 'INPUT14', message: '请输入承包商作业数'},
                    {name: 'INPUT15', message: '请输入车间岗位数'},
                    {name: 'INPUT16', message: '请输入车间岗位运行数'},
                    {name: 'INPUT17', message: '请输入车间岗位停产数'},
                    {name: 'INPUT18', message: '请输入车间岗位检修数'},
                    {name: 'INPUT19', message: '请输入仓库是否按照国家标准分区分类储存危险化学品，是否超量、超品种储存，相互禁配物质是否混放混存'},
                    {name: 'RADIO1', message: '请选择风险辨识、作业许可及管控措施的落实情况'},
                    {name: 'RADIO2', message: '请选择处于试生产情况'},
                    {name: 'RADIO3', message: '请选择处于开停车情况'},
                    {name: 'RADIO4', message: '请选择管控情况'},
                    {name: 'RADIO5', message: '请选择变更情况'},
                    {name: 'RADIO6', message: '请选择落实审批程序情况'},
                    {name: 'RADIO7', message: '请选择罐区、仓库等危险源是否处于安全状态'},
                    {name: 'RADIO8', message: '请选择生产装置的温度、压力、组分液位、流量等主要工艺参数是否处于指标范围'},
                    {name: 'RADIO9', message: '请选择压力容器、压力管道等特种设备处于安全运行状态'},
                    {name: 'RADIO10', message: '请选择设备设施的静动密封完好无泄漏'},
                    {name: 'RADIO11', message: '请选择超限报警、紧急切断、联锁等各类安全设施配备完好投用，并可靠运行'},
                    {name: 'RADIO12', message: '请选择储罐、管道、机泵、阀门及仪表系统完好无泄漏'},
                    {name: 'RADIO13', message: '请选择储罐的液位、温度、压力、气柜钟罩无超限运行'},
                    {name: 'RADIO14', message: '请选择手动放脱水、装卸车时确保人员在岗'},
                    {name: 'RADIO15', message: '请选择可燃及有毒气体报警和联锁处于可靠运行状态'},
                    {name: 'START_TIME', message: '请选择承诺时间'},
                    {name: 'END_TIME', message: '请选择承诺时间'},
                ],
                todayDate: '',
                modalName: null,
                imgList: [],
            }
        },
        onLoad(event){
            loginSession();
            this.todayDate =  formatDate(new Date(), 'yyyy-MM-dd hh:mm');
        },
        methods: {
            goSubmit(){
                let startTime = this.pd.START_TIME
                let endTime = this.pd.END_TIME
                let timeStamp = 86400000 * 30
                if(new Date(endTime).getTime() - new Date(startTime).getTime() > timeStamp){
                  uni.showToast({
                    title:'只能选择30天内的日期',
                    icon:'none'
                  })
                  return;
                }
                var _this = this;
                let required = true
                uni.showLoading({
                    title: '请稍候'
                })
                if (_this.imgList.length <= 0) {
                    uni.showToast({
                        icon: 'none',
                        title: '请签字',
                        duration: 1500
                    });
                    return;
                }
                this.rules.map(({name,message})  => {
                    if (!this.pd[name]) {
                        uni.showToast({
                            icon: 'none',
                            title: message,
                            duration: 1500
                        });
                        required = false
                    }
                })
                if (!required) {
                    return
                }
                const formData={}
                Object.keys(this.pd).map(key => {
                    formData[key]=this.pd[key]
                })
                formData.DEPARTMENT_ID=deptId
                formData.SIGN_USER=loginUser.USER_ID
                formData.CORPINFO_ID = loginUser.CORPINFO_ID
                formData.USER_ID = loginUser.USER_ID
                this.buttonloading = true
                uni.uploadFile({
                    url: basePath+'app/commitmentworkshop/add',
                    filePath: _this.imgList[0].filePath,
                    name: 'FFILE',
                    formData:formData,
                    success: (res) => {
                      res.data = decryptAes(res.data);
                        uni.showToast({
                            icon:'none',
                            title: '保存成功',
                            duration: 2000
                        });
                        _this.goback()
                        this.buttonloading = false
                    },
                    fail: (err) => {
                        uni.hideLoading();
                        uni.showModal({
                            content: err.errMsg,
                            showCancel: false
                        });
                    }
                })
            },
            changeRadio(name,value){
                this.pd[name]=value
            },
            changeStartDate(e) {
                this.pd.START_TIME = e
                this.$forceUpdate();//强制刷新
            },
            changeEndDate(e) {
                this.pd.END_TIME = e
                this.$forceUpdate();//强制刷新
            },
            /*
			 *手写板
			 */
            showModal(e) {
                this.modalName = e.currentTarget.dataset.target
            },
            hideModal(e) {
                this.modalName = null
            },
            //完成
            subCanvas(e) {
                this.imgList.splice(0,this.imgList.length);
                this.imgList.push(e);
                this.pd.SIGNER_TIME = formatDate(new Date(), 'yyyy-MM-dd hh:mm');
                this.hideModal()
            },
            ViewImage(e) {
                let files =[];
                files.push(e.currentTarget.dataset.url)
                uni.previewImage({
                    urls: files,
                    current: e.currentTarget.dataset.url
                });
            },
            goback(){
                var pages = getCurrentPages();	// 获取当前页面栈
                var prePage = pages[pages.length - 2];	// 上二级页面
                prePage.$vm.initflag = true;    // A 页面 init方法 为true
                uni.navigateBack({delta: 1});
                uni.hideLoading();
            },
        }
    }
</script>

<style scoped>
.radio+.radio{
	margin-left: 5px;
	}
</style>
