<template>
  <div style="width:100%">
    <EMSTableNew
      ref="paymentPlanTable"
      :loadCallback="loadCallback"
      :autoFirst="false"
      :server="server"
      action="QueryPaymentPlans"
      :params="formSearch"
      :pageSizeOpts="pageSizeOpts"
      :columnsFn="columnsFn"
      :changePageFun="changePageFun"
      @on-select="select"
      @on-selection-change="onSelectChnage"
    >
      <Form
        slot="search-bar"
        ref="formSearch"
        :rules="rules"
        :model="formSearch"
        :label-width="120"
      >
        <Row>
          <Col span="6">
          <Form-item
            prop="ouCode"
            label="归属公司"
          >
            <SelectCompany
              ref="selectCompany"
              v-model="formSearch.ouCode"
              query="com"
              filterable
              transfer
              clearable
            ></SelectCompany>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="付款类型">
            <DataSelectV
              v-model="formSearch.paymentType"
              :someValue="[16, 17, 1]"
              :value="formSearch.paymentType"
              code="payType"
              clearable
              transfer
              @loadFinish="loadedPayWay"
            >
            </DataSelectV>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item
            prop="payPlandueDate"
            label="付款计划到期日"
          >
            <Date-picker
              v-model="formSearch.payPlandueDate"
              placement="top-end"
              type="daterange"
              format="yyyy/MM/dd"
              transfer
              clearable
            ></Date-picker>
          </Form-item>
          </Col>

          <Col
            v-show="!showMore"
            span="6"
          >
          <div class="search_btns ivu-form-item">
            <Button
              type="warning"
              class="ems-btn-medium ems-btn-type1"
              style="padding: 0 18px;"
              @click.native="search"
            >
              {{ $t("查询") }}
            </Button>
            <Button
              class="ems-btn-medium ems-btn-type3"
              style="padding: 0 18px;"
              @click.native="reset"
            >
              {{ $t("重置") }}
            </Button>
            <a @click="changeShowMore">{{ $t('查看更多') }}</a>
          </div>
          </Col>

          <Col span="6">
          <Form-item label="供应商名称">
            <Input
              v-model="formSearch.vendorName"
              type="text"
              maxlength="30"
              clearable
            ></Input>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="总账日期">
            <Date-picker
              v-model="formSearch.glDate"
              placement="top-end"
              type="date"
              format="yyyy/MM/dd"
              transfer
            ></Date-picker>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="发票编号">
            <Input
              v-model="formSearch.invoiceClaimNo"
              type="text"
              maxlength="30"
              clearable
            ></Input>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="供应商类型">
            <DataSelect
              v-model="formSearch.vendorType"
              code="vendorType"
              clearable
              transfer
            ></DataSelect>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="币种">
            <DataSelect
              v-model="formSearch.currency"
              code="currency"
              transfer
              clearable
              @loadFinish="currencyLoadFinish"
            ></DataSelect>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="是否全额创建">
            <Select
              v-model="formSearch.isCreateApplyAll"
              filterable
              transfer
              clearable
            >
              <Option
                v-for="item in isCreatedApplyAll"
                :key="item.value"
                :value="item.value"
              >
                {{ item.label }}
              </Option>
            </Select>
          </Form-item>
          </Col>

          <Col span="6">
          <Form-item label="付款方式">
            <DataSelect
              v-model="formSearch.paymentMethod"
              code="PAYMENT_MODE"
              transfer
              clearable
            ></DataSelect>
          </Form-item>
          </Col>

          <Col
            v-show="showMore"
            span="12"
          >
          <div class="search_btns ivu-form-item">
            <Button
              type="warning"
              class="ems-btn-medium ems-btn-type1"
              style="padding: 0 18px;"
              @click.native="search"
            >
              {{ $t("查询") }}
            </Button>
            <Button
              class="ems-btn-medium ems-btn-type3"
              style="padding: 0 18px;"
              @click.native="reset"
            >
              {{ $t("重置") }}
            </Button>
            <a @click="changeShowMore">{{ $t('隐藏条件') }}</a>
          </div>
          </Col>

          <div class="v-summary-tips">
            <span>{{ money }}</span>
          </div>
        </row>
      </Form>
      <div slot="table-bar">
        <Button
          :loading="createdLoad"
          :disabled="selections.length == 0"
          type="warning"
          icon="plus-round"
          @click="createPaymentApply"
        >
          创建付款申请
        </Button>
        <Button
          type="warning"
          icon="plus-round"
          @click="exportData"
        >
          付款申请导出
        </Button>
      </div>
    </EMSTableNew>
  </div>
</template>

<script>
import Server from './server.js';
import util from '@paymentPlatformSrc/tools/util.js';
import miment from 'miment';
import accounting from 'accounting';
import qs from 'qs';
import {
  SelectCompany
} from '@paymentPlatformComps/index.js';
const server = new Server();
let vm;
export default {
  components: {
    SelectCompany
  },
  directives: {},
  data() {
    const self = this;
    return {
      pageSizeOpts: [10, 20, 50, 100, 300],
      createdLoad: false,
      money: '',
      // urlParams: urlParams,
      server: server,
      companys: [],
      payList: [],
      paymentTypes: [],
      queryTypes: [],
      vendorTypes: [],
      currency: [],
      paymentModes: [],
      createdPayRequestList: [
        { label: '是', value: 'Y' },
        { label: '否', value: 'N' }
      ],
      isCreatedApplyAll: [
        { label: '未创建/部分创建', value: 'NOTALL' },
        { label: '已全额创建', value: 'ALL' }
      ],
      createdPayRequestMap: { Y: '是', N: '否' },
      selections: [],
      payTypeList: [],
      queryTypeList: [],
      vendorTypeList: [],
      currencyList: [],
      currencyMap: {},
      requestPaymentTypeNameList: [],
      formSearch: {
        // applyType: "2",
        ouCode: '',
        paymentType: '',
        payPlandueDate: '',
        dueStartDate: '',
        dueEndDate: '',
        vendorName: '',
        queryType: '',
        glDate: '',
        invoiceClaimNo: '',
        vendorType: '',
        invoiceDateFrom: '',
        invoiceDateTo: '',
        projectCode: '',
        projectName: '',
        currency: '',
        createdPayRequest: '',
        paymentMethod: '',
        categoryCode: 'SN9000092',
        contractNo: '',
        // sourceSystem: urlParams.categoryCode == "8003001" ? "RESOLINK" : "ECP",
        // 报账系统是 CLAIM      其他的还不知道
        sourceSystem: 'CLAIM',
        // 2是从应付获取  1总账获取  这个从url上获取
        applyType: '1',
        isCreateApplyAll: 'NOTALL',
        paymentTypeList: []
      },
      rules: {
        ouCode: [
          {
            required: true,
            message: '请选择归属公司',
            trigger: 'change'
          }
        ],
        payPlandueDate: [
          {
            required: true,
            validator: function(rule, value, callback) {
              var startDate = self.formSearch.payPlandueDate[0];
              var endDate = self.formSearch.payPlandueDate[1];
              if (startDate == '' || endDate == '') {
                callback(new Error('请选择开始日期和结束日期'));
                return;
              }
              callback();
            },
            message: '请选择付款计划到期日',
            trigger: 'change'
          }
        ]
      },
      isOneInvoiceNo: '',
      showMore: false
    };
  },
  computed: {},
  watch: {},
  beforeCreate() {
  },
  created: function() {
    console.log('22222222222');
    // 去除url中的crctoken
    // crctoken在中间
    vm = this;
    if (location.hash.match(/crctoken=(\S*)&source/)) {
      const substr = location.hash.match(/crctoken=(\S*)&source/)[0];
      location.hash = location.hash.replace(substr, 'source');
    } else {
      // crctoken在尾部
      location.hash = location.hash.split('&crctoken')[0];
    };
    // vm.queryValuePayType();
    vm.queryValueSetByCode();
  },
  mounted() {
    // document.body.className = 'singlePage-wrapper';
    document.title = '费用类账龄付款';
  },
  methods: {
    changeShowMore() {
      this.showMore = !this.showMore;
      this.$refs.paymentPlanTable.showMore();
    },
    loadedPayWay(val) {
      vm.payList = val.valueList;
    },
    queryValuePayType() {
      // payType
      vm.server.queryValueSetByCode({ code: 'payWay' }).then(response => {
        // if (response) {
        //   vm.payTypeList = response;
        //   vm.server.queryCategoryCfgList({
        //     categoryCode: urlParams.categoryCode
        //   }).then(res => {
        //     let list = []; const dataList = vm.payTypeList;
        //     if (res) {
        //       for (let k = 0; k < res.length; k++) {
        //         if (res[k].categoryCfgCode == 'PAY_TYPE_LIST') {
        //           list = res[k].categoryCfgValue.split(',');
        //           vm.formSearch.paymentTypeList = res[k].categoryCfgValue.split(',');
        //           for (let i = 0; i < dataList.length; i++) {
        //             for (let n = 0; n < list.length; n++) {
        //               if (dataList[i].value == list[n]) {
        //                 vm.payList.push(dataList[i]);
        //               }
        //             }
        //           }
        //         }
        //         if (res[k].categoryCfgCode == 'ONE_INVOICE_APPLY_LIMIT') {
        //           vm.isOneInvoiceNo = res[k].categoryCfgValue;
        //         }
        //         if (res[k].categoryCfgCode == 'DEFAULT_DUE_DATE') {
        //           this.formSearch.payPlandueDate = this._dealDate(res[k].categoryCfgValue);
        //         }
        //       }
        //     } else {
        //       this.$Message.error(res.msg || '查询大类配置失败');
        //     }
        //   });
        // }
      }).catch(err => {
        this.$Message.error(err.msg);
      });
    },
    queryValueSetByCode() {
      vm.server.queryValueSetByCode({ code: 'PAYMENT_MODE' }).then(response => {
        vm.requestPaymentTypeNameList = response;
      }).catch(err => {
        this.$Message.error(err.msg);
      });
    },
    currencyLoadFinish(data) {
      this.currencyMap = data.valueMap;
    },
    loadCallback(data) {
      this.selections = [];
      this.money = '';
    },
    onSelectChnage(d) {
      this.selections = d;

      if (d.length == 0) {
        this.money = '';
        return;
      }
      // 过滤掉相同发票编号的数据(同一个发票编号的只能计算一次发票金额，到期金额是累加)

      const invoceData = [];
      let invoceFlag = true;
      for (let i = 0; i < d.length; i++) {
        invoceFlag = true;
        for (let j = 0; j < invoceData.length; j++) {
          if (d[i].invoiceNo == invoceData[j].invoiceNo) {
            invoceFlag = false;
            break;
          }
        }
        if (invoceFlag) {
          invoceData.push(d[i]);
        }
      }

      let m1 = 0;
      let m2 = 0;

      d.forEach(item => {
        m1 = m1 + item.dueDateBalance;
      });
      invoceData.forEach(item => {
        m2 = m2 + item.invoiceAmount;
      });
      this.money = `到期金额：${accounting.formatNumber(
        m1,
        2
      )} 发票金额：${accounting.formatNumber(m2, 2)}`;
    },
    handleSelect(obj) {
      this.formSearch.projectCode = obj.projectCode || '';
      this.formSearch.projectName = obj.projectName || '';
    },
    cleanProject() {
      this.formSearch.projectCode = '';
    },
    columnsFn() {
      return [
        {
          type: 'selection',
          width: 60,
          align: 'center',
          fixed: 'left'
        },
        {
          title: '供应商编号',
          key: 'vendorCode',
          align: 'left',
          resizable: true,
          width: 200
        },
        {
          title: '供应商名称',
          key: 'vendorName',
          width: 250,
          resizable: true,
          align: 'left'
        },
        {
          title: '供应商地点',
          key: 'vendorSite',
          width: 200,
          resizable: true,
          align: 'left'
        },
        {
          title: '发票编号',
          key: 'invoiceClaimNo',
          align: 'left',
          width: 180,
          resizable: true,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: params.row.invoiceNo
                }
              },
              params.row.invoiceNo
            );
          }
        },
        {
          title: '到期日',
          key: 'dueToDate',
          align: 'left',
          width: 180,
          resizable: true,
          render: (h, params) => {
            const val = params.row.dueToDate &&
                      new Date(params.row.dueToDate).toLocaleDateString().replace(/\//g, '-');
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis'
                }
              },
              val
            );
          }
        },
        {
          title: '到期金额',
          width: 100,
          resizable: true,
          key: 'dueDateBalance',
          align: 'left',
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: accounting.formatNumber(params.row.dueDateBalance, 2)
                }
              },
              accounting.formatNumber(params.row.dueDateBalance, 2)
            );
          }
        },
        {
          title: '发票摘要',
          key: 'summary',
          align: 'left',
          resizable: true,
          width: 160
        },
        {
          title: '发票金额',
          key: 'invoiceAmount',
          align: 'left',
          width: 160,
          resizable: true,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: accounting.formatNumber(params.row.invoiceAmount, 2)
                }
              },
              accounting.formatNumber(params.row.invoiceAmount, 2)
            );
          }
        },
        {
          title: '总账日期',
          key: 'glDate',
          align: 'left',
          width: 160,
          resizable: true,
          render: (h, params) => {
            const val = params.row.glDate &&
                      new Date(params.row.glDate).toLocaleDateString().replace(/\//g, '-');
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis'
                }
              },
              val
            );
          }
        },
        {
          title: '付款方式',
          key: 'paymentMethod',
          align: 'left',
          width: 100,
          resizable: true,
          render: (h, params) => {
            const val = params.row.paymentMethod;
            const list = vm.requestPaymentTypeNameList || [];
            let text = '';
            list.forEach(function(item) {
              if (item.value == val) {
                text = item.label;
                return false;
              }
            });
            return h('div', {}, text);
          }
        },
        {
          title: '收款账户',
          key: 'vendorAccountNo',
          align: 'left',
          width: 100,
          resizable: true,
          render: (h, params) => {
            return h(
              'span',
              {
                attrs: {
                  title: params.row.vendorAccountNo
                }
              },
              params.row.vendorAccountNo
            );
          }
        },
        {
          title: '币种',
          key: 'paymentCurrency',
          align: 'left',
          width: 100,
          resizable: true,
          render: (h, params) => {
            return h('div', {}, this.currencyMap[params.row.paymentCurrency]);
          }
        },
        {
          title: '是否申请',
          key: 'createdPayRequest',
          align: 'left',
          width: 100,
          resizable: true,
          render: (h, params) => {
            return h(
              'div',
              {},
              this.createdPayRequestMap[params.row.createdPayRequest]
            );
          }
        },
        {
          title: '申请人',
          key: 'applyEmpName',
          align: 'left',
          resizable: true,
          width: 100
        },
        {
          title: '付款申请单号',
          key: 'claimNo',
          align: 'left',
          width: 180,
          resizable: true,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: params.row.claimNo
                }
              },
              params.row.claimNo
            );
          }
        }
      ];
    },

    // 搜索
    search(page = 1) {
      console.log('9999999 : ', this.formSearch.payPlandueDate);
      this.$refs.formSearch.validate(valid => {
        if (valid) {
          //     // payPlandueDate
          //     this.formSearch.dueStartDate =
          //     this.formSearch.payPlandueDate[0] == '' ? '' : miment(this.formSearch.payPlandueDate[0]).format('YYYY-MM-DD');
          this.formSearch.paymentTypeList = this.payList.map(v => { return v.value; });
          this.formSearch.dueEndDate = this.formSearch.payPlandueDate[1] ? miment(this.formSearch.payPlandueDate[1]).format('YYYY-MM-DD') : '';
          this.formSearch.dueStartDate = this.formSearch.payPlandueDate[0] ? miment(this.formSearch.payPlandueDate[0]).format('YYYY-MM-DD') : '';
          this.formSearch.glDate = this.formSearch.glDate ? miment(this.formSearch.glDate).format('YYYY-MM-DD') : '';
          this.$refs.paymentPlanTable.load(this.formSearch);
          //     this.formSearch.payPlandueDate = [this.formSearch.dueStartDate, this.formSearch.dueEndDate];
          //     // this.formSearch.glDateFrom = this.formSearch.glDate[0]? miment(this.formSearch.glDate[0]).format("YYYY-MM-DD"): null;
          //     // this.formSearch.glDateTo = this.formSearch.glDate[1]? miment(this.formSearch.glDate[1]).format("YYYY-MM-DD"): null;
          //     this.formSearch.glDate = this.formSearch.glDate ? miment(this.formSearch.glDate).format('YYYY-MM-DD') : '';

          //     // 这个记得删除掉
          //     // this.formSearch.ouCode = "XLYY0";
          //     // 对paymentTypeList and paymentType进行整理
          //     // 根据paymentType来进行判断
          //     if (!this.formSearch.paymentType && this.formSearch.paymentTypeList.length !== 0) {
          //       this.formSearch.paymentType = this.formSearch.paymentTypeList + '';
          //     }

          //     this.$refs.paymentPlanTable.load(this.formSearch, page, function(
          //       arr
          //     ) {
          //       arr.forEach(item => {
          //         if (item.createdPayRequest == 'Y') {
          //           item._disabled = true;
          //         }
          //       });
          //     });
        }
      });
    },
    changePageFun(page) {
      this.$refs.paymentPlanTable.tableData.forEach(item => {
        if (item.createdPayRequest == 'Y') {
          item._disabled = true;
        }
      });
    },
    // 重置
    reset() {
      this.$refs.formSearch.resetFields();
      Object.keys(this.formSearch).map(key => {
        if (key != 'sourceSystem' && key != 'isCreateApplyAll') {
          this.formSearch[key] = '';
        }
      });
      this.formSearch.paymentTypeList = [];
      this.formSearch.payPlandueDate = ['', ''];
      // this.payList = [];
      this.formSearch.applyType = '1';
      this.queryValuePayType();
    },
    /**
     * changanmin1@crc.com.hk
     * 多项选择时
        1.币种相同
        2.对公或对私 必须是同一种
        3.根据同一供应商vendorName 分组，每一组的申请累加金额大于等于0 方可发起申请
        4.是否申请为否
      单项
        申请金额 需 大于等于0
     */
    validateSelection() {
      const selections = this.selections;
      if (selections && selections.length > 1) {
        // 多项
        const temp_selection = selections[0];
        const bool_currency = selections.some(item => {
          return item.paymentCurrency !== temp_selection.paymentCurrency;
        }); // 币种
        if (bool_currency) {
          this.$Message.warning('请勾选相同【币种】的行！');
          return true;
        }
        const bool_vendorType = selections.some(item => {
          return item.vendorType !== temp_selection.vendorType;
        }); // 对公对私
        if (bool_vendorType) {
          this.$Message.warning('请勾选相同【对公/对私】的行！');
          return true;
        }
        const bool_is = selections.some(item => {
          console.log(item);
          return item.createdPayRequest !== 'N';
        });
        if (bool_is) {
          this.$Message.warning('请勾选未发起的付款申请！');
          return true;
        }
        // let bool_payRequestOuCode = selections.some(item => {return item.payRequestOuCode !== temp_selection.payRequestOuCode});//同一归属公司
        // if(bool_payRequestOuCode){
        //    this.$Message.warning("请勾选相同【归属公司】的行！");
        // }
        const temp_vendorCode = new Map();
        selections.forEach(element => {
          const vendor = temp_vendorCode.get(element.vendorCode) || {
            dueDateBalance: 0
          };
          temp_vendorCode.set(element.vendorCode, {
            dueDateBalance: vendor.dueDateBalance + +element.dueDateBalance,
            vendorName: element.vendorName
          });
        });
        for (const [key, value] of temp_vendorCode) {
          if (value.dueDateBalance < 0) {
            this.$Message.warning(
              `${value.vendorName}的总到期金额为负数，该付款申请不可进行创建`
            );
            return true;
          }
        }
      } else if (selections && selections.length === 1) {
        // 单项
        const item = selections[0];
        const bool_applyAmount = +item.dueDateBalance < 0;
        if (bool_applyAmount) {
          this.$Message.warning(
            '您选择的项到期金额为负数，该付款申请不可进行创建'
          );
          return true;
        }
      }
      return false;
    },
    // 导出
    async exportData() {
      // 返回结果
      const params = {
        page: { currentPage: 1, pageSize: 1000, recordCount: 1 },
        params: this.formSearch,
        sortDTO: { fieldName: '', orderBy: '' }
      };
      this.server.exportResult(params).then(res => {
        if (res.statusCode === '-1') {
          this.$Message.error('导出失败');
        } else {
          const date = new Date();
          const ExcelName = '应付付款计划' + miment(date).format('YYYYMMDDhhmmss');
          this.exportFile(ExcelName, res);
        }
      });
    },
    exportFile(fileNameStr, res) {
      if (res.statusCode === '-1') {
        this.$Message.error(res.msg);
      } else {
        const blob = new Blob([res.data]);
        const fileName = `${fileNameStr}.xls`;
        if ('msSaveOrOpenBlob' in navigator) {
          window.navigator.msSaveOrOpenBlob(blob, fileName);
        } else {
          const elink = document.createElement('a');
          elink.download = fileName;
          elink.style.display = 'none';
          elink.href = URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        }
      }
    },
    createPaymentApply() {
      if (this.selections.length == 0) {
        return;
      }
      if (this.validateSelection()) {
        return;
      }
      // 发起付款申请 前校验选择项
      this.createdLoad = true; //
      const self = this;
      const selectCompanyValue = this.$refs.selectCompany.value;
      let selectCompany = {};
      this.$refs.selectCompany.dataList.forEach(function(item) {
        if (selectCompanyValue == item.value) {
          selectCompany = item;
        }
      });
      const postData = {
        isOneInvoiceNo: this.isOneInvoiceNo,
        ouCode: selectCompany.value,
        ouName: selectCompany.label,
        categoryCode: 'SN9000092',
        categoryName: '非采购类账龄付款',
        // rootCategoryCode: parseInt(urlParams.rootCategoryCode) || 1,
        // rootCategoryName: urlParams.rootCategoryName || "",
        lines: [],
        applyType: '1',
        tpCode: 'payment-plan-gl',
        sourceSystem: self.formSearch.sourceSystem,
        buCode: this.selections[0].buCode
      };

      const o = this.selections[0];
      if (o) {
        o.dueToDate = o.dueToDate.replace(/\s+/g, ' ');
        o.glDate = o.glDate.replace(/\s+/g, ' ');
        o.invoiceDate = o.invoiceDate.replace(/\s+/g, ' ');
      }

      // receiVendorAccountNo: null
      // receiVendorCode: null
      // receiVendorName: null
      // receiVendorSite: null

      const updateVendors = this.selections.map((val) => {
        val.receiVendorAccountNo = val.vendorAccountNo;
        val.receiVendorCode = val.vendorCode;
        val.receiVendorName = val.vendorName;
        val.receiVendorSite = val.vendorSite;
        return val;
      });

      // postData.lines = this.selections;
      postData.lines = updateVendors;
      this.server.addPayApply(postData).then(response => {
        console.log('response', response);
        self.createdLoad = false;
        if (response.data.code == 0) {
          self.$Message.error(response.data.msg || '创建付款申请失败!');
          return;
        } else if (response.data.code == 1) {
          self.$Message.success('创建付款申请成功');
          self.search();
        }
        util.startProcess(response.data.obj);
        // util.openByClaimIdAndClaimNo(response.data.obj);
      }).catch(error => {
        console.log(error);
        self.createdLoad = false;
      });
    },
    _dealDate(val) {
      if (!val) {
        return '';
      }
      function deal(curTime, calNum, val) {
        return new Date(curTime + val * calNum).toLocaleDateString();
      }
      const deal_arr = [];
      const dateNum = 86400000; // 一天的时间值
      const dateNow = +new Date();
      const nowDate = new Date().toLocaleDateString();
      const dls = val.split('-');
      // val中含有T字样则按当前日期来计算
      // 否则分割返回
      if (!~val.indexOf('T')) {
        deal_arr[0] = dls[0].trim();
        deal_arr[1] = dls[1].trim();
      } else {
        if (~dls[0].indexOf('+')) {
          deal_arr[0] = deal(dateNow, dateNum, parseFloat(dls[0].split('+')[1]));
        }
        if (~dls[0].indexOf('-')) {
          deal_arr[0] = deal(dateNow, dateNum, -parseFloat(dls[0].split('-')[1]));
        }
        if (~dls[1].indexOf('+')) {
          deal_arr[1] = deal(dateNow, dateNum, parseFloat(dls[1].split('+')[1]));
        }
        if (~dls[1].indexOf('-')) {
          deal_arr[1] = deal(dateNow, dateNum, -parseFloat(dls[1].split('-')[1]));
        }
      }
      return deal_arr;
    },
    _baseEncrypt(data) {
      // base64加密所有查询字段
      const that = this;

      const encrypts = function(data) {
        const forms = {};
        for (const key in data) {
          const o = data[key];
          if (typeof o === 'string' || typeof o === 'undefined') {
            forms[key] = that.$base64.encode(o) || '';
          }
          if (o instanceof Array) {
            const isArr = function(arrs) {
              const _arr = [];
              for (let i = 0; i < arrs.length; i++) {
                const s = arrs[i]; const sm = {};
                if (s instanceof Object) {
                  for (const k in s) {
                    sm[k] = that.$base64.encode(s[k]);
                  }
                  _arr.push(sm);
                }
              }
              return _arr;
            };
            forms[key] = isArr(o);
          }
        }
        return forms;
      };
      return encrypts(data);
    },
    select() {}
  }
};
</script>
<style lang="less" scoped>
/deep/ .ivu-form-item-required {
  .ivu-form-item-label {
    height:32px;
  }
}
/deep/ .ivu-form-item {
  margin-bottom: 18px;
}
</style>
