<template>
  <div class="sidelip-box">
    <Form
      ref="searchForm"
      slot="search-bar"
      :model="searchForm"
      :rules="rules"
      :label-width="120"
    >
      <Row
        class="code-row-bg"
      >
        <Col span="6">
        <Form-item
          prop="ouCode"
          label="核算机构"
        >
          <SelectCompany
            v-model="searchForm.ouCode"
            :filterable="true"
            size="small"
            style="width:200px"
            :disabled="canSelCompany"
            :flag="true"
            clearable
            @loadFinish="loadedSelectCompany"
          />
        </Form-item>
        </Col>

        <Col span="6">
        <Form-item
          prop="isBillEnable"
          label="已启用票据平台"
        >
          <!-- <DataSelect
            ref="yesNoSelect"
            v-model="searchForm.isBillEnable"
            size="small"
            code="YES_NO"
            style="width:200px"
            :clearable="true"
            @loadFinish="loadedVsYesNo"
          >
          </DataSelect> -->

          <Select
            v-model="searchForm.isBillEnable"
            size="small"
            code="YES_NO"
            style="width:200px"
            :clearable="true"
          >
            <Option value="1">
              是
            </Option>
            <Option value="0">
              否
            </Option>
          </Select>
        </Form-item>
        </Col>

        <Col span="6">
        <Form-item
          prop="manuallyCreator"
          label="付款准备操作用户"
        >
          <SelectEmployee
            :selectedItems="searchForm.manuallyCreator"
            :value="showEmployeeName(searchForm.manuallyCreator)"
            style="width:200px"
            @handleSelect="selectEmployee"
          />
        </Form-item>
        </Col>

        <Col span="6">
        <Form-item
          prop="isCapitalPlanEnable"
          label="启用资金计划预占"
        >
          <!-- <DataSelect
            v-model="searchForm.isCapitalPlanEnable"
            size="small"
            code="YES_NO"
            style="width:200px"
            :clearable="true"
          >
          </DataSelect> -->

          <Select
            v-model="searchForm.isCapitalPlanEnable"
            size="small"
            code="YES_NO"
            style="width:200px"
            :clearable="true"
          >
            <Option value="1">
              是
            </Option>
            <Option value="0">
              否
            </Option>
          </Select>
        </Form-item>
        </Col>
      </Row>

      <Row
        class="code-row-bg-2"
      >
        <Col span="6">
        <Form-item
          prop="localCashierList"
          label="本地出纳"
        >
          <SelectEmployee
            :selectedItems="searchForm.localCashierList"
            :value="showEmployeeName(searchForm.localCashierList)"
            style="width:200px"
            @handleSelect="selectLocalCashier"
          />
        </Form-item>
        </Col>

        <Col span="6">
        <Form-item
          prop="fundManager"
          label="资金负责人"
        >
          <SelectEmployee
            :selectedItems="searchForm.fundManager"
            :value="showEmployeeName(searchForm.fundManager)"
            style="width:200px"
            title="选择默认审核人"
            @handleSelect="selectLocalCapital"
          />
        </Form-item>
        </Col>

        <Col span="6">
        <Form-item
          prop="userList"
          label="查询用户"
        >
          <SelectEmployee
            :selectedItems="searchForm.userList"
            :value="showEmployeeName(searchForm.userList)"
            style="width:200px"
            @handleSelect="selectUser"
          />
        </Form-item>
        </Col>

        <Col span="6">
        <Form-item
          prop="accountSourceServiceCode"
          label="来源服务代码"
        >
          <Input
            v-model="searchForm.accountSourceServiceCode"
            style="width:200px"
            type="text"
            maxlength="30"
            clearable
          ></Input>
        </Form-item>
        </Col>
      </Row>

      <span class="dashed-hr"></span>

      <div class="card-box">
        <common-title titleText="自动创建付款准备" />
        <div>
          <Table
            ref="paymentTable"
            :columns="paymentTable.columns"
            :data="paymentTable.data"
            border
          ></Table>
        </div>
      </div>

      <span class="dashed-hr"></span>

      <div class="card-box">
        <common-title titleText="准备明细操作用户" />
        <div>
          <Table
            ref="prepareUser"
            :columns="prepareUser.columns"
            :data="prepareUser.data"
            border
          ></Table>
        </div>
      </div>
    </Form>
    <DataSelect
      v-show="false"
      code="BUSINESS_TYPE"
      @loadFinish="loadedBusinessType"
    />
  </div>
</template>
<script>
import { SelectCompany, commonTitle } from '@paymentPlatformComps/index.js';
import Server from '../server';
const server = new Server();

export default {
  name: 'AddOrEditPaymentPermission',
  components: {
    SelectCompany,
    'common-title': commonTitle
  },
  directives: {},
  props: {
    // 选中的行对象，放在一个数组中
    companys: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    const vm = this;
    const bindPaymentTableData = (index, prop, val) => {
      vm.paymentTable.data[index][prop] = val;
    };
    const bindPrepareTableData = (index, prop, val) => {
      vm.prepareUser.data[index][prop] = val;
    };
    const bindAuditData = (index, prop, val) => {
      vm.paymentTable.data[index][prop] = val;
      vm.paymentTable.data[index].defaultAuditUserCode = val[0].code;
      vm.paymentTable.data[index].defaultAuditUserName = val[0].title;
    };
    // 渲染下拉选择
    const renderSelect = (h, params, list, prop) => {
      const options = (() => {
        const options = [];
        list.map(item => {
          const option = h(
            'i-option',
            {
              props: {
                value: item.value
              }
            },
            item.label
          );
          options.push(option);
        });
        return options;
      })();

      return h(
        'i-select',
        {
          style: {
            width: '80px'
          },
          props: {
            // re-render 后确保有已选择的值
            value: vm.paymentTable.data[params.index][prop]
          },
          on: {
            // 这里要手动双向绑定
            'on-change': val => {
              bindPaymentTableData(params.index, prop, val);
              console.log(vm.paymentTable.data);
            }
          }
        },
        options
      );
    };

    // 渲染表头
    const renderHeader = (h, title) => {
      return h('div', [
        h(
          'span',
          {
            style: {
              color: 'red'
            }
          },
          '*'
        ),
        h('span', title)
      ]);
    };

    const renderDataSelect = (code, prop, params) => {
      return (
        <DataSelect
          code={code}
          size="default"
          clearable={false}
          style="width:100%"
          value={vm.paymentTable.data[params.index][prop]}
          on-input={val => {
            vm.paymentTable.data[params.index][prop] = val;
          }}
        />
      );
    };
    return {
      searchForm: {
        ouCode: '', // 核算机构
        isBillEnable: '', // 已启用票据平台
        isCapitalPlanEnable: '', // 是否启用资金计划预占
        manuallyCreator: '', // 付款准备手工操作用户
        fundManager: '', // 资金负责人
        localCashierList: '', // 本地出纳
        userList: '', // 查询用户
        accountSourceServiceCode: ''
      },
      rules: {
        ouCode: [
          {
            required: true,
            message: '请选择核算机构'
          }
        ],
        manuallyCreator: [
          {
            required: true,
            message: '请选择付款准备手工操作用户'
          }
        ],
        fundManager: [
          {
            required: true,
            message: '请选择付款准备手工操作用户'
          }
        ],
        localCashierList: [
          {
            required: true,
            message: '请选择本地出纳'
          }
        ]
      },
      paymentTable: {
        // 自动创建付款准备 table 配置
        columns: [
          {
            renderHeader: h => renderHeader(h, '业务类型'),
            key: 'businessType',
            align: 'left',
            width: 130,
            render: (h, params) => {
              return (
                <DataSelect
                  code="BUSINESS_TYPE"
                  size="default"
                  clearable={false}
                  value={vm.paymentTable.data[params.index].businessType}
                  on-input={vm.createTableFormByBizType}
                />
              );
            }
          },
          {
            renderHeader: h => renderHeader(h, '是否自动审核'),
            key: 'isAutoAudit',
            align: 'left',
            width: 120,
            render: (h, params) => {
              return h(
                'Select',
                {
                  props: {
                    value: params.row.isAutoAudit || '1'
                  },
                  attrs: {
                    transfer: true
                  },
                  on: {
                    'on-change': function(val) {
                      vm.paymentTable.data[params.index].isAutoAudit = val;
                    }
                  }
                },
                [
                  h(
                    'Option',
                    {
                      props: {
                        value: '1'
                      }
                    },
                    '是'
                  ),
                  h(
                    'Option',
                    {
                      props: {
                        value: '0'
                      }
                    },
                    '否'
                  )
                ]
              );
            }
          },
          {
            renderHeader: h => renderHeader(h, '默认审核人'),
            key: 'auditor',
            align: 'left',
            width: 220,
            render: (h, params) => {
              return (
                <SelectEmployee
                  isMultiple={false}
                  isShowCheckbox={false}
                  selectedItems = {vm.paymentTable.data[params.index].auditor}
                  on-handleSelect={val => {
                    bindAuditData(params.index, 'auditor', val);
                  }}
                  value={vm.showEmployeeName(
                    vm.paymentTable.data[params.index].auditor
                  )}
                />
              );
            }
          },
          {
            renderHeader: h => renderHeader(h, '是否自动创建'),
            key: 'isAutoCreatePayment',
            align: 'left',
            width: 130,
            render: (h, params) => {
              return h(
                'Select',
                {
                  props: {
                    value: params.row.isAutoCreatePayment
                  },
                  attrs: {
                    transfer: true
                  },
                  on: {
                    'on-change': function(val) {
                      vm.paymentTable.data[params.index].isAutoCreatePayment = val;
                    }
                  }
                },
                [
                  h(
                    'Option',
                    {
                      props: {
                        value: '1'
                      }
                    },
                    '是'
                  ),
                  h(
                    'Option',
                    {
                      props: {
                        value: '0'
                      }
                    },
                    '否'
                  )
                ]
              );
            }
          },
          {
            renderHeader: h => renderHeader(h, '默认创建用户'),
            key: 'auToUser',
            align: 'left',
            width: 200,
            render: (h, params) => {
              return (
                <SelectEmployee
                  selectedItems = {vm.paymentTable.data[params.index].auToUser}
                  on-handleSelect={val => {
                    bindPaymentTableData(params.index, 'auToUser', val);
                  }}
                  value={vm.showEmployeeName(
                    vm.paymentTable.data[params.index].auToUser
                  )}
                />
              );
            }
          },

          {
            renderHeader: h => renderHeader(h, '转账'),
            key: 'tssPayStatus',
            align: 'left',
            width: 150,
            render: (h, params) => {
              return renderDataSelect('TRANSFER_STATUS', 'tssPayStatus', params);
            }
          },
          {
            renderHeader: h => renderHeader(h, '票据'),
            key: 'billPayStatus',
            align: 'left',
            width: 120,
            render: (h, params) => {
              return renderDataSelect('INVOICE_STATUS', 'billPayStatus', params);
            }
          },
          {
            renderHeader: h => renderHeader(h, '其他-需付款'),
            key: 'otherPayStatus',
            align: 'left',
            width: 180,
            render: (h, params) => {
              return renderDataSelect('PAYMENT_CONFIG_OTHER_PAY_STATUS', 'otherPayStatus', params);
            }
          },
          {
            renderHeader: h => renderHeader(h, '其他-无需付款'),
            key: 'otherStatus',
            align: 'left',
            width: 180,
            render: (h, params) => {
              return renderDataSelect('PAYMENT_CONFIG_OTHER_STATUS', 'otherStatus', params);
            }
          },
          {
            renderHeader: h => renderHeader(h, '付款批数上限'),
            key: 'payBatchMax',
            align: 'left',
            width: 150,
            render: (h, params) => {
              return h('InputNumber', {
                style: {
                  width: '120px'
                },
                props: {
                  min: 0,
                  max: 99999999,
                  value: vm.paymentTable.data[params.index].payBatchMax
                },
                attrs: {
                  placeholder: '请填写数字'
                },
                on: {
                  'on-change': value => {
                    bindPaymentTableData(params.index, 'payBatchMax', value);
                  }
                }
              });
            }
          }
        ],
        data: []
      },
      yesNoData: [], // 是、否 值集
      businessTypeData: [], // 业务类型 值集
      selectCompanyData: [], // 结算机构 列表对象
      prepareUser: {
        data: [],
        columns: [
          {
            renderHeader: h => renderHeader(h, '业务类型'),
            key: 'payWayName',
            align: 'left',
            width: 110
          },
          {
            renderHeader: h => renderHeader(h, '付款准备手工操作用户'),
            key: 'userDtoList',
            align: 'left',
            render: (h, params) => {
              return (
                <SelectEmployee
                  style="width: 430px;"
                  selectedItems = {vm.prepareUser.data[params.index].userDtoList}
                  on-handleSelect={val => {
                    bindPrepareTableData(params.index, 'userDtoList', val);
                  }}
                  value={vm.showEmployeeName(
                    vm.prepareUser.data[params.index].userDtoList
                  )}
                />
              );
            }
          }
        ]
      }
    };
  },
  computed: {
    companyCodes() {
      const codes = [];
      this.companys.map(item => {
        codes.push(item.ouCode);
      });
      return codes;
    },
    companyNames() {
      const names = [];
      this.companys.map(item => {
        names.push(item.ouName);
      });
      return names;
    },
    companysCodeNameMap() {
      const theMap = {};
      this.companys.map(item => {
        theMap[item.ouCode] = item.ouCode;
      });
      return theMap;
    },
    // 选择核算机构 批量修改时true，其他false
    canSelCompany() {
      if (this.companyCodes.length > 1) {
        return true;
      } else {
        return false;
      }
    }
  },
  watch: {
    'searchForm.ouCode'(newVal, oldVal) {
      const self = this;
      // console.log('self.searchForm.ouCode', self.searchForm.ouCode);
      if (typeof self.searchForm.ouCode === 'string') { // 单个修改支持选择核算机构并加载对应数据
        server.getSettingByOuCode({ ouCode: newVal })
          .then(response => {
            const company = response.data;
            if (response.statusCode === '-1') {
              return this.$Message.error(response.msg);
            }
            Object.keys(self.searchForm).map(key => {
              // if(key == "localCashierList"){
              //   this.searchForm[key]=[];
              //   company[key].map((item)=>{
              //     this.searchForm[key].push(item.split("-")[1]);
              //   })
              // }else{
              self.searchForm[key] = company[key];
              // }
              self.searchForm.isBillEnable = company.isBillEnable;
              self.searchForm.isCapitalPlanEnable = company.isCapitalPlanEnable;
              self.searchForm.accountSourceServiceCode = company.accountSourceServiceCode;
              self.searchForm.manuallyCreator = [];
              if (company.manualChnNameList) {
                company.manualChnNameList.map((title, index) => { // 还原 付款准备手工操作用户 数据对象
                  self.searchForm.manuallyCreator.push({
                    title,
                    id: company.manualEmpIdList[index],
                    code: company.manualUserCodeList[index]
                  });
                });
              }

              self.searchForm.fundManager = [];
              if (company.fundManagerChnNameList) {
                company.fundManagerChnNameList.map((title, index) => { // 还原资金负责人  数据对象
                  self.searchForm.fundManager.push({
                    title,
                    id: company.fundManagerEmpIdList[index],
                    code: company.fundManagerUserCodeList[index]
                  });
                });
              }
              self.searchForm.localCashierList = [];
              if (company.localCashierChnNameList) {
                company.localCashierChnNameList.map((title, index) => { // 还原 本地出纳 数据对象
                  self.searchForm.localCashierList.push({
                    title,
                    id: company.localCashierEmpIdList[index],
                    code: company.localCashierUserCodeList[index]
                  });
                });
              }
              self.searchForm.userList = [];
              if (company.readOnlyUserChnNames) {
                company.readOnlyUserChnNames.map((title, index) => { // 还原 查询用户 数据对象
                  self.searchForm.userList.push({
                    title,
                    id: company.readOnlyUserEmpIds[index],
                    code: company.readOnlyUserUserCodes[index]
                  });
                });
              }
              if (company.paymentPermissionConfigRespList) {
                const configs = company.paymentPermissionConfigRespList; // 还原 默认创建用户 数据对象
                // console.log('company.paymentPermissionConfigRespList', company.paymentPermissionConfigRespList);
                // console.log('configs', configs);
                configs.map((citem, cindex) => {
                  citem.auToUser = [];
                  citem.auToChnNameList && citem.auToChnNameList.map((title, index) => {
                    citem.auToUser.push({
                      title,
                      id: citem.auToEmpIdList[index],
                      code: citem.auToUserCodeList[index]
                    });
                  });
                  // 审核人
                  citem.auditor = [];
                  citem.auditor.push({
                    title: citem.defaultAuditUserName,
                    code: citem.defaultAuditUserCode
                  });
                  // citem.isAutoAudit = citem.isAutoAudit;
                  // citem.defaultAuditUserName = citem.defaultAuditUserName;
                  // citem.defaultAuditUserCode = citem.defaultAuditUserCode;
                  // citem.isAutoCreatePayment = citem.isAutoCreatePayment;
                });
                this.paymentTable.data = configs; // 数据填充到 自动创建付款准备 表格里
                // this.$set(this.paymentTable, 'data', configs);
                console.log('this.paymentTable', this.paymentTable);
              }
              this.prepareUser.data = [];
              const preparationUserData = company.payPreparationDetailUserDtos || [];
              if (company.payPreparationDetailUserDtos) {
                preparationUserData.map((item, index) => { // 还原准备明细手工操作用户
                  item.userDtoList.map((_item, index) => {
                    if (_item.userName || _item.userCode || _item.title || _item.code) {
                      _item.title = _item.userName;
                      _item.code = _item.userCode;
                    } else {
                      item.userDtoList = [];
                    }
                  });
                });
              }
              server.QueryValueSetByCode({ code: 'payWay' }).then(response => {
                this.prepareUser.data = [];
                if (response.stateCode == -1) {
                  this.$Message.success(response.msg);
                } else {
                  for (let i = 0; i < response.length; i++) {
                    if (preparationUserData.length == 0) {
                      this.prepareUser.data.push({
                        payWay: response[i].value,
                        payWayName: response[i].label,
                        userDtoList: [],
                        companyCode: newVal
                      });
                      // console.log('123', this.prepareUser.data);
                    } else {
                      for (let m = 0; m < preparationUserData.length; m++) {
                        if (response[i].value == preparationUserData[m].payWay) {
                          this.prepareUser.data.push({
                            payWay: response[i].value,
                            payWayName: response[i].label,
                            userDtoList: preparationUserData[m].userDtoList,
                            companyCode: newVal
                          });
                        }
                      }
                      // console.log('456', this.prepareUser.data);
                    }
                  }
                }
              });
            });
          });
      }
    }
  },

  created: function() {
    this.setPageActions();
    if (!this.companyCodes.length) {
      this.$emit('SetTitle', '新增');
    } else {
      this.$emit('SetTitle', '编辑');
      if (this.companyCodes.length === 1) {
        this.searchForm.ouCode = this.companyCodes[0];
      } else {
        // this.searchForm.companyCode = this.companyCodes; // 批量
        delete this.rules.ouCode;
      }
    }
  },

  beforeMount: function() {},

  mounted: function() {

  },

  beforeDestroy: function() {},

  destroyed: function() {},

  methods: {
    // 设置弹出框属性
    setPageActions() {
      this.$emit('SetPageActions', [
        {
          text: this.$t('保存'),
          theme: 'warning',
          action: 'EditEmail',
          handle: this.save
        }
      ]);
    },

    // 保存
    save() {
      const self = this;
      console.log('self.paymentTable.data', self.paymentTable.data);
      const unValid = self.paymentTable.data.some(item => {
        const keys = Object.keys(item);
        return keys.some(key => {
          if (!item[key]) {
            return true;
          }
        });
      });

      if (unValid) {
        return this.$Message.warning('自动创建付款准备表格需要全部填写完整！');
      }

      this.$refs.searchForm.validate(valid => {
        if (valid) {
          // 提交给后端的数据
          let datas = Object.assign({}, self.searchForm, {
            paymentPermissionConfigReqList: self.paymentTable.data
          });

          const configList = datas.paymentPermissionConfigReqList;
          datas.ouName = self.selectCompanyData.valueMap[datas.ouCode]; // 核算机构 中文名称
          datas.manualChnNameList = self.showEmployeeName(datas.manuallyCreator).split(','); // 手工操作用户 中文姓名
          datas.manualEmpIdList = self.showEmployeeId(datas.manuallyCreator); // 手工操作用户 Id
          datas.manualUserCodeList = self.showEmployeeCode(datas.manuallyCreator); // 手工操作用户LDAP账户
          datas.fundManagerChnNameList = self.showEmployeeName(datas.fundManager).split(','); // 资金负责人 中文姓名
          datas.fundManagerEmpIdList = self.showEmployeeId(datas.fundManager); // 资金负责人用户 Id
          datas.fundManagerUserCodeList = self.showEmployeeCode(datas.fundManager); // 资金负责人用户LDAP账户
          datas.localCashierChnNameList = self.showEmployeeName(datas.localCashierList).split(','); // 本地出纳 中文姓名
          datas.localCashierEmpIdList = self.showEmployeeId(datas.localCashierList); // 本地出纳ID
          datas.localCashierUserCodeList = self.showEmployeeCode(datas.localCashierList);// 本地出纳LDAP账户
          // datas.localCashierList =  self.showEmployeeName(datas.localCashierList).split(",") // 本地出纳 中文姓名
          datas.readOnlyUserChnNames = self.showEmployeeName(datas.userList).split(','); // 查询用户 中文姓名
          datas.readOnlyUserEmpIds = self.showEmployeeId(datas.userList); // 查询用户ID
          datas.readOnlyUserUserCodes = self.showEmployeeCode(datas.userList);// 查询用户LDAP账户
          datas.isAutoCreatePaymentPrivate = configList[0].isAutoCreatePayment; // 对私
          datas.isAutoCreatePaymentPublic = configList[1].isAutoCreatePayment; // 对公
          configList.map(item => {
            item.auToChnNameList = self.showEmployeeName(item.auToUser).split(','); // 自动准备批创建人中文姓名
            item.auToEmpIdList = self.showEmployeeId(item.auToUser); // 自动准备批创建人EmpId
            item.auToUserCodeList = self.showEmployeeCode(item.auToUser); // 自动准备批创建人LDAP账户
            item.ouCode = datas.ouCode;
          });
          datas.payPreparationDetailUserDtos = [];
          const payPreparationDetailUserDtos = self.prepareUser.data;
          self.prepareUser.data.forEach(function(prepareItem) {
            datas.payPreparationDetailUserDtos.push({
              ouCode: prepareItem.companyCode,
              payWay: prepareItem.payWay,
              userDtoList: []
            });
          });
          const list = datas.payPreparationDetailUserDtos;
          list.forEach((item, index) => {
            payPreparationDetailUserDtos[index].userDtoList.forEach(_item => {
              if (_item.userName || _item.userCode || _item.title || _item.code) {
                item.userDtoList.push({
                  userName: _item.userName ? _item.userName : _item.title,
                  userCode: _item.userCode ? _item.userCode : _item.code,
                  title: _item.userName ? _item.userName : _item.title,
                  code: _item.userCode ? _item.userCode : _item.code
                });
              }
            });
          });
          if (self.companyCodes.length > 1) { // 批量修改 要求按这个格式传 [{},{}]，只有companyCode、companyName不一样
            const dataList = [];
            self.companyCodes.map(code => {
              const datasBatch = JSON.parse(JSON.stringify(datas));
              const ditem = {
                ...datasBatch,
                ouCode: code
                // companyName: this.companysCodeNameMap[code]
              };
              ditem.paymentPermissionConfigReqList.map(item => {
                item.companyCode = code;
              });
              dataList.push(ditem);
            });

            datas = dataList;
          }

          // 把值集的转换成1/0而不是YES/NO  在保存这里统一处理，方便以后后端如果改成1/0的数据接收，可以直接把这里代码注释掉
          Object.keys(datas).forEach(key => {
            if (datas[key] == 'YES') {
              datas[key] = '1';
            } else if (datas[key] == 'NO') {
              datas[key] = '0';
            }
          });

          // 提交数据
          let serverAction = 'addSetting';
          self.companys.length === 1 && (serverAction = 'editSetting');
          self.companys.length > 1 && (serverAction = 'editSettingBatch');
          server[serverAction](datas)
            .then(response => {
              if (response.data.code == '1') {
                this.$Message.success('保存成功');
                this.$emit('Close');
              } else {
                this.$Message.error(response.data.msg);
              }
            })
            .catch(err => {});
        } else {
          this.$Message.error({
            content: '未通过验证',
            duration: 3
          });
        }
      });
    },

    // 根据 业务类型 生成表单
    createTableFormByBizType(val) {
      console.log('啊四六级范德萨京东方【感觉');
      const data = {
        businessType: '',
        isAutoCreatePayment: '',
        auToUser: '',
        auditor: '',
        tssPayStatus: '',
        billPayStatus: '',
        otherPayStatus: '',
        payBatchMax: ''
      };
      const newData = type => {
        return Object.assign(JSON.parse(JSON.stringify(data)), { businessType: type });
      };
      const datas = [];
      const bizType = this.businessTypeData.valueMap;
      console.log('bizType', bizType);
      // debugger;
      if (val === 'ALL') {
        // 全部
        datas.push(newData(val));
      } else {
        // 对公 & 对私
        for (const btkey in bizType) {
          if (btkey !== 'ALL') {
            datas.push(newData(btkey));
          }
        }
      }
      console.log('this.paymentTable', this.paymentTable);
      this.$set(this.paymentTable, 'data', datas);
      console.log('datas', datas);
      console.log('this.paymentTable', this.paymentTable);
    },

    // 选择 付款准备手工操作用户
    selectEmployee(data) {
      this.searchForm.manuallyCreator = data;
    },

    // 选择 本地出纳
    selectLocalCashier(data) {
      this.searchForm.localCashierList = data;
    },
    // 选择 查询用户
    selectUser(data) {
      this.searchForm.userList = data;
    },
    // 选择资金负责人
    selectLocalCapital(data) {
      this.searchForm.fundManager = data;
    },
    showEmployeeName(data) {
      if (!data || !(data instanceof Array)) {
        return '';
      }

      const names = [];

      if (data.length > 0 && data[0] && data[0].title) { // 组件返回的是 Array[Object]
        data.map(item => {
          names.push(item.title);
        });
      } else { // 从后端拉取得是Array[String]
        data.map(item => {
          if (typeof (item) == 'string') {
            if (item.indexOf('-') >= 0) {
              names.push(item.split('-')[1]);
            } else {
              names.push(item);
            }
          } else {
            names.push(item.title);
          }
        });
      }

      return names.join(',');
    },
    // showPreEmployeeName(data) {
    //   if (!data || !(data instanceof Array)) {
    //     return "";
    //   }
    //   let names = [];
    //   if(data.length > 0 && data[0] && data[0].title){ // 组件返回的是 Array[Object]
    //     data.map(item => {
    //       names.push(item.title);
    //     });
    //   }else { // 从后端拉取得是Array[String]
    //     data.map(item => {
    //       if(typeof (item) == "string"){
    //         if(item.indexOf('-') >=0){
    //           names.push(item.split('-')[1]);
    //         }else{
    //           names.push(item);
    //         }
    //       }else{
    //         names.push(item.userName?item.userName:item.title)
    //       }
    //     });
    //   }
    //   return names.join(",");
    // },
    showEmployeeNameAndId(data) {
      if (!data || !(data instanceof Array)) {
        return '';
      }

      let names = [];

      if (data.length > 0 && data[0] && data[0].title) { // 组件返回的是 Array[Object]
        data.map(item => {
          names.push(item.id + '-' + item.title);
        });
      } else { // 从后端拉取得是Array[String]
        names = data;
      }

      return names.join(',');
    },
    showEmployeeId(data) {
      if (!data || !(data instanceof Array)) {
        return [];
      }
      const ids = [];
      data.map(item => {
        ids.push(item.id);
      });
      return ids;
    },

    showEmployeeCode(data) {
      if (!data || !(data instanceof Array)) {
        return [];
      }
      const codes = [];
      data.map(item => {
        codes.push(item.code);
      });
      return codes;
    },

    // 是、否 值集 valueList数据 反显值valueMap
    loadedVsYesNo(val) {
      this.yesNoData = val;
    },

    // 业务类型 值集 valueList数据 反显值valueMap
    loadedBusinessType(val) {
      this.businessTypeData = val;
      // 初始化“自动创建付款准备”表格设置
      this.createTableFormByBizType();
    },

    // 选核算机构后返回列表对象 valueList数据 反显值valueMap
    loadedSelectCompany(data) {
      this.selectCompanyData = data;
    }
  }
};
</script>

<style lang="less" scoped>
/deep/ .ivu-form-item-label {
  font-size: 12px!important;
}
.card-box {
  padding: 24px;
}
.code-row-bg-2 {
  margin-bottom: 12px;
}
.dashed-hr {
  display: block;
  margin-left: 24px;
  height: 1px;
  border-top: 1px dashed #424656;
  opacity: 0.12;
  width: 97%;
}

</style>
