| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import Taro, { Component } from '@tarojs/taro'
- import { View, Input, Picker, ScrollView, Button } from '@tarojs/components'
- import { Loading } from '@components'
- import { connect } from '@tarojs/redux'
- import * as actions from '@actions/template'
- import TemplateList from './templatelist'
- import { getWindowHeight } from '@utils/style'
- import './template.scss'
- @connect(state => state.home, { ...actions, })
- class Template extends Component {
- config = {
- navigationBarTitleText: '模板管理'
- }
- state = {
- loaded: false,
- loading: false,
- lastItemId: 0,
- hasMore: true,
- selectorChecked: { id: 0, key: "按模板名称", value: 'title' },
- selector: [
- { id: 0, key: "按模板名称", value: 'title' },
- { id: 1, key: "按标签", value: 'tags' },],
- keyword: "",
- dataList: [],
- }
- componentDidMount() {
- this.getData()
- }
- // 列表数据
- getData = () => {
- this.setState({ loading: true })
- let payload = {
- field: this.state.selectorChecked.value,
- keyword: this.state.keyword,
- }
- this.props.getList(payload).then((data) => {
- this.setState({
- loading: false,
- dataList: data.items,
- })
- }).catch(() => {
- this.setState({ loading: false })
- })
- }
- // 删除模板
- deleteTemplate = (value) => {
- let payload = {
- id: value.id,
- }
- this.props.deleteTemplate(payload).then((data) => {
- this.setState({
- loading: false,
- })
- Taro.showToast({
- title: "操作成功",
- icon: 'none'
- })
- this.getData()
- }).catch(() => {
- this.setState({ loading: false })
- })
- }
- onChange = e => {
- this.setState({
- selectorChecked: this.state.selector[e.detail.value],
- })
- }
- onInput = e => {
- this.setState({
- keyword: e.detail.value
- })
- }
- render() {
- // if (!this.state.loaded) {
- // return <Loading />
- // }
- const { } = this.props
- return (
- <View className='home'>
- <View className='home_head'>
- <Picker
- mode='selector'
- range={this.state.selector}
- rangeKey="key"
- value={this.state.selectorChecked.id}
- onChange={this.onChange}>
- <View className='picker'>
- {this.state.selectorChecked.key} ▼
- </View>
- </Picker>
- <Input className='input' type='text' placeholder='请输入关键词进行查询' onInput={this.onInput} />
- <View className='button'
- onClick={() => {
- this.page = 1
- this.getData()
- }}
- >搜索</View>
- </View>
- <ScrollView
- scrollY
- className='home__wrap'
- onScrollToLower={this.getData}
- style={{ height: (getWindowHeight().substring(0, getWindowHeight().length - 2) - 55) + "px" }}
- >
- <TemplateList list={this.state.dataList} deleteTemplate={(e) => { this.deleteTemplate(e) }} />
- </ScrollView>
- </View>
- )
- }
- }
- export default Template
|