<template>
  <view>
    <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">隐患记录-详情</block>
    </cu-custom>
    <hiddenView :hidden_id="this.id"/>
  </view>
</template>

<script>
import {
  basePath,
  baseImgPath,
  corpinfoId,
  loginUser
} from '@/common/tool.js';
import hiddenView from '@/components/hidden_view/index.vue';

export default {
  components: {
    hiddenView,
  },
  data() {
    return {
      noClick: true,
      date: '',
      RECTIFICATIONTIME: '',
      imgList: [],
      id: '',
      pd: [],
      hs: [],
      files: [],
      files2: [],
      files3: [],
      files4: [],
      files5: [],
      files6: [],
      videoList: [],
      checkList: [],
      confirmDataList: [],
      correctionDataList: [],
      correctionRepulseDataList: [],
      delayedReviewDataList: [],
      acceptRepulseDataList: [],
      CHECKDESCR: '',
      basePath: basePath,
      baseImgPath: baseImgPath,
      ISQUALIFIED: '1',
      modalShow: false,
      videoSrc: '',
    }
  },
  onLoad(e) {
    this.id = e.id;
    // let now = new Date();
    // this.date = formatDate(now, 'yyyy-MM-dd');
    this.getData();
  },
  // filters: {
  // 	formatDate(time) {
  // 		time = time * 1
  // 		let date = new Date(time)
  // 		return formatDate(date, 'yyyy-MM-dd hh:mm')
  // 	}
  // },
  methods: {
    fullScreenHandler(e) {
      if (uni.getSystemInfoSync().platform == "ios") {
        return
      }
    },
    getData() {
      var _this = this;
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + '/app/hidden/goEdit',
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          HIDDEN_ID: _this.id,
          CORPINFO_ID: loginUser.CORPINFO_ID,
          USER_ID: loginUser.USER_ID,
        },
        success: (res) => {
          if ("success" == res.data.result) {
            uni.hideLoading();
            _this.pd = res.data.pd; //参数map
            _this.hs = res.data.hs; //参数map
            for (let i = 0; i < res.data.hImgs.length; i++) {
              if (res.data.hImgs[i].FILEPATH.substring(res.data.hImgs[i].FILEPATH.lastIndexOf(".") + 1, res.data.hImgs[i].FILEPATH.length) === 'mp4') {
                _this.videoList.push(res.data.hImgs[i])
              } else {
                _this.files.push(res.data.hImgs[i])
              }
            }
            // _this.files = res.data.hImgs;
            _this.files2 = res.data.rImgs;
            //_this.files3 = res.data.cImgs;
            _this.files4 = res.data.sImgs;
            _this.files5 = res.data.pImgs;
            _this.files6 = res.data.yImgs;
            _this.checkList = res.data.checkList;
            _this.confirmDataList = res.data.confirmDataList;
            _this.correctionDataList = res.data.correctionDataList;
            _this.correctionRepulseDataList = res.data.correctionRepulseDataList;
            _this.delayedReviewDataList = res.data.delayedReviewDataList;
            _this.acceptRepulseDataList = res.data.acceptRepulseDataList;


          } else if ("exception" == data.result) {
            uni.showToast({
              title: '错误',
              duration: 2000
            });
          }
        }
      });
    },
    //图片上传
    ChooseImage() {
      var _this = this;
      uni.chooseImage({
        count: 4, //默认9
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['camera', 'album'], //从相册选择
        success: (res) => {
          if (this.imgList.length != 0) {
            this.imgList = this.imgList.concat(res.tempFilePaths)
          } else {
            this.imgList = res.tempFilePaths
          }
        }
      });
    },
    ViewImage(e) {
      uni.previewImage({
        urls: this.imgList,
        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)
          }
        }
      })
    },
    textareaAInput(e) {
      this.CHECKDESCR = e.detail.value
    },
    goSubmit() {
      var _this = this;
      if (!_this.CHECKDESCR) {
        uni.showToast({
          icon: 'none',
          title: '请填验收描述',
          duration: 1500
        });
        return;
      }
      if (_this.imgList.length <= 0) {
        uni.showToast({
          icon: 'none',
          title: '请上传验收照片',
          duration: 1500
        });
        return;
      }


      var i = 0;
      _this.uploadImg(_this.imgList, i);
    },

    uploadImg(tempFilePaths, i) {
      var _this = this;
      uni.showLoading({
        title: '上传中'
      })
      uni.uploadFile({
        url: basePath + '/app/imgfiles/add',
        filePath: tempFilePaths[i],
        name: 'FFILE',

        formData: {
          'FOREIGN_KEY': _this.id,
          'TYPE': '5',
          CORPINFO_ID: loginUser.CORPINFO_ID,
          USER_ID: loginUser.USER_ID,
        },
        success: (res) => {
          i++;
          if (tempFilePaths.length > i) {
            _this.uploadImg(tempFilePaths, i);
          } else {
            _this.submit();
          }
        },
        fail: (err) => {
          uni.hideLoading();
          console.log('uploadImage fail', err);
          uni.showModal({
            content: err.errMsg,
            showCancel: false
          });
        }
      })
    },
    submit() {
      var _this = this;
      uni.request({
        url: basePath + "/app/hidden/check", //提交接口
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          ISQUALIFIED: _this.ISQUALIFIED,
          CHECKDESCR: _this.CHECKDESCR,
          HIDDEN_ID: _this.id,
          CORPINFO_ID: loginUser.CORPINFO_ID,
          USER_ID: loginUser.USER_ID,
        },
        success: (res) => {

          uni.hideLoading();
          if ("success" == res.data.result) {
            uni.showToast({
              icon: 'none',
              title: '提交成功',
              duration: 1500
            });
            setTimeout(function () {
              var pages = getCurrentPages(); // 获取当前页面栈
              var prePage = pages[pages.length - 2]; // 上一个页面
              prePage.$vm.initflag = true; // A 页面 init方法 为true
              uni.navigateBack({});
              uni.hideLoading();
            }, 1500);
          } else {
            uni.showToast({
              title: '错误',
              duration: 2000
            });
          }

        }
      });
    },
    changeDate(e) {
      this.RECTIFICATIONTIME = e.detail.value
    },
    radio(e) {
      this.ISQUALIFIED = e
    },
    ViewShowImage(e) {
      let files = [];
      for (var i = 0; i < this.files.length; i++) {
        files.push(baseImgPath + this.files[i].FILEPATH)
      }
      uni.previewImage({
        urls: files,
        current: e.currentTarget.dataset.index
      });
    },
    ViewShowImage2(e) {
      let files = [];
      for (var i = 0; i < this.files2.length; i++) {
        files.push(baseImgPath + this.files2[i].FILEPATH)
      }
      uni.previewImage({
        urls: files,
        current: e.currentTarget.dataset.index
      });
    },
    ViewShowImage3(e) {
      let files = [];
      for (var i = 0; i < this.files3.length; i++) {
        files.push(baseImgPath + this.files3[i].FILEPATH)
      }
      uni.previewImage({
        urls: files,
        current: e.currentTarget.dataset.index
      });
    },
    ViewShowImage4(e) {
      let files = [];
      for (var i = 0; i < this.files4.length; i++) {
        files.push(baseImgPath + this.files4[i].FILEPATH)
      }
      uni.previewImage({
        urls: files,
        current: e.currentTarget.dataset.index
      });
    },
    ViewShowImages(imgs, index) {
      let files = [];
      for (var i = 0; i < imgs.length; i++) {
        files.push(baseImgPath + imgs[i].FILEPATH)
      }
      uni.previewImage({
        urls: files,
        current: index
      });
    },
    goToOpen(e) {
      var url = e;
      plus.runtime.openURL(url, function (res) {
        console.log(res);
      });


      // uni.navigateTo({
      // 	url: '/pages/application/safety-production-account/organization-personnel/web-view?link=' + url
      // });
    },
    playVideo(e) {
      this.videoSrc = e.currentTarget.dataset.src
      this.modalShow = true
    }
  }
}
</script>

<style>

</style>
