
import { attachmentList } from "@/api/common/uploadAttachment.js";
import { getPermanent, attachmentQuery, getInfo } from '../api/index.js';
import DictTag from '@/components/DictTag';
export default {
  components: {
    DictTag
  },
  props: {
    data: {},
    type: {
      type: String,
      default: '1'
    }
  },
  data () {
    return {
      isLoad: false,
      permanentDetail: {},
      // 资产类别字典
      assetTypeOptions: [],
      // 经营属性字典
      operationTypeOptions: [],
      // 增加方式字典
      addTypeOptions: [],
      // 使用情况字典
      useTypeOptions: [],
      // 折旧方式字典
      depreciationTypeOptions: [],
      // 资产状态字典
      assetStatusOptions: [],
      // 系统是否字典
      sysYesNoOptions: [],
      // 履约情况字典
      agreeTypeOptions: [],
      //单位字段
      unitOptions:[],
      // 合同类型字典
      typeOfContractTypeOptions: [],
      // 结款方式字典
      settleTypeOptions: [],
      // 收付款类型字典
      collectionPayOptions: [],
      // 合同来源字典
      contractionSourceOptions: [],
      // 合同状态字典
      contractionStatusOptions: [],
      // 招标方式字典
      biddingWayOptions: [],
      // 招标类型字典
      biddingTypesOptions: [],
      // 合同支付方式字典
      contractPaymentTypeOptions: [],
      // 投资形式字典
      investTypeOptions: [],
      // 出资形式字典
      payTypeOptions: [],

      showfile: false,
      showfileHT: false,
    };
  },
  watch: {
    data: {
      handler () {
        this.getData();
      },
      immediate: true, // 立即执行
    }
  },
  computed: {
  },
  created () {
    this.isLoad = false
    this.getDicts("asset_type").then((response) => {
      this.assetTypeOptions = response.data;
    });
    this.getDicts("operation_type").then((response) => {
      this.operationTypeOptions = response.data;
    });
    this.getDicts("add_type").then((response) => {
      this.addTypeOptions = response.data;
    });
    this.getDicts("use_type").then((response) => {
      this.useTypeOptions = response.data;
    });
    this.getDicts("depreciation_type").then((response) => {
      this.depreciationTypeOptions = response.data;
    });
    this.getDicts("asset_status").then((response) => {
      this.assetStatusOptions = response.data;
    });
    this.getDicts("fixed_assets_unit").then((response) => {
      this.unitOptions = response.data;
    });
    this.getDicts("sys_yes_no").then((response) => {
      this.sysYesNoOptions = response.data;
    });
    this.getDicts("agree_type").then(response => {
      this.agreeTypeOptions = response.data;
    });
    this.getDicts("type_of_contract").then(response => {
      this.typeOfContractTypeOptions = response.data;
    });
    this.getDicts("settle_type").then(response => {
      this.settleTypeOptions = response.data;
    });
    this.getDicts("collection_pay").then(response => {
      this.collectionPayOptions = response.data;
    });
    this.getDicts("contraction_source").then(response => {
      this.contractionSourceOptions = response.data;
    });
    this.getDicts("contraction_status").then(response => {
      this.contractionStatusOptions = response.data;
    });
    this.getDicts("bidding_way").then(response => {
      this.biddingWayOptions = response.data;
    });
    this.getDicts("bidding_types").then(response => {
      this.biddingTypesOptions = response.data;
    });
    this.getDicts("contract_payment_type").then(response => {
      this.contractPaymentTypeOptions = response.data;
    });
    this.getDicts("invest_type").then(response => {
      this.investTypeOptions = response.data;
    });
    this.getDicts("pay_type").then(response => {
      this.payTypeOptions = response.data;
    });
  },
  mounted () {
  },
  methods: {
    openImage (url) {
      this.$emit('openImage',url)
      // this.dialogImageUrl = url;
      // this.dialogVisible = true;
    },
    close () {
      this.$emit('close')
    },
    getData(){
      this.showfile = false;
      this.showfileHT = false;
      if (this.type == '1' ||this.type == '2' || this.type == '3'){
        getPermanent(this.data.id).then((response) => {
          this.permanentDetail = response.data;
          this.permanentDetail.fileList = [];
          attachmentQuery({tableId: this.data.id, tableName: 't_asset_permanent', bizPath: 'asset'}).then((response) => {
            if (response.code == 200) {
              let UattachmentList = response.rows;
              for (let i = 0; i < UattachmentList.length; i++) {
                let fileName = UattachmentList[i].fileName;
                let subIndex = fileName.lastIndexOf(".");
                let ext = fileName.substring(subIndex + 1, fileName.length);
                let urls = "";
                let type = "";
                if (ext == "xlsx" || ext == "xls") {
                  urls = require("./icon_excel.jpg");
                  type = 'excel';
                } else if (ext == "doc" || ext == "docx") {
                  urls = require("./icon_word.jpg");
                  type = 'word';
                } else if (ext == "pdf") {
                  urls = require("./icon_pdf.jpg");
                  type = 'pdf';
                } else if (ext == "zip") {
                  urls = require("./icon_zip.jpg");
                  type = 'zip';
                } else {
                  urls = UattachmentList[i].fileUrl;
                  type = 'image';
                }
                this.permanentDetail.fileList.push({
                  url: urls,
                  urlApi: '/api' + UattachmentList[i].fileUrl,
                  thumUrl: '/api' + UattachmentList[i].thumUrl,
                  type: type
                })
                this.showfile = true;
              }
            }
          });
        });
      }
      if (this.type == '4' || this.type == '5' || this.type == '6'){
        getInfo(this.data.id).then((response) => {
          this.permanentDetail = response.data;
          this.permanentDetail.fileList = [];
          attachmentQuery({tableId: this.data.id, tableName: 't_contraction_info', bizPath: 'contraction'}).then((response) => {
            if (response.code == 200) {
              let UattachmentList = response.rows;
              for (let i = 0; i < UattachmentList.length; i++) {
                let fileName = UattachmentList[i].fileName;
                let subIndex = fileName.lastIndexOf(".");
                let ext = fileName.substring(subIndex + 1, fileName.length);
                let urls = "";
                let type = "";
                if (ext == "xlsx" || ext == "xls") {
                  urls = require("./icon_excel.jpg");
                  type = 'excel';
                } else if (ext == "doc" || ext == "docx") {
                  urls = require("./icon_word.jpg");
                  type = 'word';
                } else if (ext == "pdf") {
                  urls = require("./icon_pdf.jpg");
                  type = 'pdf';
                } else if (ext == "zip") {
                  urls = require("./icon_zip.jpg");
                  type = 'zip';
                } else {
                  urls = UattachmentList[i].fileUrl;
                  type = 'image';
                }
                this.permanentDetail.fileList.push({
                  url: urls,
                  urlApi: '/api' + UattachmentList[i].fileUrl,
                  thumUrl: '/api' + UattachmentList[i].thumUrl,
                  type: type
                })
                this.showfileHT = true;
              }
            }
          });
        });
      }

    }
  }
};
