Changeset View
Changeset View
Standalone View
Standalone View
src/pages/businessManagement/index.jsx
- This file was added.
import Taro, { Component } from "@tarojs/taro" | |||||
import { Toast } from "@tujia/rba-miniapp-ui" | |||||
import { | |||||
View, | |||||
Text | |||||
} from "@tarojs/components" | |||||
import api from './api/index' | |||||
import { TAB_LIST, STATUS_TO_LIST, STATUS_TO_TOTALSIZE, STATUS_TO_TOTALPAGE, STATUS_TO_NOMORE, SEATCH_NAME } from "./const" | |||||
import Tabs from "@/components/tabs" | |||||
import SearchBar from "./comSearchBar" | |||||
import ApplyList from "./comApplyList" | |||||
import ApplyDialog from './comDialog' | |||||
import "./index.scss" | |||||
class Index extends Component { | |||||
config = { | |||||
navigationBarTitleText: "商户管理", | |||||
enablePullDownRefresh: true, | |||||
backgroundTextStyle: "dark" | |||||
} | |||||
constructor(props) { | |||||
super(props); | |||||
this.state = { | |||||
//搜索关键词展示 | |||||
searchValue: "", | |||||
//搜索栏默认展示字段 | |||||
searchPlaceholder: "请输入联系人/联系电话/城市", | |||||
//tab | |||||
tabList: TAB_LIST, | |||||
//当前点击tab 0-待处理申请 1-已处理申请 | |||||
current: 0, | |||||
//总条数 | |||||
totalNum: 0, | |||||
//弹框类型 1-驳回 2-通过 | |||||
dialogStatus: 0, | |||||
//弹框是否展示 | |||||
showStatus: 0, | |||||
pageSize: 5, | |||||
pageNum: [1, 1], | |||||
//点击电话号码 | |||||
applyMobile: '', | |||||
//待处理申请 | |||||
peddingList: [], | |||||
peddingTotalSize: 0, | |||||
peddingTotalPage: 1, | |||||
peddingNoMore: false, | |||||
//已处理申请 | |||||
processedList: [], | |||||
processedTotalSize: 0, | |||||
processedTotalPage: 1, | |||||
processedNoMore: false, | |||||
showList: [ | |||||
], | |||||
noMore: false, | |||||
//搜索框下拉列表 | |||||
dropDownList: ["联系人", "联系电话", "城市"], | |||||
//驳回通过对应id | |||||
id: '', | |||||
searchObj: { | |||||
}, | |||||
//待申请添加状态 | |||||
notEnumCscApplyStatus: '' | |||||
} | |||||
} | |||||
componentWillMount () { | |||||
this.setState({ | |||||
dialogStatus: 0 | |||||
}) | |||||
this._initList() | |||||
} | |||||
/** | |||||
* 页面卸载重置筛选项 | |||||
*/ | |||||
componentWillUnmount () { } | |||||
/** | |||||
* 初始化 | |||||
*/ | |||||
_initList = () => { | |||||
const { current, tabList, pageNum, notEnumCscApplyStatus } = this.state | |||||
const newPageNum = [...pageNum] | |||||
newPageNum[current] = 1 | |||||
this.setState({ | |||||
pageNum: newPageNum | |||||
}, () => { | |||||
this._getApplyList(tabList[current].id, notEnumCscApplyStatus) | |||||
}) | |||||
} | |||||
/** | |||||
* 获取申请列表 | |||||
* type 类型 | |||||
*/ | |||||
_getApplyList = (type, notEnumCscApplyStatus) => { | |||||
const { searchObj, pageSize, pageNum, current } = this.state | |||||
const pageNo = pageNum[current] | |||||
api.getApplyList({ | |||||
enumCscApplyStatus: type, | |||||
...searchObj, | |||||
pageNo: pageNo, | |||||
pageSize, | |||||
notEnumCscApplyStatus | |||||
}).then((res) => { | |||||
const { list, totalSize, totalPage } = res | |||||
if (list.length < this.state.pageSize) { | |||||
if (list.length == 0) { | |||||
this.setState({ | |||||
[STATUS_TO_LIST[current]]: this.state.pageNum[current] == 1 ? [...list] : [...this.state[STATUS_TO_LIST[current]], ...list], | |||||
showList: this.state.pageNum[current] == 1 ? [...list] : [...this.state[STATUS_TO_LIST[current]], ...list], | |||||
totalNum: this.state[STATUS_TO_TOTALSIZE[current]], | |||||
[STATUS_TO_NOMORE[current]]: true, | |||||
noMore: true | |||||
}) | |||||
return | |||||
} | |||||
//没有更多数据了 | |||||
this.setState({ | |||||
[STATUS_TO_LIST[current]]: this.state.pageNum[current] == 1 ? [...list] : [...this.state[STATUS_TO_LIST[current]], ...list], | |||||
showList: this.state.pageNum[current] == 1 ? [...list] : [...this.state[STATUS_TO_LIST[current]], ...list], | |||||
[STATUS_TO_NOMORE[current]]: true, | |||||
noMore: true | |||||
}) | |||||
} else { | |||||
//还有数据 | |||||
this.setState({ | |||||
[STATUS_TO_LIST[current]]: this.state.pageNum[current] == 1 ? [...list] : [...this.state[STATUS_TO_LIST[current]], ...list], | |||||
showList: this.state.pageNum[current] == 1 ? [...list] : [...this.state[STATUS_TO_LIST[current]], ...list], | |||||
}) | |||||
const newPageNum = [...this.state.pageNum] | |||||
newPageNum[current] += 1 | |||||
this.setState({ | |||||
pageNum: newPageNum | |||||
}) | |||||
} | |||||
this.setState({ | |||||
[STATUS_TO_TOTALSIZE[current]]: totalSize, | |||||
[STATUS_TO_TOTALPAGE[current]]: totalPage, | |||||
totalNum: totalSize | |||||
}) | |||||
}).catch(({ errorMsg }) => { | |||||
Taro.$toast(errorMsg) | |||||
}) | |||||
} | |||||
/** | |||||
* 上拉加载更多 | |||||
*/ | |||||
onScrollToLower = () => { | |||||
const { current, tabList, notEnumCscApplyStatus } = this.state | |||||
if (this.state[STATUS_TO_NOMORE[current]]) { | |||||
return | |||||
} | |||||
this._getApplyList(tabList[current].id, notEnumCscApplyStatus) | |||||
} | |||||
handleSearchInput = value => { | |||||
this.setState({ | |||||
searchValue: value | |||||
}) | |||||
} | |||||
handleCancelSearch = () => { | |||||
this.setState( | |||||
{ | |||||
searchValue: '', | |||||
searchObj: {} | |||||
} | |||||
) | |||||
} | |||||
/** | |||||
* 点击 Tab,刷新数据 | |||||
* @param index | |||||
*/ | |||||
handleTabsClick = index => { | |||||
this.handleCancelSearch() | |||||
const searchPlaceholder = | |||||
index == 0 | |||||
? "请输入联系人/联系电话/城市" | |||||
: "请输入联系人/联系电话/城市/状态" | |||||
const dropDownList = index == 0 ? ["联系人", "联系电话", "城市"] : ["联系人", "联系电话", "城市", "状态"] | |||||
const notEnumCscApplyStatus = index == 0 ? '' : 1 | |||||
this.setState( | |||||
{ | |||||
current: index, | |||||
searchValue: "", | |||||
searchObj: {}, | |||||
searchPlaceholder, | |||||
dropDownList, | |||||
notEnumCscApplyStatus | |||||
}, | |||||
() => { | |||||
const { pageNum, tabList, current } = this.state | |||||
const newPageNum = [...pageNum] | |||||
newPageNum[this.state.current] = 1 | |||||
this.setState({ | |||||
pageNum: newPageNum | |||||
}, () => { | |||||
this._getApplyList(tabList[current].id, this.state.notEnumCscApplyStatus) | |||||
}) | |||||
} | |||||
) | |||||
} | |||||
/** | |||||
* 点击驳回通过按钮 | |||||
*/ | |||||
showDialog = (type, id) => { | |||||
this.setState({ | |||||
dialogStatus: type, | |||||
showStatus: 1, | |||||
id | |||||
}) | |||||
} | |||||
/** | |||||
* 关闭弹框 | |||||
*/ | |||||
closeDialog = () => { | |||||
this.setState({ | |||||
showStatus: 0 | |||||
}) | |||||
} | |||||
/** | |||||
* 点击拒绝并通知商户 | |||||
*/ | |||||
handleRefuse = (refuseReason) => { | |||||
const { id } = this.state | |||||
api.handleApply({ | |||||
id, | |||||
refuseReason, | |||||
enumCscApplyStatus: 3 | |||||
}).then((res) => { | |||||
Taro.$toast('驳回成功') | |||||
this.closeDialog() | |||||
const { tabList, current, pageNum, searchObj, notEnumCscApplyStatus } = this.state | |||||
const newPageNum = [...pageNum] | |||||
newPageNum[current] = 1 | |||||
this.setState({ | |||||
searchObj, | |||||
pageNum: newPageNum | |||||
}, () => { | |||||
this._getApplyList(tabList[current].id, notEnumCscApplyStatus) | |||||
}) | |||||
}).catch(({ errorMsg }) => { | |||||
Taro.$toast(errorMsg) | |||||
}) | |||||
} | |||||
/** | |||||
* 点击确认并启用账号 | |||||
*/ | |||||
handlePass = () => { | |||||
const { id } = this.state | |||||
api.handleApply({ | |||||
id, | |||||
enumCscApplyStatus: 2 | |||||
}).then((res) => { | |||||
Taro.$toast('账号已通过并创建成功!') | |||||
this.closeDialog() | |||||
const { tabList, current, pageNum, searchObj, notEnumCscApplyStatus } = this.state | |||||
const newPageNum = [...pageNum] | |||||
newPageNum[current] = 1 | |||||
this.setState({ | |||||
searchObj, | |||||
pageNum: newPageNum | |||||
}, () => { | |||||
this._getApplyList(tabList[current].id, notEnumCscApplyStatus) | |||||
}) | |||||
}).catch(({ errorMsg }) => { | |||||
Taro.$toast(errorMsg) | |||||
}) | |||||
} | |||||
/** | |||||
* 搜索申请列表 | |||||
*/ | |||||
handleSearch = (clickType, clickValue) => { | |||||
this.setState({ | |||||
searchObj: {} | |||||
}, () => { | |||||
if (clickValue == '已驳回') { | |||||
clickValue = 3 | |||||
} else if (clickValue == '已通过') { | |||||
clickValue = 2 | |||||
} | |||||
const { tabList, current, pageNum, notEnumCscApplyStatus } = this.state | |||||
const newSearchObj = { [SEATCH_NAME[clickType]]: clickValue } | |||||
const newPageNum = [...pageNum] | |||||
newPageNum[current] = 1 | |||||
this.setState({ | |||||
searchObj: newSearchObj, | |||||
pageNum: newPageNum | |||||
}, () => { | |||||
this._getApplyList(tabList[current].id, notEnumCscApplyStatus) | |||||
}) | |||||
}) | |||||
} | |||||
render () { | |||||
const { | |||||
searchPlaceholder, | |||||
tabList, | |||||
current, | |||||
totalNum, | |||||
dialogStatus, | |||||
showStatus, | |||||
showList, | |||||
noMore, | |||||
dropDownList, | |||||
searchValue | |||||
} = this.state | |||||
return ( | |||||
<View className='business-management-list_page'> | |||||
<View className='header'> | |||||
<View className='search-wrapper'> | |||||
<SearchBar | |||||
placeholder={searchPlaceholder} | |||||
dropDownList={dropDownList} | |||||
searchValue={searchValue} | |||||
onInput={this.handleSearchInput} | |||||
onCancel={this.handleCancelSearch} | |||||
onClick={this.handleClick} | |||||
onSearch={this.handleSearch} | |||||
onConfirm={this.handleConfirm} | |||||
></SearchBar> | |||||
</View> | |||||
<Tabs | |||||
tabList={tabList} | |||||
current={current} | |||||
onClick={this.handleTabsClick} | |||||
></Tabs> | |||||
<View className='gradient-container'> | |||||
{showList.length !== 0 && <Text>当前总条数:{totalNum}条</Text>} | |||||
</View> | |||||
</View> | |||||
<ApplyList showList={showList} current={current} noMore={noMore} onShowDialog={this.showDialog} onScrollToLower={this.onScrollToLower}> | |||||
</ApplyList> | |||||
<ApplyDialog dialogStatus={dialogStatus} showStatus={showStatus} onClick={this.closeDialog} onRefuse={this.handleRefuse} onPass={this.handlePass}></ApplyDialog> | |||||
<Toast duration={3000}></Toast> | |||||
</View > | |||||
) | |||||
} | |||||
} | |||||
export default Index |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL