"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _fdx = require("@whalecloud/fdx");

var _fishx = require("fishx");

var _react = _interopRequireWildcard(require("react"));

require("./index.less");

var _excluded = ["total"],
    _excluded2 = ["total"],
    _excluded3 = ["total"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var Option = _fdx.Select.Option;

var ProductDetailPage = function ProductDetailPage(props) {
  var setUrl = props.setUrl;

  var _useState = (0, _react.useState)([]),
      _useState2 = _slicedToArray(_useState, 2),
      productList = _useState2[0],
      setProductList = _useState2[1];

  var _useState3 = (0, _react.useState)([]),
      _useState4 = _slicedToArray(_useState3, 2),
      brandData = _useState4[0],
      setBrandData = _useState4[1];

  var _useState5 = (0, _react.useState)({}),
      _useState6 = _slicedToArray(_useState5, 2),
      brandId = _useState6[0],
      settBrandId = _useState6[1];

  var _useState7 = (0, _react.useState)(''),
      _useState8 = _slicedToArray(_useState7, 2),
      productCode = _useState8[0],
      setProductCode = _useState8[1];

  var _useState9 = (0, _react.useState)(''),
      _useState10 = _slicedToArray(_useState9, 2),
      productName = _useState10[0],
      setProductName = _useState10[1];

  var _useState11 = (0, _react.useState)(false),
      _useState12 = _slicedToArray(_useState11, 2),
      loading = _useState12[0],
      setLoading = _useState12[1];

  var _useState13 = (0, _react.useState)({
    pageSize: 20,
    pageIndex: 1
  }),
      _useState14 = _slicedToArray(_useState13, 2),
      paginationParams = _useState14[0],
      setPaginationParams = _useState14[1];

  var columns = [{
    title: 'Image',
    dataIndex: 'productImageUrl',
    width: 80,
    render: function render(url) {
      return /*#__PURE__*/_react["default"].createElement("img", {
        width: 72,
        src: url,
        alt: ""
      });
    }
  }, {
    title: 'Product Name',
    dataIndex: 'productName',
    render: function render(name) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "productName"
      }, name);
    }
  }, {
    title: 'SKU',
    dataIndex: 'attrValues',
    render: function render(sku) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "productName"
      }, sku);
    }
  }, {
    title: 'Merchant',
    dataIndex: 'storeName'
  }];
  var rowSelection = {
    onChange: function onChange(selectedRowKeys, selectedRows) {
      setUrl("proDetail-".concat(selectedRows[0].offerId, "-").concat(selectedRows[0].productId));
      console.log("selectedRowKeys: ".concat(selectedRowKeys), 'selectedRows: ', selectedRows);
    },
    type: 'radio'
  };
  var queryGoods = (0, _fishx.useFetch)(function (params) {
    return {
      url: "".concat(window.MParams.MBaseUrl, "/products"),
      method: 'get',
      params: params
    };
  }, {
    manual: true,
    onSuccess: function onSuccess(res) {
      setLoading(false);
      paginationParams.total = res.total;
      setProductList(res.list); // console.log(paginationParams, 3333);
      // setPaginationParams({ ...paginationParams });

      window.MProductList = res.list;
    }
  }); // 请求品牌

  var queryBrand = (0, _fishx.useFetch)(function () {
    return {
      url: "".concat(window.MParams.MBaseUrl, "/brands/list"),
      method: 'get'
    };
  }, {
    manual: true,
    onSuccess: function onSuccess(res) {
      setBrandData(res);
    }
  });

  var handleBrandChange = function handleBrandChange(value, node) {
    settBrandId(node);
  };

  var reset = function reset() {
    setProductName('');
    setProductCode('');
    settBrandId({});
  };

  (0, _react.useEffect)(function () {
    setLoading(true);

    var total = paginationParams.total,
        params = _objectWithoutProperties(paginationParams, _excluded);

    queryGoods.run(params);
    queryBrand.run();
  }, []);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "productDetailPage"
  }, /*#__PURE__*/_react["default"].createElement(_fdx.Row, {
    className: "mb12",
    style: {
      width: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement(_fdx.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "labelStyle"
  }, "Product Name"), /*#__PURE__*/_react["default"].createElement(_fdx.Input, {
    value: productName,
    onChange: function onChange(e) {
      setProductName(e.target.value);
    },
    className: "inputStyle",
    placeholder: "Basic usage"
  })), /*#__PURE__*/_react["default"].createElement(_fdx.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "labelStyle"
  }, "SKU Code"), /*#__PURE__*/_react["default"].createElement(_fdx.Input, {
    value: productCode,
    onChange: function onChange(e) {
      setProductCode(e.target.value);
    },
    className: "inputStyle",
    placeholder: "Basic usage"
  }))), /*#__PURE__*/_react["default"].createElement(_fdx.Row, {
    className: "mb12",
    style: {
      width: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement(_fdx.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "labelStyle"
  }, "Brand"), /*#__PURE__*/_react["default"].createElement(_fdx.Select, {
    className: "inputStyle",
    placeholder: "Please select",
    defaultValue: [],
    value: brandId.value,
    onChange: handleBrandChange
  }, brandData && brandData.length > 0 && brandData.map(function (v) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: v.brandId,
      value: v.brandName
    }, v.brandName);
  }))), /*#__PURE__*/_react["default"].createElement(_fdx.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement(_fdx.Button, {
    onClick: function onClick() {
      setLoading(true);
      paginationParams.pageIndex = 1;

      var total = paginationParams.total,
          params = _objectWithoutProperties(paginationParams, _excluded2);

      queryGoods.run(_objectSpread({
        productName: productName,
        productCode: productCode,
        brandIds: brandId.key || ''
      }, params));
    },
    type: "primary",
    style: {
      marginRight: 10
    }
  }, "Query"), /*#__PURE__*/_react["default"].createElement(_fdx.Button, {
    onClick: function onClick() {
      reset();
    }
  }, "Cancel"))), /*#__PURE__*/_react["default"].createElement(_fdx.Table, {
    scroll: {
      y: 340
    },
    loading: loading,
    bordered: false,
    rowKey: "productId",
    rowSelection: rowSelection,
    columns: columns,
    dataSource: productList,
    pagination: _objectSpread({}, paginationParams, {
      onChange: function onChange(page) {
        setLoading(true);
        paginationParams.pageIndex = page;

        var total = paginationParams.total,
            params = _objectWithoutProperties(paginationParams, _excluded3);

        queryGoods.run(_objectSpread({
          productName: productName,
          productCode: productCode,
          brandIds: brandId.key || ''
        }, params));
      }
    })
  }));
};

var _default = ProductDetailPage;
exports["default"] = _default;