index.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. import { Component } from "react";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import { AtInput } from "taro-ui";
  4. import "./index.less";
  5. import aliPayIcon from "../../../images/aliPayIcon.png";
  6. import { get_my_worker_info, worker_register, card_ocr } from "../../../service/money_api";
  7. import Taro from '@tarojs/taro';
  8. export default class Index extends Component {
  9. state = {
  10. name: "", // 账户姓名
  11. account: "", // 支付宝账户
  12. phone: "", // 手机号
  13. idCard: "", // 身份证号
  14. bankCard: "", // 银行卡号
  15. idCardFront: "https://video-img.fyshark.com/1735011631991upload-background-front.11d37038.png", // 身份证正面
  16. idCardBack: "https://video-img.fyshark.com/1735011647149upload-background-back.5b42ae0e.png", // 身份证反面
  17. type: "alipay", // 类型
  18. phoneError: false, // 手机号格式错误标志
  19. isLoading: false, // 是否加载中
  20. isAlipay: false, // 是否已绑定支付宝
  21. isBank: false, // 是否已绑定银行卡
  22. signImg: "https://video-img.fyshark.com/1735033624483%E5%B7%B2%E7%AD%BE%E7%BA%A6.png", // 签约码
  23. };
  24. componentDidMount () {
  25. this.getWorkerInfo(); // 页面加载时请求签约信息
  26. }
  27. // 获取签约信息
  28. getWorkerInfo = async () => {
  29. const res = await get_my_worker_info();
  30. if (res.data.length > 0) {
  31. res.data.forEach(item => {
  32. if (item.rsv_account_type === 1) {
  33. this.setState({
  34. name: item.name,
  35. idCard: item.card_no,
  36. phone: item.phone,
  37. idCardFront: item.portrait_page,
  38. idCardBack: item.national_emblem_page,
  39. account: item.bank_no,
  40. isAlipay: true
  41. });
  42. } else {
  43. this.setState({
  44. name: item.name,
  45. idCard: item.card_no,
  46. phone: item.phone,
  47. idCardFront: item.portrait_page,
  48. idCardBack: item.national_emblem_page,
  49. bankCard: item.bank_no,
  50. isBank: true
  51. });
  52. }
  53. });
  54. }
  55. console.log(res, 'res');
  56. }
  57. // 账户姓名
  58. handleChangeName (value) {
  59. this.setState({ name: value });
  60. }
  61. // 支付宝账户
  62. handleChangeAccount (value) {
  63. this.setState({ account: value });
  64. }
  65. // 手机号
  66. handleChangePhone (value) {
  67. this.setState({ phone: value });
  68. }
  69. // 身份证号
  70. handleChangeIdCard (value) {
  71. this.setState({ idCard: value });
  72. }
  73. // 银行卡号
  74. handleChangeBankCard (value) {
  75. this.setState({ bankCard: value });
  76. }
  77. handleChooseImage (type) {
  78. if (this.isBind()) return;
  79. Taro.chooseImage({
  80. count: 1, // 选择一张图片
  81. sizeType: ['compressed'], // 可以指定是原图还是压缩图
  82. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机
  83. success: (res) => {
  84. const filePath = res.tempFilePaths[0];
  85. Taro.showLoading({
  86. title: '上传中...',
  87. mask: true
  88. });
  89. Taro.uploadFile({
  90. url: 'https://api.yushixcx.com/money/upload', // 上传接口地址
  91. filePath: filePath,
  92. name: 'file',
  93. header: {
  94. 'accept': 'application/json',
  95. 'Content-Type': 'multipart/form-data'
  96. },
  97. formData: {
  98. 'type': 'image/png' // 根据需要设置文件类型
  99. },
  100. success: async (uploadRes) => {
  101. const data = JSON.parse(uploadRes.data);
  102. if (type === 'front') {
  103. this.setState({ idCardFront: data.url });
  104. let that = this;
  105. await card_ocr({
  106. img_url: data.url
  107. }).then(res => {
  108. console.log(res, 'res111');
  109. let info = JSON.parse(res.data);
  110. that.setState({ idCard: info.card_no, name: info.name });
  111. })
  112. } else if (type === 'back') {
  113. this.setState({ idCardBack: data.url });
  114. }
  115. // 隐藏加载提示
  116. Taro.hideLoading();
  117. }
  118. });
  119. }
  120. });
  121. }
  122. // 提交
  123. handleSubmit () {
  124. const { name, account, phone, idCard, bankCard, idCardFront, idCardBack, type, phoneError } = this.state;
  125. const defaultFront = "https://video-img.fyshark.com/1735011631991upload-background-front.11d37038.png";
  126. const defaultBack = "https://video-img.fyshark.com/1735011647149upload-background-back.5b42ae0e.png";
  127. switch (true) {
  128. case name.length === 0:
  129. Taro.showToast({
  130. title: '请填写账户姓名',
  131. icon: 'none',
  132. duration: 2000
  133. });
  134. return;
  135. case phone.length === 0 || phoneError:
  136. Taro.showToast({
  137. title: phone.length === 0 ? '请填写手机号' : phoneError ? '手机号格式错误' : '请填写手机号',
  138. icon: 'none',
  139. duration: 2000
  140. });
  141. return;
  142. case idCard.length === 0:
  143. Taro.showToast({
  144. title: '请填写身份证号',
  145. icon: 'none',
  146. duration: 2000
  147. });
  148. return;
  149. case type === 'alipay' && account.length === 0:
  150. Taro.showToast({
  151. title: '请填写支付宝账户',
  152. icon: 'none',
  153. duration: 2000
  154. });
  155. return;
  156. case type === 'bank' && bankCard.length === 0:
  157. Taro.showToast({
  158. title: '请填写银行卡号',
  159. icon: 'none',
  160. duration: 2000
  161. });
  162. return;
  163. case idCardFront === defaultFront || idCardBack === defaultBack:
  164. Taro.showToast({
  165. title: '请上传身份证照片',
  166. icon: 'none',
  167. duration: 2000
  168. });
  169. return;
  170. }
  171. Taro.showLoading({
  172. title: '签约中...',
  173. mask: true
  174. });
  175. worker_register({
  176. name,
  177. card_no: idCard,
  178. bank_no: type === 'alipay' ? account : bankCard,
  179. phone,
  180. rsv_account_type: type === 'alipay' ? "1" : "0",
  181. portrait_page: idCardFront,
  182. national_emblem_page: idCardBack
  183. }).then(res => {
  184. console.log(res, 'res');
  185. if (res.code === 200) {
  186. this.getWorkerInfo()
  187. Taro.showToast({
  188. title: '签约成功',
  189. icon: 'success',
  190. mask: true,
  191. duration: 2000
  192. });
  193. } else {
  194. Taro.showToast({
  195. title: `签约失败:${res.msg}`,
  196. icon: 'none',
  197. mask: true,
  198. duration: 3000
  199. });
  200. }
  201. }).finally(() => {
  202. Taro.hideLoading();
  203. })
  204. }
  205. // 选择类型
  206. handleChooseType (type) {
  207. this.setState({ type });
  208. }
  209. // 手机号
  210. handleBlurPhone (value) {
  211. const phonePattern = /^1[3-9]\d{9}$/; // 简单的中国大陆手机号验证
  212. if (phonePattern.test(value)) {
  213. this.setState({ phoneError: false });
  214. } else {
  215. this.setState({ phoneError: true });
  216. }
  217. }
  218. // 是否已绑定
  219. isBind () {
  220. return (this.state.isAlipay && this.state.type === 'alipay') || (this.state.isBank && this.state.type === 'bank')
  221. }
  222. render () {
  223. return (
  224. <View className="index">
  225. {/* 支付宝信息 */}
  226. <View className="alipay-info">
  227. <View className="alipay-info-item">
  228. <View className="type-box">
  229. <View className={["type-title", this.state.type === 'alipay' ? 'active' : '']} onClick={() => this.handleChooseType('alipay')}>支付宝</View>
  230. <View className={["type-title", this.state.type === 'bank' ? 'active' : '']} onClick={() => this.handleChooseType('bank')}>银行卡</View>
  231. </View>
  232. </View>
  233. <View className="upload-box">
  234. <View className="upload-title" style={{ color: this.isBind() ? '#999' : '#333' }}>请上传身份证照片</View>
  235. <View className="upload-image">
  236. <View className="upload-image-item" onClick={() => this.handleChooseImage('front')}>
  237. <Image src={this.state.idCardFront} className="upload-image-item-image" />
  238. </View>
  239. <View className="upload-image-item" onClick={() => this.handleChooseImage('back')}>
  240. <Image src={this.state.idCardBack} className="upload-image-item-image" />
  241. </View>
  242. </View>
  243. </View>
  244. <AtInput
  245. name="value"
  246. title="账户姓名"
  247. type="text"
  248. disabled={this.isBind()}
  249. placeholder="请输入账户姓名"
  250. value={this.state.name}
  251. onChange={this.handleChangeName.bind(this)}
  252. />
  253. <AtInput
  254. name="value"
  255. title="身份证号"
  256. disabled={this.isBind()}
  257. type="text"
  258. placeholder="请输入身份证号"
  259. value={this.state.idCard}
  260. onChange={this.handleChangeIdCard.bind(this)}
  261. />
  262. <AtInput
  263. name="value"
  264. title="手机号"
  265. disabled={this.isBind()}
  266. type='phone'
  267. placeholder="请输入手机号"
  268. value={this.state.phone}
  269. onChange={this.handleChangePhone.bind(this)}
  270. onBlur={this.handleBlurPhone.bind(this)}
  271. error={this.state.phoneError}
  272. errorMessage={this.state.phoneError ? '请输入正确的手机号' : ''}
  273. />
  274. {
  275. this.state.type === 'bank' && (
  276. <AtInput
  277. name="value"
  278. disabled={this.isBind()}
  279. title="银行卡号"
  280. type="text"
  281. placeholder="请输入银行卡号"
  282. value={this.state.bankCard}
  283. onChange={this.handleChangeBankCard.bind(this)}
  284. />
  285. )
  286. }
  287. {
  288. this.state.type === 'alipay' && (
  289. <AtInput
  290. border={false}
  291. disabled={this.isBind()}
  292. name="value"
  293. title="支付宝账户"
  294. type="text"
  295. placeholder="请输入支付宝账户"
  296. value={this.state.account}
  297. onChange={this.handleChangeAccount.bind(this)}
  298. />
  299. )
  300. }
  301. </View>
  302. {
  303. this.isBind() &&
  304. <View className="alipay-info-tips">
  305. <View className="alipay-info-tips-item">
  306. <Image src={this.state.signImg} className="alipay-info-tips-item-icon" />
  307. <View className="alipay-info-tips-item-text">
  308. 如需更改,请联系客服
  309. </View>
  310. </View>
  311. </View>
  312. }
  313. {/* 注意 */}
  314. {
  315. !this.isBind() && (
  316. <View className="attention">
  317. <View className="attention-top">
  318. <Image src={aliPayIcon} className="attention-icon" />
  319. 注意:
  320. </View>
  321. <View className="attention-bottom">
  322. 所维护的信息需要与提现认证提交的自然人为同一人,非同一人会提现失败
  323. </View>
  324. </View>
  325. )
  326. }
  327. {/* 提交 */}
  328. {
  329. !this.isBind() &&
  330. <View className="submit" onClick={this.handleSubmit.bind(this)}>提交</View>
  331. }
  332. {
  333. !this.isBind() &&
  334. <View className="submit" onClick={this.handleSubmit.bind(this)}>提交</View>
  335. }
  336. </View>
  337. );
  338. }
  339. }