UNPKG

@nutui/nutui-react-taro

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

68 lines (67 loc) 3.32 kB
import { _ as _object_spread } from "@swc/helpers/_/_object_spread"; import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties"; import React from "react"; import { Check, Location } from "@nutui/icons-react-taro"; import { ScrollView, View } from "@tarojs/components"; import { useConfig } from "../configprovider/index"; var defaultProps = { type: 'exist', existList: [], defaultIcon: null, selectIcon: null, custom: false }; export var ExistRender = function(props) { var locale = useConfig().locale; var _ref = _object_spread({}, defaultProps, props), children = _ref.children, type = _ref.type, existList = _ref.existList, selectIcon = _ref.selectIcon, defaultIcon = _ref.defaultIcon, custom = _ref.custom, onSelect = _ref.onSelect, onSwitch = _ref.onSwitch, rest = _object_without_properties(_ref, [ "children", "type", "existList", "selectIcon", "defaultIcon", "custom", "onSelect", "onSwitch" ]); var classPrefix = 'nut-address'; var selectedExist = function(item) { existList.forEach(function(list, index) { ; list.selectedAddress = false; }); item.selectedAddress = true; onSelect && onSelect(item); }; var onClick = function(e) { e.stopPropagation(); onSwitch && onSwitch({ type: type === 'exist' ? 'cascader' : 'exist' }); }; return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ScrollView, { scrollY: true, style: { height: '100%' } }, /*#__PURE__*/ React.createElement("ul", { className: "".concat(classPrefix, "-exist") }, existList.map(function(item, index) { return /*#__PURE__*/ React.createElement("li", { className: "".concat(classPrefix, "-exist-item ").concat(item.selectedAddress ? 'active' : ''), key: index, onClick: function(e) { e.stopPropagation(); selectedExist(item); } }, item.selectedAddress ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.isValidElement(selectIcon) ? selectIcon : /*#__PURE__*/ React.createElement(Check, { color: "#FF0F23" })) : /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.isValidElement(defaultIcon) ? defaultIcon : /*#__PURE__*/ React.createElement(Location, null)), /*#__PURE__*/ React.createElement(View, { className: "".concat(classPrefix, "-exist-item-info") }, item.name && item.phone && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(View, null, item.name), /*#__PURE__*/ React.createElement(View, null, item.phone)), /*#__PURE__*/ React.createElement(View, null, item.provinceName + item.cityName + item.countyName + item.townName + item.addressDetail))); }))), (custom || custom && locale.address.chooseAnotherAddress) && /*#__PURE__*/ React.createElement(View, { className: "".concat(classPrefix, "-footer"), onClick: onClick }, /*#__PURE__*/ React.createElement(View, { className: "".concat(classPrefix, "-footer-btn") }, custom))); };