"use strict";

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

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

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

var _fishx = require("fishx");

var _dateUtil = require("../../../utils/dateUtil");

require("./index.less");

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 _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 BundleCampaign = function BundleCampaign(props) {
  var setUrl = props.setUrl;

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

  var _useState3 = (0, _react.useState)(''),
      _useState4 = _slicedToArray(_useState3, 2),
      campaignName = _useState4[0],
      setCampaignName = _useState4[1];

  var _useState5 = (0, _react.useState)(''),
      _useState6 = _slicedToArray(_useState5, 2),
      storeId = _useState6[0],
      setStoreId = _useState6[1];

  var _useState7 = (0, _react.useState)('A,B'),
      _useState8 = _slicedToArray(_useState7, 2),
      cmpState = _useState8[0],
      setCmpState = _useState8[1];

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

  var _useState11 = (0, _react.useState)([]),
      _useState12 = _slicedToArray(_useState11, 2),
      storeList = _useState12[0],
      setStoreList = _useState12[1];

  var stateMap = [{
    key: 'A,B',
    value: 'All'
  }, {
    key: 'A',
    value: 'Has not started'
  }, {
    key: 'B',
    value: 'Processing'
  }];
  var cmpStateMap = {
    A: 'Has not started',
    B: 'Processing'
  };
  var columns = [{
    title: 'Campaign Name',
    dataIndex: 'campaignName'
  }, {
    title: 'Start/End time',
    dataIndex: 'effDate',
    render: function render(text, record) {
      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", null, (0, _dateUtil.formatDateTime)(record.effDate)), /*#__PURE__*/_react["default"].createElement("div", null, (0, _dateUtil.formatDateTime)(record.expDate)));
    }
  }, {
    title: 'Campaign State',
    dataIndex: 'cmpState',
    render: function render(text, record) {
      return cmpStateMap[record.cmpState];
    }
  }, {
    title: 'Store Name',
    dataIndex: 'storeName'
  }];
  var rowSelection = {
    onChange: function onChange(selectedRowKeys) {
      setUrl("bundleCampaign-".concat(selectedRowKeys));
    },
    type: 'radio'
  };

  var changeCamState = function changeCamState(value) {
    setCmpState(value);
  };

  var reset = function reset() {
    setCampaignName('');
    setStoreId('');
    setCmpState('A,B');
  };

  var _useFetch = (0, _fishx.useFetch)(function (params) {
    return {
      url: "".concat(window.MParams.MBaseUrl, "/bundle/list"),
      method: 'get',
      params: params
    };
  }, {
    manual: true,
    onSuccess: function onSuccess(res) {
      setLoading(false);
      SetBundleList(res.list);
    }
  }),
      queryBundleList = _useFetch.run;

  var queryFunc = function queryFunc() {
    var params = {
      campaignName: campaignName,
      storeId: storeId,
      cmpState: cmpState
    };
    setLoading(true);
    queryBundleList(params);
  }; // 请求店铺列表


  var queryStore = (0, _fishx.useFetch)(function () {
    return {
      url: "".concat(window.MParams.MBaseUrl, "/stores/list"),
      method: 'get'
    };
  }, {
    manual: true,
    onSuccess: function onSuccess(res) {
      setStoreList(res);
    }
  });
  (0, _react.useEffect)(function () {
    queryStore.run();
    var params = {
      campaignName: campaignName,
      storeId: storeId,
      cmpState: cmpState
    };
    setLoading(true);
    queryBundleList(params);
  }, []);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "bundleCampaign"
  }, /*#__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"
  }, "Campaign Name"), /*#__PURE__*/_react["default"].createElement(_fdx.Input, {
    value: campaignName,
    onChange: function onChange(e) {
      setCampaignName(e.target.value);
    },
    className: "inputStyle"
  })), /*#__PURE__*/_react["default"].createElement(_fdx.Col, {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "labelStyle"
  }, "Store"), /*#__PURE__*/_react["default"].createElement(_fdx.Select, {
    showSearch: true,
    optionFilterProp: "children",
    className: "inputStyle",
    placeholder: "Please select",
    value: storeId,
    onChange: function onChange(value) {
      return setStoreId(value);
    }
  }, storeList && storeList.length > 0 && storeList.map(function (v) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: v.storeId,
      value: v.storeId
    }, v.storeName);
  })))), /*#__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"
  }, "Campaign State"), /*#__PURE__*/_react["default"].createElement(_fdx.Select, {
    defaultValue: "A,B",
    value: cmpState,
    onChange: changeCamState,
    className: "inputStyle"
  }, stateMap && stateMap.length > 0 && stateMap.map(function (v) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: v.key,
      value: v.key
    }, v.value);
  })))), /*#__PURE__*/_react["default"].createElement(_fdx.Row, {
    className: "mb12",
    style: {
      width: '100%'
    },
    type: "flex",
    justify: "end"
  }, /*#__PURE__*/_react["default"].createElement(_fdx.Col, {
    span: 5
  }, /*#__PURE__*/_react["default"].createElement(_fdx.Button, {
    onClick: queryFunc,
    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: "campaignId",
    rowSelection: rowSelection,
    columns: columns,
    dataSource: bundleList
  }));
};

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