<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.CHECK_NO}}
        </view>
        <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.NAME}}
        </view>
        <view class="cu-form-group">
          <view class="title">介质：</view>
          {{ form.MEDIUM }}
        </view>
        <view class="cu-form-group">
          <view class="title">温度：</view>
          {{ form.TEMPERATURE }}
        </view>
        <view class="cu-form-group">
          <view class="title">盲板材质：</view>
          {{ form.BOARD_MATERIAL }}
        </view>
        <view class="cu-form-group">
          <view class="title">盲板规格：</view>
          {{ form.BOARD_SPECIFICATION }}
        </view>
        <view class="cu-form-group">
          <view class="title">盲板编号：</view>
          {{ form.BOARD_NO }}
        </view>
        <view class="cu-form-group">
          <view class="title">实施时间装：</view>
          {{ form.BOARD_INSTALL_TIME }}
        </view>
        <view class="cu-form-group">
          <view class="title">实施时间拆：</view>
          {{ form.BOARD_DISASSEMBLE_TIME }}
        </view>
        <view class="cu-form-group">
          <view class="title">作业人装：</view>
          {{ form.BOARD_INSTALL_USER }}
        </view>
        <view class="cu-form-group">
          <view class="title">作业人拆：</view>
          {{ form.BOARD_DISASSEMBLE_USER }}
        </view>
        <view class="cu-form-group">
          <view class="title">监护人装：</view>
          {{ form.BOARD_INSTALL_CUSTODY_USER }}
        </view>
        <view class="cu-form-group">
          <view class="title">监护人拆：</view>
          {{ form.BOARD_DISASSEMBLE_CUSTODY_USER }}
        </view>
        <view class="cu-form-group">
          <view class="title">盲板位置图：</view>
          {{form.imgList.length}}/4
        </view>
        <view class="cu-form-group" style="padding-top:20upx">
          <view class="grid col-4 grid-square flex-sub">
            <view class="bg-img" v-for="(item,index) in form.imgList" :key="index" @tap="ViewImage" :data-url="form.imgList[index]">
              <image :src="form.imgList[index]" mode="aspectFill"></image>
            </view>
          </view>
        </view>
        <view class="cu-form-group">
          <view class="title">编制人签字：</view>
        </view>
        <view>
          <view>
            <image :src="baseImgPath + form.BOARD_SIGNER_PATH" style="width: 330upx;height: 260upx"></image>
          </view>
          <view style="text-align: center">{{form.BOARD_SIGNER_TIME}}</view>
        </view>
        <view class="cu-form-group" v-if="form.WORK_PLACE">
          <view class="title">作业地点：</view>
          <view>{{form.WORK_PLACE}}</view>
        </view>
        <view class="cu-form-group" v-if="form.LONGITUDE">
          <view class="title">作业地点经度：</view>
          <view>{{form.LONGITUDE}}</view>
        </view>
        <view class="cu-form-group" v-if="form.LATITUDE">
          <view class="title">作业地点纬度：</view>
          <view>{{form.LATITUDE}}</view>
        </view>
        <view class="cu-form-textarea">
          <view class="cu-form-title">安全措施及确认意见:</view>
          <textarea class="cu-input" disabled placeholder="请输入安全措施及确认意见" v-model="form.CONFIRM_OPINION"></textarea>
        </view>
        <view class="cu-form-group">
          <view class="title">作业单位负责人签字：</view>
        </view>
        <view>
          <view>
            <image :src="baseImgPath + form.CONFIRM_SIGNER_PATH" style="width: 330upx;height: 260upx"></image>
          </view>
          <view style="text-align: center">{{form.CONFIRM_SIGNER_TIME}}</view>
        </view>
        <view class="cu-form-textarea">
          <view class="cu-form-title">安全措施及确认意见:</view>
          <textarea class="cu-input" placeholder="请输入安全措施及确认意见" v-model="form.APPROVE_OPINION"></textarea>
        </view>
        <view class="cu-form-group">
          <view class="title">分公司（中心）审批人签字：</view>
          <button class="cu-btn bg-green shadow" @tap="modalShow = true" data-target="Modal">手写签字</button>
        </view>
        <view class="cu-bar bg-white" v-show="imgList && imgList.length > 0">
          <view class="action">
            签字照片
          </view>
        </view>
        <view class="cu-form-group" v-show="imgList && imgList.length > 0">
          <view class="grid col-4 grid-square flex-sub">
            <view style="width: 60%;" class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage1" data-type="0" :data-url="imgList[index].filePath">
              <image :src="imgList[index].filePath" mode="aspectFill"></image>
              <view class="cu-tag bg-red" @tap.stop="DelImg" data-type="0" :data-index="index">
                <text class='cuIcon-close'></text>
              </view>
            </view>
          </view>
        </view>
        <view class="cu-modal" :class="{'show':modalShow}">
          <sign @confirm="subCanvas" @cancel="modalShow = false"></sign>
        </view>
      </view>
    </view>
    <view class="cu-bar btn-group" style="margin-top: 30upx;">
      <button class="cu-btn bg-blue margin-tb-sm lg" @click="$noMultipleClicks(goSubmit,'-3')">不通过</button>
      <button class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goSubmit,'2')">通过</button>
    </view>
    <view class="padding flex flex-direction"></view>
  </view>
</template>

<script>
import {
  basePath,
  baseImgPath,
  loginSession,
  formatDate,
  loginUserId
} from '@/common/tool.js';
import sign from '@/components/sign/sign.vue';

export default {
  components: {
    sign
  },
  data() {
    return {
      baseImgPath,
      noClick: true,
      BLINDBOARD_ID: '',
      form: {
        APPLY_DEPARTMENT_ID: '',
        APPLY_DEPARTMENT_NAME: '',
        APPLY_USER_ID: '',
        APPLY_USER_NAME: '',
        CHECK_NO: '',
        APPLICATIO_DEPARTMENT_ID: '',
        NAME: '',
        MEDIUM: '',
        TEMPERATURE: '',
        BOARD_MATERIAL: '',
        BOARD_SPECIFICATION: '',
        BOARD_NO: '',
        BOARD_INSTALL_TIME: '',
        BOARD_DISASSEMBLE_TIME: '',
        BOARD_INSTALL_USER: '',
        BOARD_DISASSEMBLE_USER: '',
        BOARD_INSTALL_CUSTODY_USER: '',
        BOARD_DISASSEMBLE_CUSTODY_USER: '',
        imgList: [],
        LONGITUDE: '',
        LATITUDE: '',
        BOARD_SIGNER_PATH: '',
        BOARD_SIGNER_TIME: '',
        CONFIRM_OPINION: '',
        CONFIRM_SIGNER_PATH: '',
        CONFIRM_SIGNER_TIME: '',
        APPROVE_OPINION: '',
      },
      treeNode: [],
      todayDate: formatDate(new Date(), 'yyyy-MM-dd hh:mm'),
      modalShow: false,
      imgList: [],
    }
  },
  onLoad(event) {
    this.BLINDBOARD_ID = event.id
    this.getData();
    loginSession();
  },
  methods: {
    getData() {
      var _this = this;
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + '/app/blindboard/personChargeGoEdit',
        method: 'POST',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          BLINDBOARD_ID: _this.BLINDBOARD_ID,
        },
        success: (res) => {
          if ("success" === res.data.result) {
            this.form = res.data.varList;
            this.$set(this.form, 'imgList', []);
            for (let i = 0; i < res.data.imgList.length; i++) {
              this.form.imgList.push(baseImgPath + res.data.imgList[i].FILEPATH);
            }
            uni.hideLoading();
          } else if ("exception" === res.data.result) {
            uni.showToast({
              title: '错误',
              duration: 2000
            });
          }
        }
      });
    },
    goSubmit(type) {
      var _this = this;
      let required = true;
      if(type === '2'){
        if(!this.form.APPROVE_OPINION){
          uni.showToast({
            icon: 'none',
            title: '请输入安全措施及确认意见',
            duration: 1500
          })
          required = false;
        }
        if(this.imgList.length === 0){
          uni.showToast({
            icon: 'none',
            title: '请签字',
            duration: 1500
          })
          required = false
        }
        if (!required) {
          return
        }
      }
      uni.showLoading({
        title: '请稍候'
      })
      if(type === '2'){
        uni.uploadFile({
          url: basePath + '/app/blindboard/corpinfoapproveaddopinion',
          filePath: this.imgList[0].filePath,
          name: 'APPROVE_SIGNER_PATH',
          formData: {
            BLINDBOARD_ID: _this.BLINDBOARD_ID,
            ...this.form,
            APPROVE_SIGNER_TIME: formatDate(new Date(), 'yyyy-MM-dd hh:mm')
          },
          success: (res) => {
            uni.hideLoading();
            uni.showToast({
              title: '提交成功',
              duration: 1500
            });
            _this.goback()
          },
        });
      }else {
        uni.request({
          url: basePath + '/app/blindboard/repulse',
          method: 'POST',
          header: {
            'Content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            BLINDBOARD_ID: _this.BLINDBOARD_ID,
            APPLY_STATUS: type,
            loginUserId: loginUserId,
          },
          success: (res) => {
            uni.hideLoading();
            uni.showToast({
              title: '提交成功',
              duration: 1500
            });
            _this.goback()
          },
        });
      }
    },
    ViewImage(e) {
      uni.previewImage({
        urls: this.form.imgList,
        current: e.currentTarget.dataset.url
      });
    },
    subCanvas (e) {
      this.imgList.splice(0, this.imgList.length);
      this.imgList.push(e);
      this.modalShow = false;
    },
    ViewImage1 (e) {
      let files = [];
      for (var i = 0; i < this.imgList.length; i++) {
        files.push(this.imgList[i].filePath)
      }
      uni.previewImage({
        urls: files,
        current: e.currentTarget.dataset.url
      });
    },
    DelImg(e) {
      uni.showModal({
        title: '双控平台',
        content: '确定要删除这张图片吗？',
        cancelColor: "#000000",
        cancelText: '取消',
        confirmText: '确定',
        success: res => {
          if (res.confirm) {
            this.imgList.splice(e.currentTarget.dataset.index, 1)
          }
        }
      })
    },
    goback() {
      uni.navigateBack({
        delta: 1
      });
      uni.hideLoading();
    },
  }
}
</script>

<style>
.right_icon {
  position: relative;
  padding-right: 36upx;
  width: 200upx;
  text-align: right;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.right_icon ::after {
  font-family: cuIcon;
  display: block;
  content: "\e6a3";
  position: absolute;
  font-size: 17px;
  color: #8799a3;
  line-height: 50px;
  width: 30px;
  text-align: center;
  top: -28upx;
  bottom: 0;
  right: -22upx;
  margin: auto;
}

.modal_content {
  display: flex;
  text-align: left;
}

.modal_left {
  flex-basis: 50%;
  padding: 50upx 20upx;
  border-right: 1px solid #000000;
}

.modal_right {
  flex-basis: 50%;
  padding: 50upx;
}

.modal_left_title, .modal_right_title {
  font-size: 16px;
  color: #000000;
  font-weight: 700;
}

.checkbox-item {
  display: flex;
  align-items: center;
  padding: 0 30upx;
  min-height: 100upx;
  background-color: #ffffff;
  border-bottom: 1upx solid #ddd;
}

.checkbox-item:last-child {
  border-bottom: none;
}
</style>
