<template>
  <div>
    <Modal
      v-model="modalVisible"
      :title="completeTitle"
      :mask="true"
      :closable="true"
      :mask-closable="false"
      :width="width"
      class="importDialogAddOther"
      @on-cancel="closeDialog"
    >
      <div>
        <div
          v-if="tablename == 'T_OMSALIPAYBILLDETAIL' || tablename == 'T_OMSSTATEACCOUNTTOPOSITEM'"
          class="importForm"
        >
          <Form
            ref="formModel"
            :model="formModel"
            :rules="ruleValidate"
            :label-width="75"
            label-position="left"
          >
            <FormItem
              label="对账平台:"
              prop="accountType"
              v-if="tablename == 'T_OMSALIPAYBILLDETAIL'"
            >
              <Select
                v-model="formModel.accountType"
                filterable
                clearable
                @on-change="changeType"
              >
                <Option
                  v-for="item in accountTypeList"
                  :key="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </Option>
              </Select>
            </FormItem>
            <FormItem
              label="账户:"
              required
              v-if="formModel.accountType == 1 && tablename == 'T_OMSALIPAYBILLDETAIL'"
            >
              <Select
                v-model="formModel.account"
                @on-change="changeAccount"
                filterable
                clearable
              >
                <Option
                  v-for="item in accountList"
                  :key="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </Option>
              </Select>
              <div class="inputTip">
                没找到？点击这里<span
                  class="ToNewAccount"
                  @click="ToNewAccount"
                >新建账号</span>
              </div>
            </FormItem>
            <FormItem
              label="店铺:"
              required
              v-if="(formModel.accountType && formModel.accountType != 1) || tablename == 'T_OMSSTATEACCOUNTTOPOSITEM'"
            >
              <Select
                v-model="formModel.shopId"
                filterable
                clearable
              >
                <Option
                  v-for="item in shopList"
                  :key="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </Option>
              </Select>
            </FormItem>
            <FormItem
              label="账单类型:"
              prop="billType"
              v-if="formModel.accountType == 2"
            >
              <Select
                v-model="formModel.billType"
                filterable
                clearable
              >
                <Option value="0">月账单</Option>
                <Option value="1">账户流水</Option>
              </Select>
            </FormItem>
            <FormItem
              label="账单类型:"
              prop="billType"
              v-if="formModel.accountType == 7 || formModel.accountType == 20"
            >
              <Select
                v-model="formModel.billType"
                filterable
                clearable
              >
                <Option value="0">线上交易</Option>
                <Option value="1">线上退款</Option>
              </Select>
            </FormItem>
          </Form>
        </div>
        <div class="import-panel">
          <div class="upload-panel">
            <span style="display: inline-block;width: 75px;">文件:</span><Button
              type="posdefault"
              :size="buttonSize"
            >
              选择文件
            </Button>
            <!-- name -->
            <input
              id="file"
              class="fileInput"
              type="file"
              accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
              @change="fileChange($event)"
            >
            <!-- @click="clearFile" -->
            <!-- <div
              class="tip"
            >
              {{ ChineseDictionary.FILEMAX }}{{ fileSizeNumber }}
            </div> -->
            <div
              v-if="fileName"
              class="tip fileName"
            >
              已选择：<span class="chooedFile">{{ fileName }}</span>
            </div>
          </div>
          <transition name="fade">
            <span v-if="loading">数据正在导入中，请稍候</span>
          </transition>
          <div class="el-upload__tip" style="line-height:18px;">
            注意：<span style='font-size: 14px;font-weight:600;'>{{ ChineseDictionary.IMPORTTITLETWO }}</span>{{ ChineseDictionary.IMPORTTITLE }}
            <a
              @click.stop="downloadTemplate"
            >{{ ChineseDictionary.DOWNTEMPLATE }}</a>
          </div>
        </div>
      </div>
      <div slot="footer">
        <div>
          <Button
            type="fcdefault"
            :disabled="loading"
            :size="buttonSize"
            @click="submitUpload()"
          >
            {{ ChineseDictionary.IMPORT }}
          </Button>

          <Button
            type="fcdefault"
            :size="buttonSize"
            @click.stop="closeDialog(false)"
          >
            {{ ChineseDictionary.CANCEL }}
          </Button>
        </div>
        <div
          v-if="errorMsg.errorList.length>0"
          class="error-content"
        >
          <div class="error-message">
            <div class="left-icon">
              <i class="iconfont">&#xecd0;</i>
            </div>
            <div class="right-content">
              <p
                v-if="errorMsg.errorUrl.length > 0"
                class="link"
              >
                <a :href="errorMsg.errorUrl">（下载报错信息）</a>
              </p>
              <div class="content-message">
                <p class="title">
                  {{ errorMsg.message }}
                </p>
                <p
                  v-for="(msg,index) in errorMsg.errorList"
                  :key="index"
                >
                  <span v-if="msg.rowIndex&&!(tablename=='V_IES_PRODUCT'||tablename=='T_IESSkuGroupDetail')">第{{ msg.rowIndex }}条记录报错:</span>
                  {{ msg.message }}
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </Modal>
  </div>
</template>

<script>
  // import axios from 'axios';
  // import ChineseDictionary from '../assets/js/ChineseDictionary';
  // import network, { urlSearchParams, getGateway } from '../__utils__/network';
  import Upload from '../../assets/js/upload';

  import { DispatchEvent, R3_IMPORT } from '../../assets/js/__utils__/dispatchEvent';

  const R3 = window.R3;

  const { network, urlSearchParams } = R3;

  export default {
    name: 'ImportDialog',
    props: {
      // name: {
      //   type: Boolean,
      //   default: false
      // },
      customImport: {
        type: Boolean,
        default: false
      }, // 自定义导入接口
      fatherMethod: {
        type: Function,
        default: null
      },
      visible: {// 是否打开弹框
        // 显示
        type: Boolean,
        default: false
      },
      title: {// 弹框title
        // 标题
        type: String,
        default: ''
      },
      combinedCommoditySku: {// 福袋商品对应虚拟条码
        type: String,
        default: ''
      },
      tablename: {// /p/cs/downloadImportTemplate 用于下载模版,上传文件参数
        // 子表名
        type: String,
        default: ''
      },
      mainTable: {// 用于/p/cs/import参数上传文件
        // 主表名
        type: String,
        default: ''
      },
      mainId: {// 用于/p/cs/import参数上传文件
        // 主表id
        type: [Number, String],
        default: -1
      },
      width: {// 当前弹框参数
        // 宽度
        type: String,
        default: '630'
      },
      accountList: {
        // 宽度
        type: Array,
        default: () => []
      },
    },
    components: {},
    data() {
      return {
        accountTypeList: [ // 对账平台
          {
            label: '淘宝(支付宝)',
            value: 1,
            platform: '0',
          },
          {
            label: '淘宝(微信)',
            value: 18,
            platform: '2',
          },
          {
            label: '京东',
            value: 2,
            platform: '4',
          },
          {
            label: '抖音',
            value: 3,
            platform: '57',
          },
          {
            label: '拼多多',
            value: 4,
            platform: '27',
          },
          {
            label: '京东厂直',
            value: 5,
            platform: '500',
          },
          {
            label: '小红书（新）',
            value: 6,
            platform: '116',
          },
          {
            label: '微盟',
            value: 7,
            platform: '30',
          },
          {
            label: '视频号小店',
            value: 8,
            platform: '243',
          },
          {
            label: '快手',
            value: 9,
            platform: '201',
          },
          {
            label: '得物（品牌直发）',
            value: 10,
            platform: '223',
          },
          {
            label: '得物（入仓）',
            value: 11,
            platform: '119',
          },
          {
            label: '得物（品牌专供）',
            value: 12,
            platform: '118',
          },
          {
            label: '得物（普通预售）',
            value: 13,
            platform: '117',
          },
          {
            label: '得物（普通现货）',
            value: 14,
            platform: '86',
          },
          {
            label: '驿氪',
            value: 17,
            platform: '401',
          },
          // {
            // label: '得物云仓（作废）',
            // value: 15,
            // platform: '85',
          // },
          {
            label: '其它',
            value: 16,
            platform: '1888',
          },
          {
            label: '微盟(wos)',
            value: 20,
            platform: '253',
          },
          {
            label: '有赞',
            value: 21,
            platform: '20',
          }
        ],
        inputValue: '2', // 有效起始行
        singleValue: '', // 更新记录
        modalVisible: false,
        showFlag: false,
        loading: false, // 是否加载
        ChineseDictionary: {
          IMPORTTITLE: '上传文件中，不要放置宏或图标，不要更改列的顺序，数据中不要使用公式。',
          IMPORTTITLETWO: '请注意模版内容格式，会直接影响后续对账数据准确性。',
          IMPORT: '导入',
          CANCEL: '取消',
          DOWNTEMPLATE: '(下载模版)',
          FILEMAX: '文件最大'
        },
        fileSizeNumber: '',
        fileSize: '', // 文件尺寸
        importFlies: [], // 导入文件列表
        errorMsg: {
          // 错误信息
          errorUrl: '',
          message: '',
          errorList: []
        },
        files: [],
        buttonSize: 'small',
        fileName: '',

        // 财务对账
        formModel: {
          accountType: '',
          account: '',
          shopId: '',
          billType: '0',
        },
        ruleValidate: {
          accountType: [
            { required: true, message: '', trigger: 'blur' }
          ],
          shopId: [
            { required: true, message: '', trigger: 'blur' }
          ],
        },
        shopList: [],
      };
    },
    watch: {
      modalVisible: {
        handler(val) {
          if (!val) {
            this.$emit('closeDialog');
          }
        }
      },
      visible: {
        handler(val) {
          if (val) {
            this.modalVisible = true;
          } else {
            this.modalVisible = false;
          }
        }
      }
    },
    mounted() {
      if(this.tablename == 'T_OMSSTATEACCOUNTTOPOSITEM'){
        this.getShopList('19');
      }
      if (this.visible) this.modalVisible = true;
      else this.modalVisible = false;
      this.axiosSetting();
    },

    computed: {
      completeTitle() {
        let name = '';
        name = '导入账单';
        return name;
      },
      inpNum() {
        return this.inputValue;
      }
    },

    methods: {
      changeAccount() { // 选择账号
        this.formModel.shopId = this.accountList.find(item => item.value == this.formModel.account).shopId
      },
      getShopList(accountType) { // 获取对应平台店铺列表
        let platFormVal = accountType;
        if (accountType == 19) {
          platFormVal = accountType;
        } else if (accountType == 16) {
          platFormVal = '';
        } else {
          platFormVal = this.accountTypeList.find(item => item.value == accountType).platform;
        }
        network.post('/p/cs/QueryList', urlSearchParams({
          searchdata: {
            "table":"T_V_IESSHOP",
            "startindex":0,
            "range":1000,
            "fixedcolumns": {
              "ISACTIVE": accountType == '19' ? 'Y' : '',
              "PLATFORM": platFormVal,
            },
            "column_include_uicontroller":true,
            "isolr":false
          }
        })).then(res => {
          let list = [];
          res.data.data.row.forEach(item => {
            let obj = {
              label: item.SHOPTITLE.val,
              value: item.ID.val
            };
            list.push(obj);
          });
          this.shopList = list;
        });
      },
      changeType() {
        this.shopList = [];
        this.getShopList(this.formModel.accountType);
      },
      getGateway(str) {
        return `${str}`;
      },
      handleInput(event) {
        const val = event.target.value.trim();
        // 只能是正整数或空,可根据需求修改正则
        if (/^[1-9]\d*$|^$/.test(val)) {
          this.inputValue = val;
        } else {
          event.target.value = this.inputValue;
        }
      },
      clearFile() {
        this.fileName = '';
        this.loading = false;
        this.files = [];
        const fileDom = document.getElementById('file');
        fileDom.value = '';
      },
      fileChange(e) {
        this.errorMsg = {
          // 错误信息
          errorUrl: '',
          message: '',
          errorList: []
        };
        this.files = e.target.files[0];
        this.fileName = e.target.files[0].name;
        this.fileSize = e.target.files[0].size;
      },
      // 发送请求, 获取上传参数
      axiosSetting() {
        network.post('/p/cs/settings',
                     urlSearchParams({
                       configNames: JSON.stringify(['upload.import.max-file-size'])
                     })).then((res) => {
          if (res.data.code === 0) {
            this.fileSizeNumber = res.data.data['upload.import.max-file-size'];
          } else this.fileSizeNumber = '0M';
        })
          .catch((error) => {
            if (error.response.status === 403) {
              this.closeDialog();
            }
            this.fileSizeNumber = '0M';
          });
      },
      // 发送请求, 下载模板
      downloadTemplate() {
        if (this.customImport) {
          if (this.tablename == 'T_OMSALIPAYBILLDETAIL') { 
            const link = document.createElement('a');
            link.style.display = 'none';
            if (!this.formModel.accountType) {
              return this.$Message.warning('请先选择对账平台！');
            }
            // 财务对账(对账-->平台原始账单（支付宝）)
            // 定义一个映射对象
            const accountTypeMap = {
              1: { href: '../../../static/importExcel/平台账单支付宝导入模板.xlsx', download: '平台账单支付宝导入模板.xlsx' },
              2: { href: '../../../static/importExcel/平台账单京东导入模板.xlsx', download: '平台账单京东导入模板.xlsx' },
              3: { href: '../../../static/importExcel/平台账单抖音导入模板.xlsx', download: '平台账单抖音导入模板.xlsx' },
              4: { href: '../../../static/importExcel/平台账单拼多多导入模板.xlsx', download: '平台账单拼多多导入模板.xlsx' },
              5: { href: '../../../static/importExcel/平台账单京东厂直导入模版.xlsx', download: '平台账单京东厂直导入模版.xlsx' },
              6: { href: '../../../static/importExcel/平台账单小红书导入模板.xlsx', download: '平台账单小红书导入模板.xlsx' },
              7: { href: '../../../static/importExcel/平台账单微盟导入模板.xlsx', download: '平台账单微盟导入模板.xlsx' },
              8: { href: '../../../static/importExcel/平台账单视频号导入模板.xlsx', download: '平台账单视频号导入模板.xlsx' },
              9: { href: '../../../static/importExcel/平台账单快手导入模板.xlsx', download: '平台账单快手导入模板.xlsx' },
              10: { href: '../../../static/importExcel/平台账单得物导入模板.xlsx', download: '平台账单得物导入模板.xlsx' },
              11: { href: '../../../static/importExcel/平台账单得物导入模板.xlsx', download: '平台账单得物导入模板.xlsx' },
              12: { href: '../../../static/importExcel/平台账单得物导入模板.xlsx', download: '平台账单得物导入模板.xlsx' },
              13: { href: '../../../static/importExcel/平台账单得物导入模板.xlsx', download: '平台账单得物导入模板.xlsx' },
              14: { href: '../../../static/importExcel/平台账单得物导入模板.xlsx', download: '平台账单得物导入模板.xlsx' },
              15: { href: '../../../static/importExcel/平台账单得物导入模板.xlsx', download: '平台账单得物导入模板.xlsx' },
              16: { href: '../../../static/importExcel/其它账单导入模板.xlsx', download: '其它账单导入模板.xlsx' },
              17: { href: '../../../static/importExcel/平台账单驿氪导入模板.xlsx', download: '平台账单驿氪导入模板.xlsx' },
              18: { href: '../../../static/importExcel/平台账单淘宝(微信)导入模板.xlsx', download: '平台账单淘宝(微信)导入模板.xlsx' },
              20: { href: '../../../static/importExcel/平台账单微盟(wos)导入模板.xlsx', download: '平台账单微盟(wos)导入模板.xlsx' },
              21: { href: '../../../static/importExcel/平台账单有赞导入模板.xlsx', download: '平台账单有赞导入模板.xlsx' },
              billType0: { href: '../../../static/importExcel/平台账单京东导入模板.xlsx', download: '平台账单京东导入模板-月账单.xlsx' },
              billType1: { href: '../../../static/importExcel/平台账单京东导入模板-账户流水.csv', download: '平台账单京东导入模板-账户流水.csv' },
              'billType7-0': { href: '../../../static/importExcel/平台账单微盟导入模板-线上交易.xlsx', download: '平台账单微盟导入模板-线上交易.xlsx' },
              'billType7-1': { href: '../../../static/importExcel/平台账单微盟导入模板-线上退款.xlsx', download: '平台账单微盟导入模板-线上退款.xlsx' },
              'billType20-0': { href: '../../../static/importExcel/平台账单微盟(wos)导入模板-线上交易.xlsx', download: '平台账单微盟(wos)导入模板-线上交易.xlsx' },
              'billType20-1': { href: '../../../static/importExcel/平台账单微盟(wos)导入模板-线上退款.xlsx', download: '平台账单微盟(wos)导入模板-线上退款.xlsx' },
            };
            // 获取 accountType
            const accountType = this.formModel.accountType;
            // 根据 accountType 获取对应的 href 和 download
            let href; let 
            download;
            if (accountType === 2) {
              // 京东账单根据billType取不同模板
              const billTypeKey = `billType${this.formModel.billType}`;
              ({ href, download } = accountTypeMap[billTypeKey] || { href: '', download: '' });
            }else if(accountType ===7 || accountType === 20){
              //微盟/微盟WOS账单导入逻辑
              const billTypeKey = `billType${accountType}-${this.formModel.billType}`;
              ({ href, download } = accountTypeMap[`${billTypeKey}`] || { href: '', download: '' });
            }else{
              ({ href, download } = accountTypeMap[accountType] || { href: '', download: '' });
            }
           
            // 设置 link 的属性
            link.href = href;
            link.setAttribute('download', download);
            document.body.appendChild(link);
            link.click();
          }else if(this.tablename == 'T_OMSSTATEACCOUNTTOPOSITEM') {
            const link = document.createElement('a');
            link.style.display = 'none';
            link.href = '../../../static/importExcel/唯品会账单导入模版.xlsx';
            link.setAttribute('download', '唯品会账单导入模版.xlsx');
            document.body.appendChild(link);
            link.click();
          }
        }
      },
      // 提交上传文件请求
      submitUpload() {
        if (this.tablename == 'T_OMSALIPAYBILLDETAIL') {
          if (this.formModel.accountType == '' || !this.formModel.accountType) {
            return this.$Message.warning('请先选择对账平台！');
          }
          if (this.formModel.accountType !=1 && !this.formModel.shopId) {
            return this.$Message.warning('请先选择店铺！');
          }
        }else if(this.tablename == 'T_OMSSTATEACCOUNTTOPOSITEM'){
          if (!this.formModel.shopId) {
            return this.$Message.warning('请先选择店铺！');
          }
        }
        
        if (this.files.length === 0) {
          return this.$Modal.fcWarning({
            title: '警告',
            mask: true,
            content: '请先选择要导入的文件！'
          });
        }
        this.uploadFileChange();
      },
      uploadFileChange(param = {}) {
        this.errorMsg = {
          // 错误信息
          errorUrl: '',
          message: '',
          errorList: []
        };
        this.loading = true;
        // 上传文件
        const fileInformationUploaded = this.files;
        // this.$R3loading.show();
        // debugger;
        let url = '';
        let aUploadParame;
        let sendData = {};
        if (this.customImport) {
          if (this.tablename == 'T_OMSALIPAYBILLDETAIL') { // 平台账单导入
            url = `${this.getGateway('/p/cs/alipay_data_service_bill_upload')}`;
            // 京东和抖音使用新接口
            const typeArr = [2, 3];
            if (typeArr.indexOf(Number(this.formModel.accountType)) > -1) {
              url = "/p/cs/alipay_data_service_bill_upload_batch";
            }
          }else if (this.tablename == 'T_OMSSTATEACCOUNTTOPOSITEM'){
            url = `${this.getGateway('/p/cs/wph/bill/upload')}`;
          }
          if (this.tablename == 'T_OMSALIPAYBILLDETAIL') { // 平台账单导入
            if (this.formModel.accountType == 1) { // 淘宝(支付宝)
              sendData = {
                platCode: 0,
                shopId:this.formModel.shopId
              }; 
            } else if (this.formModel.accountType === 18) { // 微信(支付宝)
              sendData = {
                platCode: 2,
                shopId:this.formModel.shopId
              }; 
            } else if (this.formModel.accountType == 2) { // 京东
              sendData = {
                platCode: 4,
                billtype: this.formModel.billType,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 3) { // 抖音
              sendData = {
                platCode: 57,
                shopId:this.formModel.shopId
                
              };
            } else if (this.formModel.accountType == 4) { // 拼多多
              sendData = {
                platCode: 27,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 5) { // 京东厂直
              sendData = {
                platCode: 500,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 6) { // 小红书
              sendData = {
                platCode: 116,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 7) { // 微盟
              sendData = {
                platCode: 30,
                billtype: this.formModel.billType,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 8) { // 视频号
              sendData = {
                platCode: 243,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 9) { // 快手
              sendData = {
                platCode: 201,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 10) { // 得物（品牌直发）
              sendData = {
                platCode: 223,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 11) { // 得物（入仓）
              sendData = {
                platCode: 119,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 12) { // 得物（品牌专供）
              sendData = {
                platCode: 118,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 13) { // 得物（普通预售）
              sendData = {
                platCode: 117,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 14) { // 得物（普通现货）
              sendData = {
                platCode: 86,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 15) { // 得物云仓（作废）
              sendData = {
                platCode: 85,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 17) { // 驿氪
              sendData = {
                platCode: 401,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 16) { // 其它
              sendData = {
                platCode: 1888,
                shopId:this.formModel.shopId
              };
            } else if (this.formModel.accountType == 20) { // 微盟（WOS）
              sendData = {
                platCode: 253,
                billtype: this.formModel.billType,
                shopId:this.formModel.shopId
              } 
            }else if (this.formModel.accountType == 21) { // 有赞
              sendData = {
                platCode: 20,
                shopId:this.formModel.shopId
              };
            }
          }else if(this.tablename == 'T_OMSSTATEACCOUNTTOPOSITEM') {
            sendData = {
              shopId:this.formModel.shopId
            };
          }
        }
        const { isConfirmRepeat } = param;
        if (isConfirmRepeat) {
          sendData.isContinue = isConfirmRepeat;
        }
        aUploadParame = Object.assign(
          {},
          {
            target: fileInformationUploaded,
            url,
            sendData,
            imgSize: this.fileSize,
            success: this.handleSuccess,
            onerror: this.handleError,
            onloadstart: this.onloadstart,
            type: 'file'

          }
        );
        const article = new Upload(aUploadParame);
        console.log(article, 'article');
      },
      // 上传成功
      handleSuccess(response) {
        const { tableName } = this.$route.params;
        const { code, message } = response || {};
        if (response.code === 0) {
          this.$R3loading.hide(tableName);
          this.closeDialog();
          this.fileName = '';
          this.$Modal.fcSuccess({
            title: '成功',
            mask: true,
            content: response.message
          });
          this.$emit('importantSuccess');
          if (this.tablename == 'T_IESSkuGroupDetail') {
            this.$emit('jumpPage'); // 福袋商品导入成功跳转编辑页面
          }
          const asyncTaskScheme = () => (window.ProjectConfig && window.ProjectConfig.asyncTaskScheme ? window.ProjectConfig.asyncTaskScheme : ''); // 异步导出设计方案
          if(asyncTaskScheme() === 'skq') {
            const params = {
              detail: {
                type: 'notice'
              }
            }
            DispatchEvent(R3_IMPORT, params)
            this.$R3loading.hide(this.loadingName);
            this.closeDialog()
            return
          }
        } else if (code === 10) {
          this.$Modal.fcWarning({
            title: '警告',
            mask: true,
            content: message,
            okText: '确定',
            cancelText: '取消',
            showCancel: true,
            onOk: () => {
              this.uploadFileChange({ isConfirmRepeat: 1 });
            },
            onCancel: () => {
              this.loading = false;
            }
          });
          return;
        } else {
          this.$R3loading.hide(tableName);
          if (response.data) {
            if (response.data.path) {
              if (response.data.path === 'undefined ===') {
                this.errorMsg.errorUrl = '';
              } else {
                const gatewayth = this.getGateway('/p/cs/download?filename');
                this.errorMsg.errorUrl = this.urlChange(`${gatewayth}=${
                  response.data.path
                }`);
              }
            }
            this.errorMsg.errorList = response.data.error || [
              { rowIndex: 0, message: '' }
            ];
          } else {
            this.errorMsg.errorList = response.error || [
              { rowIndex: 0, message: '' }
            ];
          }
          this.errorMsg.message = response.message;
          // this.$Modal.fcWarning({
          //   title: '警告',
          //   mask: true,
          //   content: response.message
          // });
          this.clearFile();
        }
        this.$emit('confirmImport');
      },
      urlChange(url) { // 对下载的url地址进行转换，处理特殊字符
        const arr = url.split('/');
        let [last] = [...arr].reverse();
        last = encodeURIComponent(last);
        arr[arr.length - 1] = last;
        return arr.join('/');
      },
      // 上传失败
      handleError(e) {
        console.log(e, 'handleError_11');
        const { tableName } = this.$route.params;
        this.$R3loading.hide(tableName);
        const emg = e;
        let formatJsonEmg = null;
        try {
          formatJsonEmg = JSON.stringify(JSON.parse(emg), null, 4);
        } catch (v) {
          if (typeof emg === 'string') {
            formatJsonEmg = emg.replace(/<br\/>/g, '\r\n');
          }
        }
        window.vm.$Modal.fcError({
          mask: true,
          titleAlign: 'center',
          title: '错误',
          render: h => h('div', {
            style: {
              padding: '10px 20px 0',
              display: 'flex',
              lineHeight: '16px'
            }
          }, [
            
            h('i', {
              props: {
              },
              style: {
                marginRight: '5px',
                display: 'inline-block',
                'font-size': '28px',
                'margin-right': ' 10px',
                'line-height': ' 1',
                padding: ' 10px 0',
                color: 'red'
              },
              class: 'iconfont iconbj_error fcError '
            }),
            h('div', {
              style: `width: 80%;
                  margin: 1px;
                  margin-bottom: -8px;
                  box-sizing: border-box;
                  padding: 5px;
                  resize: none;
                  max-height: 100px;
                  max-width: 300px;
                  overflow: auto;
                  `
            }, formatJsonEmg)
          ])
        });
        this.clearFile();
        this.closeDialog();
      },
      closeDialog() {
        this.modalVisible = false;
        this.fatherMethod();
        if (this.tablename == 'T_OMSALIPAYBILLDETAIL') {
          this.clearFile();
          this.errorMsg = {
            // 错误信息
            errorUrl: '',
            message: '',
            errorList: []
          };
        }
      },
      ToNewAccount() {
        this.closeDialog();
        window.parent.R3.store.commit('global/tabOpen', {
          type: 'V',
          tableName: 'T_OMSBANKINFO',
          tableId: '10706',
          id: 'New',
          dynamicRoutingForCustomizePage: true
        });
      }
    }
  };
</script>
<style lang="less">
.importDialogAddOther {
  .ark-select-single .ark-select-selection {
    height: 32px;
  }
  .ark-form-item {
    margin-bottom: 10px;;
  } 
  .chooedFile {
    color: #2D8cF0;
  }
  .ToNewAccount {
    cursor: pointer;
    color: #2D8cF0;
  }
  .importICon {
    margin: 0;
    text-align: center;
    .icon-span {
      display: inline-block;
      height: 28px;
      width: 28px;
      i {
        color: #09a155;
        font-size: 28px;
      }
    }
  }
  .importForm {
    padding: 0 40px;
  }
  .import-panel {
    padding: 0 40px;
    position: relative;
    .el-upload__tip {
      margin-top: 10px;
      font-size: 12px;
      color: #575757;
      .inputValue{
        border: none;
        border-bottom: 1px solid #b8b8b8;
        text-align: center;
        width: 100px;
      }
      .singleValue{
        margin-left:10px;
      }
    }
    .upload-panel {
      height: 30px;
      // margin-top: 24px;
    }
    .fileName {
      height: 21px;
      line-height: 21px;
      color: #606266;
    }
  }
  .fileInput {
    position: relative;
    left: -67px;
    opacity: 0;
    width: 62px;
  }
  .tip {
    font-size: 12px;
    display: inline-block;
    margin-left: -61px;
    color: #b8b8b8;
  }
  .error-content {
    border-top: solid 1px #bcbcbc;
    text-align: left;
    position: relative;
    font-size: 12px;
    margin-top: 10px;
    .error-message {
      height: auto;
      margin: 10px 0px;
      max-height: 240px;
      position: relative;
      width: 550px;
      .left-icon {
        height: 28px;
        width: 28px;
        position: absolute;
        left: 0;
        top: 0;
        i {
          font-size: 28px;
          color: #e80000;
        }
      }
      .right-content {
        position: relative;
        margin-left: 38px;
        .link {
          line-height: 16px;
          a {
            color: #0f8ee9;
            cursor: pointer;
            display: inline-block;
            padding-top: 6px;
            text-decoration: none;
          }
        }
        .content-message {
          max-height: 220px;
          min-height: 28px;
          overflow: auto;
          p {
            word-break: break-word;
            line-height: 16px;
            margin: 6px 0;
          }
        }
      }
    }
  }
  .ark-modal-body {
    padding: 20px !important;
  }
  .iconios-close {
    color: #999 !important;
  }
  .ark-modal-footer {
    border-top: none !important;
    padding: 0 20px 20px;
    margin: 10px 40px;
  }
  .ark-btn-fcdefault {
    height: 24px !important;
    font-size: 12px !important;
    width: 66px !important;
    padding: 0 !important;
  }
  .ark-modal-footer button > span {
    font-size: 12px;
  }
}
</style>
