12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523 |
- import React, { Component } from 'react';
- import Cropper from 'react-cropper';
- import 'cropperjs/dist/cropper.css';
- import './index.less';
- import { Checkbox, Icon } from 'antd';
- import FileUpload from '@src/components/FileUpload';
- import Assets from '@src/components/Assets';
- import scale from '@src/services/Scale';
- import { asyncSMessage } from '@src/services/AsyncTools';
- import AnswerButton from '../AnswerButton';
- import { SelectInput, VerificationInput, Input } from '../Login';
- import { MobileArea, TextbookFeedbackTarget, TextbookSubject, AskTarget } from '../../../Constant';
- import Invite from '../Invite';
- import Modal from '../Modal';
- import { Common } from '../../stores/common';
- import { User } from '../../stores/user';
- import { My } from '../../stores/my';
- import Select from '../Select';
- import { formatDate, getMap } from '../../../../src/services/Tools';
- const TextbookFeedbackTargetMap = getMap(TextbookFeedbackTarget, 'value', 'tip');
- export class BindPhone extends Component {
- constructor(props) {
- super(props);
- this.validNumber = 0;
- this.props.data = this.props.data || {};
- this.state = Object.assign({ step: 0, data: {}, empty: {} }, this.initState(this.props));
- this.stepProp = {
- 0: {
- title: '绑定手机',
- onConfirm: props.onConfirm,
- },
- 1: {
- title: '绑定手机',
- onConfirm: () => {
- this.submit();
- },
- onCancel: props.onCancel,
- confirmText: '提交',
- },
- };
- }
- initState(props) {
- if (!props.show || this.props.show) return {};
- const data = Object.assign({}, props.data);
- if (!data.area) data.area = MobileArea[0].value;
- return { step: props.data.mobile ? 0 : 1, data, validError: '', empty: {} };
- }
- componentWillReceiveProps(nextProps) {
- this.setState(this.initState(nextProps));
- }
- onNext() {
- this.setState({ step: 1, validError: '', mobileError: '', empty: {} });
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty, mobileError: null });
- }
- validMobile() {
- const { data } = this.state;
- const { area, mobile } = data;
- if (!area || !mobile) return;
- this.validNumber += 1;
- const number = this.validNumber;
- if (mobile === this.props.data.mobile) {
- this.setState({ mobileError: '' });
- return;
- }
- User.validMobile(area, mobile)
- .then(result => {
- if (number !== this.validNumber) return Promise.resolve();
- if (result) {
- this.setState({ mobileError: '' });
- return Promise.resolve();
- }
- return Promise.reject(new Error('该手机已绑定其他账号,请更换手机号码'));
- })
- .catch(err => {
- this.setState({ mobileError: err.message });
- });
- }
- sendValid() {
- const { data, mobileError } = this.state;
- const { area, mobile } = data;
- if (mobileError) return Promise.reject();
- if (!area || !mobile) {
- this.setState({ empty: { area: !data.area, mobile: !data.mobile } });
- return Promise.reject();
- }
- return Common.sendSms(area, mobile)
- .then(result => {
- if (result) {
- asyncSMessage('发送成功');
- this.setState({ mobileError: '', validError: '' });
- } else {
- throw new Error('发送失败');
- }
- })
- .catch(err => {
- this.setState({ mobileError: err.message });
- throw err;
- });
- }
- submit() {
- const { data, validError, mobileError } = this.state;
- if (validError || mobileError) return;
- const { area, mobile, mobileVerifyCode } = data;
- if (!area || !mobile || !mobileVerifyCode) {
- this.setState({ empty: { area: !data.area, mobile: !data.mobile, mobileVerifyCode: !mobileVerifyCode } });
- return;
- }
- My.bindMobile(area, mobile, mobileVerifyCode)
- .then(() => {
- asyncSMessage('操作成功');
- this.setState({ step: 0, validError: '', mobileError: '' });
- User.infoHandle(Object.assign(this.props.data, { area, mobile }));
- this.props.onConfirm();
- })
- .catch(err => {
- if (err.message.indexOf('验证码') >= 0) {
- this.setState({ validError: err.message });
- } else {
- this.setState({ mobileError: err.message });
- }
- });
- }
- render() {
- const { show } = this.props;
- const { step = 0 } = this.state;
- return (
- <Modal className="bind-phone-modal" show={show} width={630} {...this.stepProp[step]}>
- <div className="bind-phone-modal-wrapper">{this[`renderStep${step}`]()}</div>
- </Modal>
- );
- }
- renderStep0() {
- const { data } = this.state;
- return (
- <div className="step-0-layout t-2">
- 已绑定手机 {data.mobile}
- <a onClick={() => this.onNext()}>修改</a>
- </div>
- );
- }
- renderStep1() {
- return (
- <div className="step-1-layout">
- <div className="label">手机号</div>
- <div className="input-layout">
- <SelectInput
- className="w-10"
- placeholder="请输入手机号"
- selectValue={this.state.data.area}
- select={MobileArea}
- value={this.state.data.mobile}
- error={this.state.mobileError}
- empty={this.state.empty.mobile}
- onSelect={value => {
- this.changeData('area', value);
- this.validMobile();
- }}
- onChange={e => {
- this.changeData('mobile', e.target.value);
- this.validMobile();
- }}
- />
- <VerificationInput
- className="w-10"
- placeholder="请输入验证码"
- value={this.state.data.mobileVerifyCode}
- error={this.state.validError}
- empty={this.state.empty.mobileVerifyCode}
- onSend={() => {
- return this.sendValid();
- }}
- onChange={e => {
- this.changeData('mobileVerifyCode', e.target.value);
- this.setState({ validError: '' });
- }}
- />
- </div>
- </div>
- );
- }
- }
- export class BindEmail extends Component {
- constructor(props) {
- super(props);
- this.validNumber = 0;
- this.props.data = this.props.data || {};
- this.state = Object.assign({ step: 0, data: {}, empty: {} }, this.initState(this.props));
- this.stepProp = {
- 0: {
- title: '绑定邮箱',
- onConfirm: props.onConfirm,
- },
- 1: {
- title: '绑定邮箱',
- onConfirm: () => {
- this.submit();
- },
- onCancel: props.onCancel,
- confirmText: '提交',
- },
- };
- }
- initState(props) {
- if (!props.show || this.props.show) return {};
- return { step: props.data.email ? 0 : 1, data: Object.assign({}, props.data) };
- }
- componentWillReceiveProps(nextProps) {
- this.setState(this.initState(nextProps));
- }
- onNext() {
- this.setState({ step: 1, error: '', empty: {} });
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty, error: null });
- }
- validEmail() {
- const { data } = this.state;
- const { email } = data;
- if (!email) return;
- this.validNumber += 1;
- const number = this.validNumber;
- if (email === this.props.data.email) {
- this.setState({ error: '' });
- return;
- }
- User.validEmail(email)
- .then(result => {
- if (number !== this.validNumber) return Promise.resolve();
- if (result) {
- this.setState({ error: '' });
- return Promise.resolve();
- }
- return Promise.reject(new Error('该邮箱已绑定其他账号,请更换邮箱地址'));
- })
- .catch(err => {
- this.setState({ error: err.message });
- });
- }
- submit() {
- const { data, error } = this.state;
- if (error) return;
- if (!data.email) {
- this.setState({ empty: { email: !data.email } });
- return;
- }
- const { email } = data;
- My.bindEmail(email)
- .then(() => {
- asyncSMessage('操作成功');
- this.setState({ step: 0, error: '' });
- User.infoHandle(Object.assign(this.props.data, { email }));
- this.props.onConfirm();
- })
- .catch(e => {
- this.setState({ error: e.message });
- });
- }
- render() {
- const { show } = this.props;
- const { step = 0 } = this.state;
- return (
- <Modal className="bind-email-modal" show={show} width={630} {...this.stepProp[step]}>
- <div className="bind-email-modal-wrapper">{this[`renderStep${step}`]()}</div>
- </Modal>
- );
- }
- renderStep0() {
- const { data } = this.state;
- return (
- <div className="step-0-layout t-2">
- 已绑定邮箱 {data.email}
- <a onClick={() => this.onNext()}>修改</a>
- </div>
- );
- }
- renderStep1() {
- return (
- <div className="step-1-layout">
- <div className="label">邮箱地址</div>
- <div className="input-layout">
- <Input
- className="w-10"
- placeholder="请输入邮箱"
- value={this.state.data.email}
- error={this.state.error}
- empty={this.state.empty.email}
- onChange={e => {
- this.changeData('email', e.target.value);
- this.validEmail();
- }}
- />
- </div>
- </div>
- );
- }
- }
- export class EditInfo extends Component {
- constructor(props) {
- super(props);
- this.props.data = this.props.data || {};
- this.state = Object.assign({ data: {}, empty: {} }, this.initState(this.props));
- }
- initState(props) {
- if (props.image && this.waitImage) {
- const { state } = this;
- Common.upload(props.image)
- .then(result => {
- const { data } = this.state;
- data.avatar = result.url;
- this.setState({ data, uploading: false });
- })
- .catch(e => {
- this.setState({ imageError: e.message });
- });
- state.uploading = true;
- this.waitImage = false;
- return state;
- }
- if (!props.show || this.props.show) return {};
- return { data: Object.assign({}, props.data) };
- }
- componentWillReceiveProps(nextProps) {
- this.setState(this.initState(nextProps));
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty, nicknameError: null });
- }
- submit() {
- const { data, nicknameError } = this.state;
- if (nicknameError) return;
- if (!data.nickname) {
- this.setState({ empty: { nickname: !data.nickname } });
- return;
- }
- if (data.nickname.length < 2 || data.nickname.length > 14) {
- this.setState({ nicknameError: '用户名长度不足2个自负或超过14个字符' });
- return;
- }
- const { nickname, avatar } = data;
- My.editInfo({ nickname, avatar })
- .then(() => {
- asyncSMessage('操作成功');
- User.infoHandle(Object.assign(this.props.data, { nickname, avatar }));
- this.props.onConfirm();
- this.setState({ nicknameError: '' });
- })
- .catch(e => {
- this.setState({ nicknameError: e.message });
- });
- }
- render() {
- const { show, onCancel, onSelectImage } = this.props;
- return (
- <Modal
- className="edit-info-modal"
- show={show}
- width={630}
- title="修改资料"
- confirmText="保存"
- onCancel={onCancel}
- onConfirm={() => {
- this.submit();
- }}
- >
- <div className="edit-info-modal-wrapper">
- <div className="edit-info-modal-block">
- <div className="label">用户名</div>
- <div className="input-layout">
- <Input
- className="w-10"
- placeholder="2-14个字符。"
- value={this.state.data.nickname || ''}
- error={this.state.nicknameError}
- empty={this.state.empty.nickname}
- onChange={e => {
- this.changeData('nickname', e.target.value);
- }}
- />
- </div>
- </div>
- <div className="edit-info-modal-block">
- <div className="label">头像</div>
- <div className="input-layout">
- <FileUpload
- uploading={this.state.uploading}
- value={this.state.data.avatar}
- onUpload={({ file }) => {
- this.waitImage = true;
- onSelectImage(file);
- return Promise.reject();
- }}
- />
- {this.state.imageError || ''}
- </div>
- </div>
- </div>
- </Modal>
- );
- }
- }
- export class RealAuth extends Component {
- constructor(props) {
- super(props);
- this.state = { data: {} };
- }
- render() {
- const { show, onConfirm } = this.props;
- return (
- <Modal
- className="real-auth-modal"
- show={show}
- width={630}
- title="实名认证"
- confirmText="好的,知道了"
- btnAlign="center"
- onConfirm={onConfirm}
- >
- <div className="real-auth-modal-wrapper">
- <div className="real-auth-text">
- <div className="t1">完成实名认证即可领取:</div>
- <div className="t2">6个月VIP权限 和 5折机经优惠劵。</div>
- <div className="t3">扫码关注公众号,点击“我的-实名认证”</div>
- </div>
- <div className="real-auth-qrcode">
- <Assets name="qrcode" />
- </div>
- </div>
- </Modal>
- );
- }
- }
- export class EditAvatar extends Component {
- constructor(props) {
- super(props);
- this.state = Object.assign({ data: {} }, this.initState(this.props));
- }
- initState(props) {
- if (props.image) this.loadImage(props.image);
- if (!props.show || this.props.show) return {};
- return { data: {} };
- }
- componentWillReceiveProps(nextProps) {
- this.setState(this.initState(nextProps));
- }
- loadImage(file) {
- this.defaultZoomValue = 1;
- if (window.FileReader) {
- const reader = new FileReader();
- reader.readAsDataURL(file);
- // 渲染文件
- reader.onload = arg => {
- this.setState({ image: arg.target.result, fileName: file.name, zoomValue: 1 });
- };
- } else {
- const img = new Image();
- img.onload = function () {
- const canvas = document.createElement('canvas');
- canvas.height = img.height;
- canvas.width = img.width;
- const ctx = canvas.getContext('2d');
- ctx.drawImage(img, 0, 0);
- this.setState({ image: canvas.toDataURL() });
- };
- img.src = '1.gif';
- }
- }
- computerZoom() {
- const data = this.cropRef.getImageData();
- this.defaultZoomValue = 200 / parseFloat(Math.max(data.naturalWidth, data.naturalHeight));
- }
- crop() {
- // image in dataUrl
- // console.log(this.cropRef.getCroppedCanvas().toDataURL())
- // const canvas = this.cropRef.getCroppedCanvas();
- // const avatar = scale(this.props.crop, canvas, 'png-src');
- // let scaleCanvas = this.cropRef.getCroppedCanvas(this.props.crop)
- // this.setState({ avatar });
- }
- select() {
- const { fileName } = this.state;
- const { onConfirm } = this.props;
- const canvas = this.cropRef.getCroppedCanvas();
- const scaleCanvas = scale(this.props.crop, canvas);
- // let scaleCanvas = this.cropRef.getCroppedCanvas(this.props.crop)
- scaleCanvas.toBlob(blob => {
- const file = new File([blob], fileName);
- onConfirm(file);
- });
- }
- render() {
- const { show, onCancel } = this.props;
- const { image } = this.state;
- return (
- <Modal
- className="edit-avatar-modal"
- show={show}
- width={630}
- title="调整头像"
- confirmText="保存头像"
- onConfirm={() => {
- this.select();
- }}
- onCancel={onCancel}
- >
- <div className="edit-avatar-modal-wrapper">
- <div className="edit-avatar-o">
- <Cropper
- ref={ref => {
- this.cropRef = ref;
- }}
- src={image}
- ready={() => {
- this.computerZoom();
- }}
- style={{ height: 360, width: 360 }}
- // Cropper.js options
- aspectRatio={1}
- viewMode={0}
- // autoCropArea={0.8}
- preview=".img-preview"
- // dragMode='move'
- guides={false}
- movable={false}
- rotatable={false}
- scalable={false}
- // zoom={(value) => {
- // console.log('zoom', value);
- // const zoomValue = value * this.defaultZoomValue / 50;
- // this.cropRef.zoomTo(zoomValue);
- // }}
- cropmove={() => {
- this.crop();
- }}
- toggleDragModeOnDblclick={false}
- cropBoxResizable
- />
- </div>
- <div className="edit-avatar-r">
- <div className="text">头像预览</div>
- <div className="img-preview" style={{ width: 100, height: 100, overflow: 'hidden' }} />
- </div>
- </div>
- </Modal>
- );
- }
- }
- export class InviteModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: {} };
- }
- render() {
- const { show, onClose, data } = this.props;
- return (
- <Modal className="invite-modal" show={show} width={630} title="邀请好友" onClose={onClose}>
- <div className="invite-modal-wrapper">
- <div className="tip">每邀请一位小伙伴加入“千行GMAT”, 您的VIP权限会延长7天,可累加 无上限!赶紧行动吧~</div>
- <Invite data={data} />
- </div>
- </Modal>
- );
- }
- }
- // 模考选择下载
- export class DownloadModal extends Component {
- constructor(props) {
- super(props);
- this.state = { checkMap: {} };
- }
- onConfirm() {
- const { onConfirm, data } = this.props;
- if (onConfirm) onConfirm();
- const { checkMap } = this.state;
- Object.keys(checkMap).forEach(key => {
- if (!checkMap[key]) return;
- const link = data[`${key}`];
- if (link) {
- openLink(link);
- }
- });
- this.setState({ checkList: [] });
- }
- render() {
- const { show, data = {}, onCancel } = this.props;
- const { checkMap = {} } = this.state;
- const quantVersion = data.quantVersion || 0;
- const irVersion = data.irVersion || 0;
- const rcVersion = data.rcVersion || 0;
- return (
- <Modal
- className="download-modal"
- show={show}
- width={570}
- title="下载"
- confirmText="下载"
- onConfirm={() => this.onConfirm()}
- onCancel={onCancel}
- >
- <div className="download-modal-wrapper">
- <div className="t-2 t-s-18 m-b-1">请选择下载科目</div>
- <div className="m-b-1">
- {quantVersion > 0 && (
- <div className="t-2 t-s-16">
- <Checkbox
- checked={checkMap.quant}
- onChange={() => {
- checkMap.quant = !checkMap.quant;
- this.setState({ checkMap });
- }}
- />
- <span className="m-l-5">数学</span>
- <span className="t-8">
- (版本{quantVersion} 最后更新:{formatDate(data.quantTime, 'YYYY-MM-DD HH:mm:ss')})
- </span>
- </div>
- )}
- {irVersion > 0 && (
- <div className="t-2 t-s-16">
- <Checkbox
- checked={checkMap.ir}
- onChange={() => {
- checkMap.ir = !checkMap.ir;
- this.setState({ checkMap });
- }}
- />
- <span className="m-l-5">逻辑</span>
- <span className="t-8">
- (版本{irVersion} 最后更新:{formatDate(data.irTime, 'YYYY-MM-DD HH:mm:ss')})
- </span>
- </div>
- )}
- {rcVersion > 0 && (
- <div className="t-2 t-s-16">
- <Checkbox
- checked={checkMap.rc}
- onChange={() => {
- checkMap.rc = !checkMap.rc;
- this.setState({ checkMap });
- }}
- />
- <span className="m-l-5">阅读</span>
- <span className="t-8">
- (版本{rcVersion} 最后更新:{formatDate(data.rcTime, 'YYYY-MM-DD HH:mm:ss')})
- </span>
- </div>
- )}
- </div>
- </div>
- </Modal>
- );
- }
- }
- // 模考开通确认
- export class OpenConfirmModal extends Component {
- render() {
- const { show, onConfirm, onCancel, data = {} } = this.props;
- return (
- <Modal
- className="open-confirm-modal"
- show={show}
- width={570}
- title="开通确认"
- confirmText="开通"
- cancelText="暂不开通"
- onConfirm={onConfirm}
- onCancel={onCancel}
- >
- <div className="open-confirm-modal-wrapper m-b-2">
- <div className="t-2 t-s-18">您正在开通「{data.title}」。</div>
- <div className="t-2 t-s-18">模考有效期至:{data.endTime && formatDate(data.endTime, 'YYYY-MM-DD')}</div>
- </div>
- </Modal>
- );
- }
- }
- // 模考重置确认
- export class RestartConfirmModal extends Component {
- render() {
- const { show, onConfirm, onCancel } = this.props;
- return (
- <Modal
- className="restart-confirm-modal"
- show={show}
- width={570}
- title="重置确认"
- confirmText="立即重置"
- cancelText="暂不重置"
- onConfirm={onConfirm}
- onCancel={onCancel}
- >
- <div className="restart-confirm-modal-wrapper m-b-2">
- <div className="t-2 t-s-18">重置后,可进行新一轮的模考。 </div>
- <div className="t-2 t-s-18 m-b-2">本轮模考的成绩和报告可在本页面或「我的报告」查看。 </div>
- <div className="t-2 t-s-18 m-b-1">只有 1 次重置机会。</div>
- </div>
- </Modal>
- );
- }
- }
- export class FeedbackErrorDataModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: { position: ['', '', ''], content: '', originContent: '' } };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- changeDataIndex(field, index, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field][index] = value;
- if (value) empty[`${field}[${index}]`] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { onConfirm } = this.props;
- const { data } = this.state;
- if (!data.position[0] || !data.position[1] || !data.position[2] || !data.content || !data.originContent) {
- this.setState({
- empty: {
- 'position[0]': !data.position[0],
- 'position[1]': !data.position[1],
- 'position[2]': !data.position[2],
- content: !data.content,
- originContent: !data.originContent,
- },
- });
- return Promise.reject();
- }
- return My.addFeedbackErrorData(
- data.dataId,
- data.title,
- data.position.join(','),
- data.originContent,
- data.content,
- ).then(() => {
- this.setState({ data: { position: ['', '', ''], content: '', originContent: '' } });
- if (onConfirm) onConfirm();
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { position: ['', '', ''], content: '', originContent: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show } = this.props;
- const { data, empty = {} } = this.state;
- return (
- <Modal
- show={show}
- title="纠错"
- btnType="link"
- width={630}
- onConfirm={() => this.onConfirm()}
- onCancel={() => this.onCancel()}
- >
- <div className="t-2 m-b-1 t-s-16">
- 定位:
- <input
- value={data.position[0]}
- className="t-c b-c-1 m-r-5"
- style={{ width: 56 }}
- empty={empty['position[0]']}
- onChange={e => {
- this.changeDataIndex('position', 0, e.target.value);
- }}
- />
- <span className="require">页</span>
- <input
- value={data.position[1]}
- className="t-c b-c-1 m-r-5"
- style={{ width: 56 }}
- empty={empty['position[1]']}
- onChange={e => {
- this.changeDataIndex('position', 1, e.target.value);
- }}
- />
- <span className="require">行</span> , 题号
- <input
- value={data.position[2]}
- className="t-c b-c-1"
- style={{ width: 56 }}
- empty={empty['position[2]']}
- onChange={e => {
- this.changeDataIndex('position', 2, e.target.value);
- }}
- />
- </div>
- <div className="t-2 t-s-16">错误内容是:</div>
- <textarea
- value={data.originContent}
- className="b-c-1 w-10 p-10"
- rows={10}
- placeholder={'可简单描述您发现的问题'}
- empty={empty.originContent}
- onChange={e => {
- this.changeData('originContent', e.target.value);
- }}
- />
- <div className="t-2 t-s-16">应该更改为:</div>
- <textarea
- value={data.content}
- className="b-c-1 w-10 p-10"
- rows={10}
- placeholder={'提供您认为正确的内容即可'}
- empty={empty.content}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class AskCourseModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: { position: [], content: '', originContent: '' } };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { course, courseNo, onConfirm } = this.props;
- const { data } = this.state;
- if (!data.content || !data.originContent) {
- this.setState({ empty: { content: !data.content, originContent: !data.originContent } });
- return Promise.reject();
- }
- return My.addCourseAsk(course.id, courseNo.id, data.position.join(','), data.originContent, data.content).then(
- () => {
- this.setState({ data: { position: [], content: '', originContent: '' } });
- if (onConfirm) onConfirm();
- },
- );
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { position: [], content: '', originContent: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show, selectList, courseNo, getContainer } = this.props;
- const { data, empty = {} } = this.state;
- return (
- <Modal
- show={show}
- title="提问"
- btnType="link"
- width={630}
- getContainer={getContainer}
- confirmText="提交"
- onConfirm={() => this.onConfirm()}
- onCancel={() => this.onCancel()}
- >
- <div className="t-2 m-b-1 t-s-16">
- 针对<span className="t-4">课时{courseNo.no}</span>的{' '}
- <Select
- value={data.position}
- theme="white"
- list={selectList}
- onChange={item => {
- this.changeData('position', item.key);
- }}
- />
- 进行提问.
- </div>
- <div className="t-2 t-s-16">老师讲解的内容是:</div>
- <textarea
- value={data.originContent}
- className="b-c-1 w-10 p-10"
- rows={4}
- placeholder={'请简单描述,以便老师准确定位。'}
- empty={empty.originContent}
- onChange={e => {
- this.changeData('originContent', e.target.value);
- }}
- />
- <div className="t-2 t-s-16">您的问题是:</div>
- <textarea
- value={data.content}
- className="b-c-1 w-10 p-10"
- rows={4}
- placeholder={'老师会在n小时内回答你的问题。'}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class CourseNoteModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: { content: '' } };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { course, onConfirm } = this.props;
- const { data } = this.state;
- if (!data.content || !data.originContent) {
- this.setState({ empty: { content: !data.content } });
- return Promise.reject();
- }
- return My.updateCourseNote(course.id, data.courseNoId, data.content).then(() => {
- this.setState({ data: { content: '' } });
- if (onConfirm) onConfirm();
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { content: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show, course = {}, courseNos = [], noteMap = {}, getContainer } = this.props;
- const { data, empty = {} } = this.state;
- return (
- <Modal
- show={show}
- title="笔记"
- width={630}
- getContainer={getContainer}
- confirmText="提交"
- onConfirm={() => this.onConfirm()}
- onCancel={() => this.onCancel()}
- >
- <div className="t-2 m-b-1 t-s-16">
- {course.title}
- <Select
- theme="white"
- value={data.courseNoId}
- list={courseNos.map(row => {
- return {
- title: `课时${row.no}`,
- key: row.id,
- };
- })}
- onChange={item => {
- if (data.courseNoId !== item.key) {
- data.courseNoId = item.key;
- data.content = noteMap[item.key] ? noteMap[item.key].content : '';
- }
- this.setState({ data });
- }}
- />
- </div>
- <textarea
- value={data.content}
- className="b-c-1 w-10 p-10"
- rows={10}
- placeholder={'写下笔记,方便以后复习。'}
- empty={empty.content}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class TextbookFeedbackModal extends Component {
- constructor(props) {
- super(props);
- this.state = {
- data: { content: '' },
- targetList: TextbookFeedbackTarget.map(row => {
- return {
- title: row.label,
- key: row.value,
- };
- }),
- textbookSubject: TextbookSubject.map(row => {
- return {
- title: row.label,
- key: row.value,
- };
- }),
- };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { onConfirm } = this.props;
- const { data } = this.state;
- if (data.target !== 'new' && (!data.no || !data.content)) {
- this.setState({ empty: { content: !data.content, no: !data.no } });
- return Promise.reject();
- }
- if (!data.content) {
- this.setState({ empty: { content: !data.content } });
- return Promise.reject();
- }
- return My.addTextbookFeedback(data.textbookSubject, data.target, data.no, data.content)
- .then(() => {
- this.setState({ data: { content: '' } });
- if (onConfirm) onConfirm();
- })
- .catch(e => {
- asyncSMessage(e.message, 'error');
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { content: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show } = this.props;
- const { data, targetList, textbookSubject, empty = {} } = this.state;
- return (
- <Modal show={show} title="反馈" width={630} onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
- <div className="t-2 t-s-16 m-b-1">
- 机经类别:{' '}
- <Select
- value={data.textbookSubject}
- theme="white"
- list={textbookSubject}
- onChange={value => {
- data.textbookSubject = value;
- this.setState({ data });
- }}
- />
- 反馈类型:{' '}
- <Select
- value={data.target}
- theme="white"
- list={targetList}
- onChange={({ key }) => {
- data.target = key;
- this.setState({ data });
- }}
- />
- <span hidden={data.target === 'new'}>
- {' '}
- 题号是{' '}
- <input
- value={data.no}
- style={{ width: 80 }}
- className="m-l-1 b-c-1 t-c"
- empty={empty.no}
- onChange={e => {
- this.changeData('no', e.target.value);
- }}
- />
- </span>
- </div>
- <div className="t-2 t-s-16">{TextbookFeedbackTargetMap[data.target]}:</div>
- <textarea
- value={data.content}
- className="b-c-1 w-10 p-10"
- rows={10}
- placeholder={TextbookFeedbackTargetMap[data.target]}
- empty={empty.content}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class FaqModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: { content: '' } };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.defaultData && nextProps.show) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { onConfirm } = this.props;
- const { data } = this.state;
- if (!data.content) {
- this.setState({ empty: { content: !data.content } });
- return Promise.reject();
- }
- return My.addFaq(data.channel, data.position, data.content).then(() => {
- this.setState({ data: { content: '' } });
- if (onConfirm) onConfirm();
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { content: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show } = this.props;
- const { data, empty = {} } = this.state;
- return (
- <Modal show={show} title="咨询" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
- <textarea
- className="b-c-1 w-10 p-10"
- value={data.content}
- rows={6}
- placeholder="请输入您的问题!"
- empty={empty.content}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class CommentModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: { content: '' } };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { onConfirm } = this.props;
- const { data } = this.state;
- if (!data.content) {
- this.setState({ empty: { content: !data.content } });
- return Promise.reject();
- }
- return My.addComment(data.channel, data.position, data.content).then(() => {
- this.setState({ data: { content: '' } });
- if (onConfirm) onConfirm();
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { content: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show } = this.props;
- const { data, empty = {} } = this.state;
- return (
- <Modal show={show} title="评价" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
- <textarea
- value={data.content}
- className="b-c-1 w-10 p-10"
- rows={6}
- placeholder="您的看法对我们来说很重要!"
- empty={empty.content}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class FinishModal extends Component {
- render() {
- const { show, onConfirm } = this.props;
- return (
- <Modal show={show} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => onConfirm()}>
- <div className="t-2 t-s-18">
- <Icon type="check" className="t-5 m-r-5" />
- 您的每一次反馈都是千行进步的动力。
- </div>
- </Modal>
- );
- }
- }
- export class SuppleModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: { content: '' } };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm() {
- const { onConfirm } = this.props;
- const { data } = this.state;
- if (!data.content) {
- this.setState({ empty: { content: !data.content } });
- return Promise.reject();
- }
- return My.addRoomFeedback(data.roomId, data.content).then(() => {
- this.setState({ data: { content: '' } });
- if (onConfirm) onConfirm();
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { content: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show, info = {} } = this.props;
- const { data, empty = {} } = this.state;
- return (
- <Modal show={show} title="考场信息" onConfirm={() => this.onConfirm()} onCancel={() => this.onCancel()}>
- <div className="t-2 t-s-16">
- 考场位置: {info.isOverseas ? '海外' : '中国'}
- {info.area ? ` ${info.area}` : ''} {info.title}
- </div>
- <div className="t-2 t-s-16">补充内容:</div>
- <textarea
- value={data.content}
- className="b-c-1 w-10 p-10"
- empty={empty.content}
- rows={6}
- onChange={e => {
- this.changeData('content', e.target.value);
- }}
- />
- <div className="b-b m-t-2" />
- </Modal>
- );
- }
- }
- export class SuppleFinishModal extends Component {
- render() {
- const { show, onConfirm } = this.props;
- return (
- <Modal show={show} title="提交成功" confirmText="好的,知道了" btnAlign="center" onConfirm={() => onConfirm()}>
- <div className="t-2 t-s-18">
- <Icon type="check" className="t-5 m-r-5" />
- 内容将在审核通过后发布,感谢您的参与。
- </div>
- </Modal>
- );
- }
- }
- export class QuestionNoteModal extends Component {
- constructor(props) {
- super(props);
- this.state = { data: {}, noteField: AskTarget[0].value };
- }
- componentWillReceiveProps(nextProps) {
- if (nextProps.show && nextProps.defaultData) {
- this.setState({ data: Object.assign({}, nextProps.defaultData, this.state.data) });
- }
- }
- changeData(field, value) {
- let { data, empty } = this.state;
- data = data || {};
- empty = empty || {};
- data[field] = value;
- if (value) empty[field] = !value;
- this.setState({ data, empty });
- }
- onConfirm(close) {
- const { questionNo, onConfirm } = this.props;
- const { data } = this.state;
- return My.updateQuestionNote(questionNo.id, data).then(() => {
- if (close) {
- this.setState({ data: {}, noteField: AskTarget[0].value });
- if (onConfirm) onConfirm();
- }
- });
- }
- onCancel() {
- const { onCancel } = this.props;
- this.setState({ data: { content: '' } });
- if (onCancel) onCancel();
- }
- render() {
- const { show } = this.props;
- const { data, noteField } = this.state;
- return (
- <div hidden={!show} className="question-modal note">
- <div className="mask" />
- <div className="body">
- <div className="title">提问</div>
- <div className="content">
- <div className="tabs">
- {AskTarget.map(item => {
- return (
- <div
- className={`tab ${noteField === item.key ? 'active' : ''}`}
- onClick={() => {
- this.setState({ noteField: item.key });
- }}
- >
- <div className="text">{item.label}</div>
- <div className="date">{data[`${item.key}Time`] ? formatDate(data[`${item.key}Time`]) : ''}</div>
- </div>
- );
- })}
- </div>
- <div className="input">
- <textarea
- className="textarea"
- value={data[`${noteField}Content`] || ''}
- placeholder="记下笔记,方便以后复习"
- onChange={e => {
- data[`${noteField}Time`] = new Date();
- data[`${noteField}Content`] = e.target.value;
- this.setState({ data });
- }}
- />
- <div className="bottom">
- <AnswerButton
- theme="cancel"
- size="lager"
- onClick={() => {
- this.onCancel();
- }}
- >
- 取消
- </AnswerButton>
- <AnswerButton
- size="lager"
- onClick={() => {
- this.onConfirm();
- }}
- >
- 编辑
- </AnswerButton>
- <AnswerButton
- size="lager"
- onClick={() => {
- this.onConfirm(true);
- }}
- >
- 保存
- </AnswerButton>
- </div>
- </div>
- </div>
- </div>
- </div>
- );
- }
- }
|