<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($store.state.filePath + form.projectPreliminarily_PRINCIPAL)"></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($store.state.filePath + item.FILEPATH,meetingImgList)"></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($store.state.filePath + item.FILEPATH,appendixImgList)"></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($store.state.filePath + form.inspectorGeneral_PRINCIPAL)"></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">
              <u-radio-group v-model="form.isChange" placement="row">
                <u-radio label="通过" name="2"></u-radio>
                <view class="ml-10">
                  <u-radio label="不通过" name="1"></u-radio>
                </view>
              </u-radio-group>
            </view>
          </u-cell>
          <u-cell v-if="form.isChange == 2">
            <view slot="title" class="title">（港股）安委会办公室：</view>
            <view slot="value">
              <u--text :text="pd.committee_dept_id ==''?'请选择':pd.committee_dept_name" @click="showTree"></u--text>
              <tki-tree ref="tkitree" :range="deptRange" rangeKey="name" selectParent confirmColor="#4e8af7"
                        @confirm="confirmTree"/>
            </view>
          </u-cell>
          <u-cell v-if="form.isChange == 2">
            <view slot="title" class="title">（港股）安委会办公室人员：</view>
            <view slot="value">
              <u--text :text="pd.committee_user_name ==''?'请选择':pd.committee_user_name"
                       @click="showPicker"></u--text>
              <u-picker :show="show" :columns="columns"
                        keyName="NAME" @cancel="show = false" @confirm="confirmPicker"></u-picker>
            </view>
          </u-cell>
          <u-cell v-if="form.isChange == 1">
            <view slot="title" class="title">是否中止动火：</view>
            <view slot="value">
              <u-radio-group v-model="form.isEnd" placement="row">
                <u-radio label="否" name="0"></u-radio>
                <view class="ml-10">
                  <u-radio label="是" name="1"></u-radio>
                </view>
              </u-radio-group>
            </view>
          </u-cell>
          <u-cell v-if="form.isChange == '1' && form.isEnd === '0'">
            <view slot="title" class="title">提示：</view>
            <view slot="value">打回到项目主管部门负责人审核</view>
          </u-cell>
          <u-cell v-if="form.isEnd == 1 && form.isChange == 1" class="flex-none">
            <view slot="title" class="title">原因：</view>
            <view slot="label" class="mt-10">
              <u--textarea v-model="form.value1" placeholder="请输入不合格原因"></u--textarea>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </view>
    <view class="mt-10">
      <u-button type="primary" text="提交" @click="$u.debounce(submit, 1000,true)"></u-button>
    </view>
  </view>
</template>

<script>
import tkiTree from "@/components/tki-tree/tki-tree.vue"
import {
  getHotWorkGoEdit,
  getImgfilesListByKeyAndType,
  getDept,
  getDeptUser,
  approveHotWorkSupervision
} from '../../../api/index'

export default {
  components: {tkiTree},
  data() {
    return {
      form: {
        'isChange': '1',
        'isEnd': '0',
        value1: ''
      },
      pd: {
        HOTWORKAPPLICATION_ID: '',
        committee_dept_id: '',
        committee_dept_name: '',
        committee_user_id: '',
        committee_user_name: '',
        TYPE: '',
        isEnd: '',
        STATE: '35'
      },
      deptRange: [],
      deptUserRange: [],
      show: false,
      columns: [],
      HOTWORKAPPLICATION_ID: '',
      meetingImgList: [],
      appendixImgList: []
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },

  onLoad(event) {
    this.HOTWORKAPPLICATION_ID = event.HOTWORKAPPLICATION_ID
    this.pd.HOTWORKAPPLICATION_ID = event.HOTWORKAPPLICATION_ID
    this.getDate()
    this.getImgFilesList('203', 'meetingImgList')
    this.getImgFilesList('204', 'appendixImgList')
    this.getDept()
  },

  methods: {
    async getDate() {
      let resData = await getHotWorkGoEdit({...this.pd});
      this.form = resData.pd
    },
    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});
      console.info(resData.userList)
      // this.deptUserRange = JSON.stringify(resData.userList)
      this.$set(this.columns, 0, resData.userList)
    },
    fnNavigator() {
      uni.$u.route({
        url: '/pages/super-hot/hot-work-permit/index',
        params: {
          HOTWORKAPPLICATION_ID: this.HOTWORKAPPLICATION_ID
        }
      })
    },
    showTree() {
      this.$refs.tkitree._show()
    },
    confirmTree(e) {
      this.pd.committee_dept_id = e[0].id
      this.pd.committee_dept_name = e[0].name
      this.pd.committee_user_id = ''
      this.pd.committee_user_name = ''
      this.getDeptUser(this.pd.committee_dept_id)
    },
    showPicker() {
      this.show = true
    },
    confirmPicker(e) {
      this.pd.committee_user_id = e.value[0].USER_ID
      this.pd.committee_user_name = e.value[0].NAME
      this.show = false;
    },
    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
        });
      }

    },
    async submit() {
      await approveHotWorkSupervision({
        'TYPE': this.form.isChange,
        'HOTWORKAPPLICATION_ID': this.HOTWORKAPPLICATION_ID,
        'STATE': '35',
        'committee_USER_ID': this.pd.committee_user_id,
        'isEnd': this.form.isEnd,
        'OPINION': this.form.value1,
        'loginUserId': this.userInfo.USER_ID
      });
      uni.$u.route({
        type: 'navigateBack'
      })
    }
  },
}
</script>

<style scoped>

</style>
