<template>
  <a-modal
    :title="title"
    :width="width"
    :bodyStyle="bodyStyle"
    @cancel="handleCancel"
    :maskClosable="false"
    :footer="null"
    :visible="visible">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item :label="contractName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-upload
            :multiple="true"
            :fileList="fileList"
            :showUploadList="showUploadList"
          >
          </a-upload>
        </a-form-item>

      </a-form>
    </a-spin>


  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import Vue from 'vue'
  import { ACCESS_TOKEN } from '@/store/mutation-types'

  const FILE_TYPE_ALL = "all"
  const uidGenerator = () => {
    return '-' + parseInt(Math.random() * 10000 + 1, 10)
  }
  const getFileName = (path) => {
    if (path.lastIndexOf('\\') >= 0) {
      let reg = new RegExp('\\\\', 'g')
      path = path.replace(reg, '/')
    }
    return path.substring(path.lastIndexOf('/') + 1)
  }

  export default {
    name: 'HlgViewContractModal',
    components: {

    },
    data() {
      return {
        disableSubmit:false,
        options: [{
          value: '',
          label: '',
          isLeaf: false
        }],
        companyId: '',
        form: this.$form.createForm(this),
        picUrl: '',
        title: '操作',
        width: 800,
        bodyStyle: {
          paddingTop: '20px',
          paddingBottom:'50px',
          height: (window.innerHeight * 0.38) + 'px',
          'overflow-y': 'auto'
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        contractName: '合同',
        //移除删除按钮
        showUploadList:{showRemoveIcon:false},
        uploadLoading: false,
        confirmLoading: false,
        headers: {},
        fileList:[],
        validatorRules: {

        },
        url: {
          add: '/hlguser/hlgUserSubcontract/add',
          edit: '/hlguser/hlgUserSubcontract/edit',
          fileUpload: window._CONFIG['domianURL'] + '/hpSys/common/ossUpload',
          imgerver: window._CONFIG['imgDomainOssURL'],
          hpWorkImgerver:window._CONFIG['imgHpworkDomainOssURL']
        }

      }
    },
    created() {
      const token = Vue.ls.get(ACCESS_TOKEN)
      this.headers = { 'X-Access-Token': token }

    },
    methods: {
      add() {
        this.edit({})
      },
      edit(serviceContract,systemType,isImport) {
        this.form.resetFields()
        this.visible = true;
        //回显文件
        this.editFileList(serviceContract,systemType,isImport)
      },
      close() {
        this.$emit('close')
        this.visible = false
      },

      //回显文件所用
      editFileList(paths,systemType,isImport) {
        if (!paths || paths.length == 0) {
          //return [];
          // update-begin- --- author:os_chengtgen ------ date:20190729 ---- for:issues:326,Jupload组件初始化bug
          this.fileList = []
          return
          // update-end- --- author:os_chengtgen ------ date:20190729 ---- for:issues:326,Jupload组件初始化bug
        }
        let fileList = []
        let arr = paths.split(',')
        var imgerver=systemType===1? this.url.imgerver:this.url.hpWorkImgerver
        for (var a = 0; a < arr.length; a++) {
          fileList.push({
            uid: uidGenerator(),
            name: getFileName(arr[a]),
            status: 'done',
            url:this.getAvatarView(arr[a],isImport),
          })
        }
        this.fileList = fileList
      },
      handleCancel() {
        this.close()
      },
      getAvatarView(idcardPicture,isImport) {
        if( idcardPicture.indexOf("http")!=-1){
          return idcardPicture
        }else{
          return isImport==1?this.url.hpWorkImgerver+idcardPicture:this.url.imgerver+idcardPicture
        }
      },
    }
  }
</script>

<style lang="less" scoped>

</style>