import _Dialog from "@alifd/next/es/dialog";
import _extends from "@babel/runtime/helpers/extends";
import _Pagination from "@alifd/next/es/pagination";
import _Table from "@alifd/next/es/table";
import _Input from "@alifd/next/es/input";
import _Button from "@alifd/next/es/button";
import _Icon from "@alifd/next/es/icon";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import { Component } from 'react';
import styles from "./index.module.scss";
import { getShopList } from "../../../api/base";
var shopDialog = /*#__PURE__*/function (_Component) {
  _inheritsLoose(shopDialog, _Component);
  function shopDialog(props) {
    var _this;
    _this = _Component.call(this, props) || this;
    _this.getDataList = /*#__PURE__*/function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(searchValue) {
        var data, temArray, itemArray;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                if (searchValue === void 0) {
                  searchValue = null;
                }
                // console.log("111", searchValue)
                data = {
                  f: '',
                  // 1零售2金融
                  // pageNum: tableData.currentPage,
                  // pageSize: tableData.pageSize,
                  pageNum: 0,
                  pageSize: 0,
                  b: searchValue || null,
                  reasonable: true
                };
                _this.setState({
                  loading: true
                });
                temArray = [];
                itemArray = [];
                _context.next = 7;
                return getShopList(data);
              case 7:
                temArray = _context.sent;
                temArray.data.rows.map(function (item) {
                  var _item$xc$, _item$xa$, _item$xa$2;
                  itemArray.push({
                    id: item.a,
                    shop: item.b,
                    shopImg: item === null || item === void 0 ? void 0 : (_item$xc$ = item.xc[0]) === null || _item$xc$ === void 0 ? void 0 : _item$xc$.c,
                    shopTag: item.xb.map(function (items) {
                      return items.b;
                    }),
                    // 1零售2金融
                    shopF: item.f,
                    price1: item === null || item === void 0 ? void 0 : (_item$xa$ = item.xa[0]) === null || _item$xa$ === void 0 ? void 0 : _item$xa$.n,
                    price2: item === null || item === void 0 ? void 0 : (_item$xa$2 = item.xa[0]) === null || _item$xa$2 === void 0 ? void 0 : _item$xa$2.p,
                    stock: '暂无存货',
                    hits: '暂无点击量',
                    shopStatus: item === null || item === void 0 ? void 0 : item.k,
                    putStatus: item === null || item === void 0 ? void 0 : item.k
                  });
                  return itemArray;
                });
                _this.setState({
                  total: temArray.data.total,
                  loading: false,
                  dataSource: [].concat(itemArray)
                });
                // console.log("dataSourcedataSource123", this.state.dataSource)
              case 10:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));
      return function (_x) {
        return _ref.apply(this, arguments);
      };
    }();
    _this.onChangeInput = function (value) {
      _this.setState({
        searchValue: value
      });
    };
    _this.change = function (value) {
      _this.setState({
        currentPage: value
      });
    };
    _this.onChange = function () {
      var array = [];
      array = arguments.length <= 0 ? undefined : arguments[0];
      _this.setState({
        banMultiple: array
      });
    };
    _this.rowSelection = {
      onChange: _this.onChange,
      // getProps: (record) => {
      //   let status = false
      //   this.state.banMultiple.length > 2 ? status = true : status = false
      //   return {
      //     disabled: status ? this.state.banMultiple.includes(record.id) !== true : ''
      //   };
      // },
      titleProps: function titleProps() {
        return {
          style: {
            display: 'none'
          }
        };
      }
    };
    _this.theMessageF = function () {
      _this.props.theMessageS(_this.state.banMultiple);
    };
    _this.state = {
      dataSource: [],
      //  当前页
      currentPage: 1,
      pageSize: 5,
      total: 100,
      // 传递的id值 (最多三个)
      banMultiple: [],
      // 搜索值
      searchValue: null
    };
    return _this;
  }
  var _proto = shopDialog.prototype;
  _proto.componentDidMount = function componentDidMount() {
    this.getDataList();
  };
  _proto.render = function render() {
    var _this2 = this;
    var _this$props = this.props,
      _this$props$title = _this$props.title,
      title = _this$props$title === void 0 ? '编辑商品组件' : _this$props$title,
      _this$props$height = _this$props.height,
      height = _this$props$height === void 0 ? '90%' : _this$props$height,
      _this$props$top = _this$props.top,
      top = _this$props$top === void 0 ? '100px' : _this$props$top,
      onClose = _this$props.onClose,
      _this$props$visible = _this$props.visible,
      visible = _this$props$visible === void 0 ? false : _this$props$visible,
      _this$props$closeIcon = _this$props.closeIcon,
      closeIcon = _this$props$closeIcon === void 0 ? 'close' : _this$props$closeIcon,
      _this$props$titleIcon = _this$props.titleIcon,
      titleIcon = _this$props$titleIcon === void 0 ? 'edit' : _this$props$titleIcon;
    var style = {
      style: {
        display: 'flex',
        flexDirection: 'column',
        width: this.props.width || '60%',
        borderRadius: '12px',
        boxShadow: '0 9px 29px 0 rgba(0, 0, 0, 0.2)'
      }
    };
    var titleNode = /*#__PURE__*/React.createElement("div", {
      className: styles.titleStyle
    }, /*#__PURE__*/React.createElement(_Icon, {
      type: titleIcon,
      size: "small"
    }), /*#__PURE__*/React.createElement("span", null, title));
    var renderShop = function renderShop(value, index, record) {
      return /*#__PURE__*/React.createElement("div", {
        className: styles.shop
      }, /*#__PURE__*/React.createElement("div", {
        className: styles.img
      }, /*#__PURE__*/React.createElement("img", {
        src: record.shopImg
      })), /*#__PURE__*/React.createElement("div", {
        className: styles.message
      }, /*#__PURE__*/React.createElement("div", {
        className: styles.mTitle
      }, record.shop), /*#__PURE__*/React.createElement("div", null, record.shopTag.map(function (item) {
        return /*#__PURE__*/React.createElement("span", {
          key: item,
          className: styles.mTag
        }, item);
      }))));
    };
    var renderShopPrice = function renderShopPrice(value, index, record) {
      return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, record.price1));
      // if (record.price2) {
      //   return (
      //     <div>
      //       {/* <span>{Number(record.price1).toFixed(2)}</span> - <span>{Number(record.price2).toFixed(2)}</span> */}
      //       <span>{Number(record.price1).toFixed(2)}</span>
      //     </div>
      //   )
      // } else {
      //   <div>
      //     <span>{record.price1}</span>
      //   </div>
      // }
    };

    var closeIconNode = /*#__PURE__*/React.createElement(_Icon, {
      type: closeIcon,
      size: "xs"
    });
    return /*#__PURE__*/React.createElement(_Dialog, _extends({
      footer: /*#__PURE__*/React.createElement(_Button, {
        size: "large",
        type: "primary",
        onClick: this.theMessageF
      }, "\u4FDD\u5B58"),
      height: height,
      title: titleNode,
      visible: visible,
      top: top,
      "close-icon": closeIconNode,
      onClose: onClose
    }, style), /*#__PURE__*/React.createElement("div", {
      className: styles.container
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.headerStyle
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Input, {
      placeholder: "\u8F93\u5165\u5546\u54C1\u540D\u79F0\u641C\u7D22",
      style: {
        width: 200
      },
      "aria-label": "\u8F93\u5165\u5546\u54C1\u540D\u79F0\u641C\u7D22",
      onChange: this.onChangeInput
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Button, {
      type: "primary",
      onClick: function onClick() {
        return _this2.getDataList(_this2.state.searchValue);
      }
    }, "\u641C\u7D22"))), /*#__PURE__*/React.createElement("div", {
      className: styles.bodyStyle
    }, /*#__PURE__*/React.createElement(_Table, {
      dataSource: this.state.dataSource.slice((this.state.currentPage - 1) * this.state.pageSize, this.state.currentPage * this.state.pageSize),
      loading: this.state.loading,
      rowSelection: this.rowSelection
    }, /*#__PURE__*/React.createElement(_Table.Column, {
      cell: renderShop,
      title: "\u5546\u54C1",
      width: 300
    }), /*#__PURE__*/React.createElement(_Table.Column, {
      cell: renderShopPrice,
      title: "\u4EF7\u683C",
      width: 100
    })), /*#__PURE__*/React.createElement("div", {
      className: styles.paginationStyle
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Pagination, {
      current: this.state.currentPage,
      pageSize: this.state.pageSize,
      total: this.state.total,
      onChange: this.change
    }))))));
  };
  return shopDialog;
}(Component);
shopDialog.displayName = 'shopDialog';
export { shopDialog as default };