|
|
@@ -0,0 +1,185 @@
|
|
|
+import { Button, Checkbox, Dropdown, Popover } from 'antd'
|
|
|
+import React, { useState } from 'react'
|
|
|
+import { connect } from 'dva'
|
|
|
+import styles from './index.scss'
|
|
|
+import { apiConnOrDelTag } from '@/services/customer'
|
|
|
+
|
|
|
+const DropdownTypeEnum = {
|
|
|
+ check: 0,
|
|
|
+ edit: 1
|
|
|
+}
|
|
|
+// 数据类型
|
|
|
+export const TagDataTypeEnum = {
|
|
|
+ CONTACT: 0, // 联系人
|
|
|
+ COMPANY: 1 // 客户
|
|
|
+}
|
|
|
+// 标签类型
|
|
|
+export const TagTypeEnum = {
|
|
|
+ PERSONTAG: 0, // 个人
|
|
|
+ TEAMTAG: 1 // 协作
|
|
|
+}
|
|
|
+export const LabelModeType = {
|
|
|
+ column: 0, // 列操作
|
|
|
+ toolbar: 1 // 常用于表格批量操作
|
|
|
+}
|
|
|
+
|
|
|
+export const LabelChangeType = {
|
|
|
+ conn: 0, // 关联标签
|
|
|
+ del: 1 // 删除标签
|
|
|
+}
|
|
|
+
|
|
|
+const PersonLabel = props => {
|
|
|
+ const {
|
|
|
+ children,
|
|
|
+ dataId,
|
|
|
+ tagIds = [],
|
|
|
+ tagType,
|
|
|
+ tagColumn,
|
|
|
+ modeType = 'column',
|
|
|
+ checkCallBack,
|
|
|
+ dispatch,
|
|
|
+ personTags
|
|
|
+ } = props
|
|
|
+ const [dropdownType, setDropdownType] = useState(DropdownTypeEnum.check)
|
|
|
+
|
|
|
+ if (!personTags?.length) {
|
|
|
+ dispatch({
|
|
|
+ type: 'customer/fetchTags',
|
|
|
+ payload: { tagType, tagColumn }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const menu = (
|
|
|
+ <div className="zh-mg-tb-7 zh-mg-lf-14">
|
|
|
+ <DropDownMenu
|
|
|
+ dataId={dataId}
|
|
|
+ personTags={personTags}
|
|
|
+ tagIds={tagIds}
|
|
|
+ menuType={dropdownType}
|
|
|
+ tagType={tagType}
|
|
|
+ tagColumn={tagColumn}
|
|
|
+ modeType={modeType}
|
|
|
+ checkCallBack={checkCallBack}
|
|
|
+ />
|
|
|
+ <div className="zh-mg-top-5">
|
|
|
+ {dropdownType === DropdownTypeEnum.check ? (
|
|
|
+ <span
|
|
|
+ onClick={() => setDropdownType(DropdownTypeEnum.edit)}
|
|
|
+ className="zh-primary zh-pointer">
|
|
|
+ 编辑标签
|
|
|
+ </span>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <Button type="primary">确认</Button>
|
|
|
+ <Button type="default" className="zh-mg-left-5">
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ return (
|
|
|
+ <Popover content={menu} trigger="click" className={styles.dropdownMenu}>
|
|
|
+ {children}
|
|
|
+ </Popover>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const DropDownMenu = props => {
|
|
|
+ // 保存选中的checkbox ids
|
|
|
+ const {
|
|
|
+ tagIds,
|
|
|
+ dataId,
|
|
|
+ menuType,
|
|
|
+ tagType,
|
|
|
+ tagColumn,
|
|
|
+ personTags,
|
|
|
+ modeType,
|
|
|
+ checkCallBack
|
|
|
+ } = props
|
|
|
+ const [checkedIds, setCheckedIds] = useState(tagIds)
|
|
|
+
|
|
|
+ console.log('personTags', personTags)
|
|
|
+ const statusColors = {
|
|
|
+ [TagTypeEnum.PERSONTAG]: [
|
|
|
+ '#16A085',
|
|
|
+ '#2980B9',
|
|
|
+ '#8E44AD',
|
|
|
+ '#f90000',
|
|
|
+ '#B8651B',
|
|
|
+ '#2C3E50',
|
|
|
+ '#efd200'
|
|
|
+ ],
|
|
|
+ [TagTypeEnum.TEAMTAG]: [
|
|
|
+ '#F8AC59',
|
|
|
+ '#FF69B4',
|
|
|
+ '#999999',
|
|
|
+ '#7186ab',
|
|
|
+ '#778b72',
|
|
|
+ '#c292ca',
|
|
|
+ '#a14751'
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleOnchange = async (e, id) => {
|
|
|
+ const { checked } = e.target
|
|
|
+ if (modeType === LabelModeType.column) {
|
|
|
+ const payload = {
|
|
|
+ type: checked ? LabelChangeType.conn : LabelChangeType.del,
|
|
|
+ data: { tagId: id, dataId, dataType: tagColumn, tagType }
|
|
|
+ }
|
|
|
+ const { code = -1 } = await apiConnOrDelTag(payload)
|
|
|
+ } else {
|
|
|
+ const ids = checked ? [...checkedIds, id] : checkedIds.filter(item => item)
|
|
|
+ setCheckedIds(ids)
|
|
|
+ checkCallBack && checkCallBack(ids)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <ul className={styles.labelContent}>
|
|
|
+ {menuType === DropdownTypeEnum.check
|
|
|
+ ? personTags.map((item, idx) => (
|
|
|
+ <li key={item.id} className={styles.menuItem}>
|
|
|
+ <div className={styles.labelText}>
|
|
|
+ <div
|
|
|
+ className={[
|
|
|
+ styles.statusIcon,
|
|
|
+ tagType === TagTypeEnum.PERSONTAG ? styles.suqare : ''
|
|
|
+ ].join(' ')}
|
|
|
+ style={{ backgroundColor: statusColors[tagType][idx] }}
|
|
|
+ />
|
|
|
+ <span>{item.name}</span>
|
|
|
+ </div>
|
|
|
+ <div className={styles.checkSpan}>
|
|
|
+ <Checkbox
|
|
|
+ checked={checkedIds.includes(item.id)}
|
|
|
+ onChange={e => handleOnchange(e, item.id)}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </li>
|
|
|
+ ))
|
|
|
+ : null}
|
|
|
+ {menuType === DropdownTypeEnum.edit
|
|
|
+ ? personTags.map((item, idx) => (
|
|
|
+ <li key={item.id} className={styles.menuItem}>
|
|
|
+ <div>
|
|
|
+ <div
|
|
|
+ className={[
|
|
|
+ styles.statusIcon,
|
|
|
+ tagType === TagTypeEnum.PERSONTAG ? styles.suqare : ''
|
|
|
+ ].join(' ')}
|
|
|
+ style={{ backgroundColor: statusColors[tagType][idx] }}
|
|
|
+ />
|
|
|
+ <span>{item.name}</span>
|
|
|
+ </div>
|
|
|
+ </li>
|
|
|
+ ))
|
|
|
+ : null}
|
|
|
+ </ul>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default connect(({ customer }) => ({
|
|
|
+ personTags: customer.personTags
|
|
|
+}))(PersonLabel)
|