<template>
  <a-modal
    :title="$t('global-btn.export')"
    :visible='visible'
    :width="400"
    :maskClosable="false"
    @cancel="closeModal"
    @ok="exportFile"
    :okText="$t('global-btn.export')">
    <div>
      <h3>{{$t('global-dict.please-select-export-type')}}</h3>
      <a-radio-group v-model="exportType">
        <a-radio value="1" class="mr-4">{{$t('global-dict.export-by-the-selected-columns')}}</a-radio>
        <a-radio value="0">{{$t('global-dict.export-default-table-columns')}}</a-radio>
      </a-radio-group>
    </div>
  </a-modal>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      exportType: '1',
      tableId: undefined,
      formData: {
        struId: undefined,
        struFlag: undefined,
        childStruIds: undefined,
        actionType: undefined,
        state: undefined,
        actionState: undefined,
        planSDate: undefined,
        planEDate: undefined,
        startSDate: undefined,
        endEDate: undefined,
        completeSDate: undefined,
        completeEDate: undefined,
        userId: undefined,
        userEmptyFlag: undefined,
        twoLanguage: undefined,
        distributeStatus: undefined
      }
    };
  },
  methods: {
    /**
     * 关闭模态框
     *
     * @returns 无返回值
     */
    closeModal() {
      this.visible = false;
      this.exportType ='1';
      this.tableId = '';

      this.formData = {
        struId: undefined,
        struFlag: undefined,
        childStruIds: undefined,
        actionType: undefined,
        state: undefined,
        actionState: undefined,
        planSDate: undefined,
        planEDate: undefined,
        startSDate: undefined,
        endEDate: undefined,
        completeSDate: undefined,
        completeEDate: undefined,
        userId: undefined,
        userEmptyFlag: undefined,
        twoLanguage: undefined,
        distributeStatus: undefined
      };
    },
    /**
     * 导出文件
     */
    exportFile() {
      let tableId = this.tableId || '';
      let exportType = this.exportType;
      let rfmeaId = this.$store.getters.rfmeaId;
      let struId = this.formData.struIds || "";
      let struFlag = this.formData.struFlag || "";
      let childStruIds = this.formData.childStruIds || "";
      let actionType = this.formData.actionType || "";
      let state = this.formData.state || "";
      let actionState = this.formData.actionState || "";
      let planSDate = this.formData.planSDate || "";
      let planEDate = this.formData.planEDate || "";
      let startSDate = this.formData.startSDate || "";
      let endEDate = this.formData.endEDate || "";
      let completeSDate = this.formData.completeSDate || "";
      let completeEDate = this.formData.completeEDate || "";
      let userId = this.formData.userId || "";
      let userEmptyFlag = this.formData.userEmptyFlag || "";
      let twoLanguage = this.formData.twoLanguage || "";
      let distributeStatus = this.formData.distributeStatus || "";
      let url =
        this.$api.baseUrl +
        "/DFMEA/rdfmAction/Rb0426191/export?fmeaId=" +
        rfmeaId +
        "&struIds=" +
        struId +
        "&childStruIds=" +
        childStruIds +
        "&actionType=" +
        actionType +
        "&state=" +
        state +
        "&actionState=" +
        actionState +
        "&planSDate=" +
        planSDate +
        "&planEDate=" +
        planEDate +
        "&startSDate=" +
        startSDate +
        "&endEDate=" +
        endEDate +
        "&completeSDate=" +
        completeSDate +
        "&completeEDate=" +
        completeEDate +
        "&userId=" +
        userId +
        "&userEmptyFlag=" +
        userEmptyFlag +
        "&twoLanguage=" +
        twoLanguage +
        "&distributeStatus=" +
        distributeStatus +
        "&struFlag=" +
        struFlag +
        "&tableId=" +
        tableId +
        "&exportType=" +
        exportType;
      window.open(url);
      this.closeModal();
    }
  }
};
</script>
