<template>
  <view class="content p-10">
    <view class="card">
      <view class="view-title">
        <u--text text="特级动火申请" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">申请人：</view>
            <view slot="value">{{ form.APPLY_USER_NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">申请时间：</view>
            <view slot="value">{{ form.APPLICATION_DATE }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">作业证编号：</view>
            <view slot="value">{{ form.JOB_NUMBER }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">作业类型：</view>
            <view slot="value">{{ form.JOB_TYPE_NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">动火许可证：</view>
            <view slot="value">
              <u-button type="primary" text="查看" size="mini" @click="fnNavigator"></u-button>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="动火单位作业负责人确认" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">动火单位作业负责人：</view>
            <view slot="value">{{ form.projectCompetent_USER_NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">确认时间：</view>
            <view slot="value">{{ form.projectCompetent_OPERATTIME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">是否确认通过：</view>
            <view slot="value">{{ form.projectCompetent_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="项目主管人员初审" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">项目主管人员：</view>
            <view slot="value">{{ form.projectPreliminarily_USER_NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">初审时间：</view>
            <view slot="value">{{ form.projectPreliminarily_OPERATTIME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">初审结果：</view>
            <view slot="value">{{ form.projectPreliminarily_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="项目主管部门负责人审批" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">初审结果：</view>
            <view slot="value">{{ form.projectPreliminarily_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签字：</view>
            <view slot="label" class="mt-10">
              <u--image :showLoading="true" :src="$store.state.filePath + form.projectPreliminarily_PRINCIPAL"
                        width="70" height="70" mode="scaleToFill" @click="previewImage"></u--image>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签字时间：</view>
            <view slot="value">{{ form.projectPreliminarily_OPERATTIME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">上传会签文件：</view>
            <view slot="label" class="mt-10">
              <view style="display: flex;flex-wrap: wrap">
                <view v-for="(item,index) in meetingImgList" :key="index" class="ml-10 mt-10">
                  <u--image :showLoading="true" :src="$store.state.filePath + item.FILEPATH" width="70" height="70"
                            mode="scaleToFill" @click="previewImage"></u--image>
                </view>
              </view>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">上传附件：</view>
            <view slot="label" class="mt-10">
              <view style="display: flex;flex-wrap: wrap">
                <view v-for="(item,index) in appendixImgList" :key="index" class="ml-10 mt-10">
                  <u--image :showLoading="true" :src="$store.state.filePath + item.FILEPATH" width="70" height="70"
                            mode="scaleToFill" @click="previewImage"></u--image>
                </view>
              </view>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="分公司安全总监审批" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">审批结果：</view>
            <view slot="value">{{ form.inspectorGeneral_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签字：</view>
            <view slot="label" class="mt-10">
              <u--image :showLoading="true" :src="$store.state.filePath + form.inspectorGeneral_PRINCIPAL" width="70"
                        height="70" mode="scaleToFill" @click="previewImage"></u--image>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签字时间：</view>
            <view slot="value">{{ form.inspectorGeneral_OPERATTIME }}</view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="分公司主要负责人签批" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">签批结果：</view>
            <view slot="value">{{ form.supervision_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签字：</view>
            <view slot="label" class="mt-10">
              <u--image :showLoading="true" :src="$store.state.filePath + form.supervision_PRINCIPAL" width="70"
                        height="70" mode="scaleToFill"
                        @click="previewImage($store.state.filePath + form.supervision_PRINCIPAL)"></u--image>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签字时间：</view>
            <view slot="value">{{ form.supervision_OPERATTIME }}</view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="（港股）安全监督部初审" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">初审结果：</view>
            <view slot="value">{{ form.committee_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">初审人员：</view>
            <view slot="value">{{ form.committee_USER_NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">初审时间：</view>
            <view slot="value">{{ form.committee_OPERATTIME }}</view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="（港股）安委会办公室审批" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">审核结果：</view>
            <view slot="value">{{ form.safetyDirector_TYPE == '2' ? '通过' : '不通过' }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">上传会议纪要：</view>
            <view slot="label" class="mt-10">
              <view style="display: flex;flex-wrap: wrap">
                <view v-for="(item,index) in fileList" :key="index" class="ml-10 mt-10">
                  <u--image :showLoading="true" :src="$store.state.filePath + item.FILEPATH" width="70" height="70"
                            mode="scaleToFill"
                            @click="previewImage($store.state.filePath + item.FILEPATH,fileList)"></u--image>
                </view>
              </view>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">上传附件：</view>
            <view slot="label" class="mt-10">
              <view style="display: flex;flex-wrap: wrap">
                <view v-for="(item,index) in fileList1" :key="index" class="ml-10 mt-10">
                  <u--image :showLoading="true" :src="$store.state.filePath + item.FILEPATH" width="70" height="70"
                            mode="scaleToFill"
                            @click="previewImage($store.state.filePath + item.FILEPATH,fileList1)"></u--image>
                </view>
              </view>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">（港股）安委会办公室审批：</view>
            <view slot="value">{{ form.safetyDirector_USER_NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">时间：</view>
            <view slot="value">{{ form.safetyDirector_OPERATTIME }}</view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="card" v-if="type==2">
      <view class="view-title">
        <u--text text="（港股安委办主任）安全总监签发" bold></u--text>
      </view>
      <view class="mt-10">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">签批结果：</view>
            <view slot="value">
              <u-radio-group v-model="form.TYPE" placement="row">
                <u-radio label="同意" name="2"></u-radio>
                <!-- <u-radio label="不同意" name="1" class="ml-10"></u-radio> -->
              </u-radio-group>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签批人：</view>
            <view slot="value">{{ userInfo.NAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">签批时间：</view>
            <view slot="value">{{ $u.timeFormat(new Date(), 'yyyy年mm月dd日 hh时MM分ss秒') }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title" @click="signShow = true">签字：</view>
            <view slot="value">
              <u-button type="primary" text="手写添加" size="mini" class="bth-mini" @click="signShow = true"></u-button>
              <sign v-if="signShow" :signShow.sync="signShow" @confirm="signConfirm"></sign>
            </view>
          </u-cell>
          <u-cell v-if="form.safetyDirectorSign">
            <view slot="title" class="title"></view>
            <view slot="label">
              <u--image v-show="form.safetyDirectorSign" :showLoading="true" :src="form.safetyDirectorSign"
                        width="200px" height="80px" mode="scaleToFill"
                        @click="previewImage(form.safetyDirectorSign)"></u--image>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="mt-10" v-if="type==2">
      <u-button type="primary" text="提交"
                @click="$u.debounce(submit, 1000,true)"></u-button>
    </view>
  </view>
</template>

<script>
import {
  approveHotWorkSupervisionAndFfile, fileUpload,
  getDept,
  getDeptUser,
  getHotWorkGoEdit,
  getImgfilesListByKeyAndType
} from "@/api";
import sign from "../../../components/sign/sign";

export default {
  components: {
    sign,
  },
  data() {
    return {
      signShow: false,
      form: {TYPE: '2'},
      HOTWORKAPPLICATION_ID: '',
      meetingImgList: [],
      appendixImgList: [],
      fileList: [],
      fileList1: [],
      type: 1

    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onLoad(event) {
    this.type = event.type
    this.HOTWORKAPPLICATION_ID = event.HOTWORKAPPLICATION_ID
    this.getDate()
    this.getImgFilesList('203', 'meetingImgList')
    this.getImgFilesList('204', 'appendixImgList')
    this.getImgFilesList('205', 'fileList')
    this.getImgFilesList('206', 'fileList1')
    this.getDept()
  },

  methods: {
    async getDate() {
      let resData = await getHotWorkGoEdit({HOTWORKAPPLICATION_ID: this.HOTWORKAPPLICATION_ID});
      this.form = resData.pd
      this.form.TYPE = '2'
    },
    async getImgFilesList(type, listName) {
      let imgPd = {'FOREIGN_KEY': this.HOTWORKAPPLICATION_ID, 'TYPE': type}
      let resData = await getImgfilesListByKeyAndType({...imgPd});
      this[listName] = resData.imgs
    },
    async getDept() {
      let resData = await getDept({'DEPARTMENT_ID': '0'});
      this.deptRange = JSON.parse(resData.zTreeNodes)
    },
    async getDeptUser(detpId) {
      let resData = await getDeptUser({'DEPARTMENT_ID': detpId});
      this.deptUserRange = JSON.parse(resData.userList)
      this.$set(this.columns, 0, JSON.parse(resData.userList))
    },
    fnNavigator() {
      uni.$u.route({
        url: '/pages/super-hot/hot-work-permit/index',
        params: {
          HOTWORKAPPLICATION_ID: this.HOTWORKAPPLICATION_ID
        }
      })
    },
    previewImage(current, imgList) {
      if (imgList) {
        let urls = []
        for (let i = 0; i < imgList.length; i++) {
          urls.push(this.$store.state.filePath + imgList[i].FILEPATH)
        }
        uni.previewImage({
          urls,
          current
        });
      } else {
        uni.previewImage({
          urls: [current],
          current
        });
      }
    },
    signConfirm({path}) {
      this.form.safetyDirectorSign = path
    },
    async submit() {
      if (this.form.TYPE === '2') {
        if (!this.form.safetyDirectorSign) {
          uni.showToast({
            icon: "none",
            title: '请在确认人签字处签字',
            duration: 1500
          });
          return false
        }
      }
      let res = await fileUpload({
        filePath: this.form.safetyDirectorSign,
        name: "file",
        formData: {
          foreignKey: this.userInfo.USER_ID,
          corpInfoId: this.userInfo.CORPINFO_ID,
          type: 130,
        },
        loading: false
      })
      await approveHotWorkSupervisionAndFfile({
        'TYPE': this.form.TYPE,
        'HOTWORKAPPLICATION_ID': this.HOTWORKAPPLICATION_ID,
        'STATE': '37',
        'loginUserId': this.userInfo.USER_ID,
        'CORPINFO_ID': this.userInfo.CORPINFO_ID,
        'AUTOGRAPH': res.data.filePath
      })
      uni.$u.route({
        type: 'navigateBack'
      })
    }
  },
}
</script>

<style scoped>

</style>
