Background.js
3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Component } from 'react';
import { connect } from 'dva';
import { Tabs,Toast } from 'antd-mobile';
import shareHide from "../../utils/shareHide";
import css from './css.less';
class Background extends Component{
constructor(props) {
super(props);
this.state = {
templatesList:[],
backgroudTemp:{},//选中的背景
current:0,
loadingFlag:true,
}
}
componentDidMount() {
Toast.loading('loading...',0)
document.title = '选择背景';
let _this = this;
shareHide();
let cardInfo = JSON.parse(sessionStorage.getItem("cardInfo"));
let backgroudId = cardInfo.cardBackground;//已选择的背景
//获取名片背景列表
this.props.dispatch({
type: 'BusinessCard/GetCardBackgroundTmpsList',
payload: {},
callback(res) {
let current = _this.state.current;
if(res && res.length>0){
for(let ii in res){
if(res[ii].id == backgroudId){
current = Number(ii);
break;
}
}
}
_this.setState({
templatesList:res || [],
current:current,
backgroudTemp:res[current],
loadingFlag:false
})
Toast.hide();
}
})
}
confirmOk = () => {
let _this = this;
let bgdid = this.state.backgroudTemp.id;
let cardInfo = JSON.parse(sessionStorage.getItem("cardInfo"));
let userId = cardInfo.id || JSON.parse(localStorage.getItem("id"));
this.props.dispatch({
type: 'BusinessCard/UpdateBusinessCardInfo',
payload: {
id:userId,
cardBackground:bgdid,
},
callback(res) {
_this.props.history.go(-1);
}
})
}
handleSelect = (index,item)=>{
this.setState({
current:index,
backgroudTemp:item
})
}
render() {
let {templatesList,current} = this.state;
if(this.state.loadingFlag){
return <div></div>
}
return (
<div className={css.bgdtemplate}>
{
templatesList.length>0 ? (
<div>
<div className={css.bgdSection}>
{
templatesList.map((item,index)=>{
return(
<div className={css.bgdItem} key={item.id} onClick={()=>{this.handleSelect(index,item)}}>
<img className={css.bgdImg} src={item.backgroundPath} alt="" />
{current === index ? <img className={css.selected} src={require("../../assets/image/selected_white.png")} /> : ""}
</div>
)
})
}
</div>
<div className={css.footerBtn} onClick={()=>{this.confirmOk()}}>
<img src={require("../../assets/image/queding.png")} alt="" />
</div>
</div>
) : (
<div className={css.haveNoData}>
<img src={require('../../assets/image/clientless.png')} alt="" />
<div className={css.text}>暂无背景</div>
</div>
)
}
</div>
)
}
}
export default connect()(Background);