"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _vtxFormLayout = _interopRequireDefault(require("@vtx/components/lib/vtx-form-layout"));
var _input = _interopRequireDefault(require("antd/lib/input"));
var _inputNumber = _interopRequireDefault(require("antd/lib/input-number"));
var _space = _interopRequireDefault(require("antd/lib/space"));
var _Form = _interopRequireDefault(require("antd/lib/form/Form"));
var _vtxSelect = _interopRequireDefault(require("@vtx/components/lib/vtx-select"));
var _PlusCircleOutlined = _interopRequireDefault(require("@ant-design/icons/lib/icons/PlusCircleOutlined"));
var _MinusCircleFilled = _interopRequireDefault(require("@ant-design/icons/lib/icons/MinusCircleFilled"));
var _col = _interopRequireDefault(require("antd/lib/col"));
var _row = _interopRequireDefault(require("antd/lib/row"));
var _vtxColorPicker = _interopRequireDefault(require("@vtx/components/lib/vtx-color-picker"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _config = _interopRequireDefault(require("../../config"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function toChineseNumber(num) {
  var units = ['', '十', '百', '千', '万'];
  var digits = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  var decimal = '点';
  var parts = num.toString().split('.');
  var integerPart = parts[0];
  var decimalPart = parts[1];
  var chineseInteger = '';
  var chineseDecimal = '';
  // 转换整数部分
  for (var i = 0; i < integerPart.length; i++) {
    var digit = parseInt(integerPart[i]);
    var unit = units[integerPart.length - 1 - i];
    if (digit !== 0) {
      chineseInteger += digits[digit] + unit;
    } else if (!chineseInteger.endsWith('零') && !chineseInteger.endsWith(units[0])) {
      chineseInteger += digits[0];
    }
  }

  // 转换小数部分
  if (decimalPart) {
    for (var _i = 0; _i < decimalPart.length; _i++) {
      chineseDecimal += digits[parseInt(decimalPart[_i])];
    }
    chineseDecimal = decimal + chineseDecimal;
  }
  return chineseInteger + chineseDecimal;
}

// 使用示例

var Option = _vtxSelect["default"].Option;
var WaterBalance = function WaterBalance(_ref) {
  var _ref$form = _ref.form,
    form = _ref$form === void 0 ? {} : _ref$form;
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"], {
    cols: 2
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%'
    }
  }, "\u8BA1\u7B97\u7247\u533A\u914D\u7F6E"), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    name: "minDistrictLevelCode",
    label: "\u6700\u5C0F\u5206\u6790\u7247\u533A\u7B49\u7EA7",
    rules: [{
      required: true,
      message: '请选择最小分析片区等级'
    }],
    initialValue: '1'
  }, /*#__PURE__*/_react["default"].createElement(_vtxSelect["default"], {
    allowClear: false
  }, _config["default"].districtLevelList.map(function (v) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: v.key
    }, v.value);
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%'
    }
  }, "\u4F9B\u6C34\u91CF\u8BA1\u7B97\u914D\u7F6E"), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    name: "supplyPerPerson",
    label: "\u4EBA\u5747\u4F9B\u6C34\u91CF",
    rules: [{
      required: true,
      message: '请填人均供水量'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    addonAfter: "m\xB3/d",
    precision: 2,
    min: 0,
    style: {
      width: '100%'
    },
    placeholder: "\u8BF7\u8F93\u5165"
  })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    name: "supplyPerArea",
    label: "\u5355\u4F4D\u9762\u79EF\u4F9B\u6C34\u91CF",
    rules: [{
      required: true,
      message: '请填写单位面积供水量'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    addonAfter: "m\xB3",
    style: {
      width: '100%'
    },
    min: 0,
    precision: 2,
    placeholder: "\u8BF7\u8F93\u5165"
  })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    label: "\u968F\u673A\u6D6E\u52A8\u533A\u95F4",
    weights: 2,
    required: true
  }, /*#__PURE__*/_react["default"].createElement(_space["default"], {
    align: "center"
  }, /*#__PURE__*/_react["default"].createElement(_Form["default"].Item, {
    name: "supplyRandomMin",
    rules: [{
      required: true,
      message: '请填写浮动区间下限'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    style: {
      width: '100%'
    },
    placeholder: "\u8BF7\u8F93\u5165"
  })), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      marginBottom: '20px',
      display: 'inline-block'
    }
  }, "\u81F3"), /*#__PURE__*/_react["default"].createElement(_Form["default"].Item, {
    name: "supplyRandomMax",
    rules: [{
      required: true,
      message: '请填写浮动区间上限'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    style: {
      width: '100%'
    },
    placeholder: "\u8BF7\u8F93\u5165"
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%'
    }
  }, "\u6392\u6C34\u91CF\u8BA1\u7B97\u914D\u7F6E"), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    name: "drainagePerPerson",
    label: "\u4EBA\u5747\u6392\u6C34\u91CF",
    rules: [{
      required: true,
      message: '请填人均排水量'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    addonAfter: "m\xB3/d",
    precision: 2,
    min: 0,
    style: {
      width: '100%'
    },
    placeholder: "\u8BF7\u8F93\u5165"
  })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    name: "drainagePerArea",
    label: "\u5355\u4F4D\u9762\u79EF\u6392\u6C34\u91CF",
    rules: [{
      required: true,
      message: '请填写单位面积排水量'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    addonAfter: "m\xB3",
    style: {
      width: '100%'
    },
    min: 0,
    precision: 2,
    placeholder: "\u8BF7\u8F93\u5165"
  })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
    label: "\u968F\u673A\u6D6E\u52A8\u533A\u95F4",
    weights: 2,
    required: true
  }, /*#__PURE__*/_react["default"].createElement(_space["default"], {
    align: "center"
  }, /*#__PURE__*/_react["default"].createElement(_Form["default"].Item, {
    name: "drainageRandomMin",
    rules: [{
      required: true,
      message: '请填写浮动区间下限'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    style: {
      width: '100%'
    },
    placeholder: "\u8BF7\u8F93\u5165"
  })), /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      marginBottom: '20px',
      display: 'inline-block'
    }
  }, "\u81F3"), /*#__PURE__*/_react["default"].createElement(_Form["default"].Item, {
    name: "drainageRandomMax",
    rules: [{
      required: true,
      message: '请填写浮动区间上限'
    }]
  }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
    style: {
      width: '100%'
    },
    placeholder: "\u8BF7\u8F93\u5165"
  })))), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '100%'
    }
  }, "\u6C34\u5E73\u8861\u7B49\u7EA7\u914D\u7F6E"), /*#__PURE__*/_react["default"].createElement(_Form["default"].List, {
    name: "levels",
    initialValue: [{
      name: '',
      levelThreshold: '',
      colorVal: '',
      description: ''
    }]
  }, function (fields, _ref2) {
    var add = _ref2.add,
      remove = _ref2.remove;
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, fields.map(function (field, index) {
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          width: '100%',
          paddingLeft: '24px'
        }
      }, toChineseNumber(field.name + 1), "\u7EA7"), /*#__PURE__*/_react["default"].createElement(_row["default"], {
        key: index
      }, /*#__PURE__*/_react["default"].createElement(_col["default"], {
        span: 22
      }, /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"], {
        cols: 2
      }, /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
        name: [field.name, 'name'],
        label: "\u7B49\u7EA7\u540D\u79F0",
        rules: [{
          required: true,
          message: '请填写'
        }, function (_ref3) {
          var getFieldValue = _ref3.getFieldValue;
          return {
            validator: function validator(_, value) {
              var rules = getFieldValue('levels');
              if (!value || rules.every(function (rule, i) {
                if (i !== index) {
                  return rule.name !== value;
                }
                return true;
              })) {
                return Promise.resolve();
              }
              return Promise.reject(new Error('等级名称不可重复'));
            }
          };
        }]
      }, /*#__PURE__*/_react["default"].createElement(_input["default"], {
        style: {
          width: '100%'
        },
        placeholder: "\u8BF7\u8F93\u5165"
      })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
        name: [field.name, 'levelThreshold'],
        label: "\u9608\u503C",
        rules: [{
          required: true,
          message: '请填写'
        }, function (_ref4) {
          var getFieldValue = _ref4.getFieldValue;
          return {
            validator: function validator(_, value) {
              var rules = getFieldValue('levels');
              if (!value || rules.every(function (rule, i) {
                if (i !== index) {
                  return rule.levelThreshold !== value;
                }
                return true;
              })) {
                return Promise.resolve();
              }
              return Promise.reject(new Error('阈值不可重复'));
            }
          };
        }]
      }, /*#__PURE__*/_react["default"].createElement(_inputNumber["default"], {
        style: {
          width: '100%'
        },
        min: 0,
        precision: 0,
        placeholder: "\u8BF7\u8F93\u5165"
      })), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, _extends({}, field, {
        label: '颜色',
        name: [field.name, 'colorVal'],
        required: true,
        rules: [{
          required: true,
          message: '请填写'
        }]
      }), /*#__PURE__*/_react["default"].createElement(_vtxColorPicker["default"], null)), /*#__PURE__*/_react["default"].createElement(_vtxFormLayout["default"].FormItem, {
        name: [field.name, 'description'],
        label: "\u5904\u7406\u63AA\u65BD",
        weights: 2,
        rules: [{
          required: true,
          message: '请填写'
        }]
      }, /*#__PURE__*/_react["default"].createElement(_input["default"].TextArea, {
        maxLength: 500,
        placeholder: "\u8BF7\u8F93\u5165",
        style: {
          width: '100%'
        }
      })))), fields.length > 1 && fields.length - 1 === index && /*#__PURE__*/_react["default"].createElement(_col["default"], {
        span: 1
      }, /*#__PURE__*/_react["default"].createElement(_MinusCircleFilled["default"], {
        style: {
          fontSize: 20,
          color: '#1890ff'
        },
        onClick: function onClick() {
          remove(field.name);
        }
      })), fields.length === index + 1 && /*#__PURE__*/_react["default"].createElement(_col["default"], {
        span: 1
      }, /*#__PURE__*/_react["default"].createElement(_PlusCircleOutlined["default"], {
        style: {
          fontSize: 20,
          color: '#1890ff'
        },
        onClick: function onClick() {
          var rules = form.getFieldValue('levels');
          var bool = false;
          rules.forEach(function (item) {
            for (var key in item) {
              if (item[key] !== 0 && !item[key]) {
                bool = true;
              }
            }
          });
          if (bool) {
            _message["default"].warn('请填写完再新增');
            return;
          }
          add({
            name: '',
            levelThreshold: '',
            colorVal: '',
            description: ''
          });
        }
      }))));
    }));
  })));
};
var _default = exports["default"] = WaterBalance;
//# sourceMappingURL=waterBalance.js.map
