authorize.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <div class="defbb">
  3. <div class="defbb pt-spac pb-spac mt-spac">
  4. 平台账户授权 [
  5. <span class="gray-color" :class="{ 'green-color': progress }">{{
  6. stateText
  7. }}</span>
  8. ]<span class="ml-spac p-wcolor" v-if="waring"> [ 提醒:请先绑定“授权手机号”!]</span>
  9. </div>
  10. <div class="items p-spacd2">
  11. <div class="center justify-between p-spacd2">
  12. <div class="label-color">授权手机号</div>
  13. <div>
  14. <span>{{ value }}</span>
  15. <el-button class="ml-spac" type="text" @click="saveTel()" v-if="!$props.readOnly">{{
  16. bindPhoneText
  17. }}</el-button>
  18. </div>
  19. </div>
  20. <div class="center justify-between p-spacd2 defbt">
  21. <div class="label-color">转账授权</div>
  22. <div
  23. class="p-color"
  24. :class="{ 'gray-color': !isBindPhone||this.$props.readOnly ,'green-color':balanceAuthed,pointer:!$props.readOnly}"
  25. @click="authEvent(0)"
  26. >
  27. <i class="el-icon-loading
  28. " v-if="$reqState($interfaces.pay.sign_balance_protocol).ing"></i>{{authText(balanceAuthed)}}
  29. </div>
  30. </div>
  31. <div class="center justify-between p-spacd2 defbt" v-if="isDealer">
  32. <div class="label-color">提现授权</div>
  33. <div
  34. class="p-color"
  35. :class="{ 'gray-color': !isBindPhone||this.$props.readOnly,'green-color':withdrawAuthed,pointer:!$props.readOnly }"
  36. @click="authEvent(1)"
  37. >
  38. <i class="el-icon-loading
  39. " v-if="$reqState($interfaces.pay.sign_withdraw_protocol).ing"></i>{{authText(withdrawAuthed)}}
  40. </div>
  41. </div>
  42. </div>
  43. <el-dialog
  44. :append-to-body="true"
  45. title="修改手机号"
  46. :visible.sync="telDialogVisible"
  47. @close="closeEditTelDialog"
  48. >
  49. <el-steps :active="stepActive" align-center>
  50. <el-step title="解绑原手机号"></el-step>
  51. <el-step title="绑定新手机号"></el-step>
  52. </el-steps>
  53. <el-form
  54. :model="formStepOne"
  55. v-if="stepActive === 1"
  56. ref="formStepOne"
  57. :rules="formStepOneRules"
  58. >
  59. <el-form-item label="原手机号" prop="newTel">
  60. <el-input v-model="formStepOne.tel" disabled></el-input>
  61. </el-form-item>
  62. <el-form-item label="验证码" prop="code">
  63. <el-input v-model="formStepOne.code" clearable>
  64. <template slot="append"
  65. ><div class="getcode-btn" @click="getCodeEvent('formStepOne')">
  66. {{ codeBtn.text }}
  67. </div></template
  68. >
  69. </el-input>
  70. </el-form-item>
  71. </el-form>
  72. <el-form
  73. :model="formStepTwo"
  74. v-else-if="stepActive === 2"
  75. ref="formStepTwo"
  76. :rules="formStepTwoRules"
  77. >
  78. <el-form-item label="新手机号" prop="newTel">
  79. <el-input v-model="formStepTwo.newTel"></el-input>
  80. </el-form-item>
  81. <el-form-item label="验证码" prop="code">
  82. <el-input v-model="formStepTwo.code" clearable>
  83. <template slot="append"
  84. ><div class="getcode-btn" @click="getCodeEvent('formStepTwo')">
  85. {{ codeBtn.text }}
  86. </div></template
  87. >
  88. </el-input>
  89. </el-form-item>
  90. </el-form>
  91. <div slot="footer">
  92. <el-button type="primary" @click="footerBtnEvent">{{
  93. footerBtnText
  94. }}</el-button>
  95. </div>
  96. </el-dialog>
  97. <el-dialog
  98. :append-to-body="true"
  99. title="绑定手机号"
  100. :visible.sync="bindTelDialogVisible"
  101. @close="closeBindTelDialog"
  102. >
  103. <el-form
  104. :model="formBindTel"
  105. ref="formBindTel"
  106. v-if="bindTelDialogVisible"
  107. :rules="formBindTelRules"
  108. >
  109. <el-form-item label="手机号" prop="tel">
  110. <el-input v-model="formBindTel.tel"></el-input>
  111. </el-form-item>
  112. <el-form-item label="验证码" prop="code" clearable>
  113. <el-input v-model="formBindTel.code">
  114. <template slot="append"
  115. ><div class="getcode-btn" @click="getCodeEvent('formBindTel')">
  116. {{ codeBtn.text }}
  117. </div></template
  118. >
  119. </el-input>
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer">
  123. <el-button type="primary" @click="bindTelEvent">确认绑定</el-button>
  124. </div>
  125. </el-dialog>
  126. </div>
  127. </template>
  128. <script>
  129. import { $sendVerificationCode, $unbindPhone, $bindPhone } from '@/service/pay'
  130. export default {
  131. name: 'authorize',
  132. data() {
  133. return {
  134. authClicked: false,
  135. bindPhone: '66',
  136. formStepOne: {
  137. tel: '',
  138. code: ''
  139. },
  140. formStepOneRules: {
  141. code: [{ required: true, message: '此选项不能为空', trigger: 'blur' }]
  142. },
  143. formStepTwo: {
  144. newTel: '',
  145. code: ''
  146. },
  147. formStepTwoRules: {
  148. newTel: [
  149. { required: true, message: '此选项不能为空', trigger: 'blur' }
  150. ],
  151. code: [{ required: true, message: '此选项不能为空', trigger: 'blur' }]
  152. },
  153. telDialogVisible: false,
  154. bindTelDialogVisible: false,
  155. stepActive: 1,
  156. codeBtn: {
  157. text: '获取验证码',
  158. disabled: false
  159. },
  160. formBindTel: {
  161. tel: '',
  162. code: ''
  163. },
  164. formBindTelRules: {
  165. tel: [{ required: true, message: '此选项不能为空', trigger: 'blur' }],
  166. code: [{ required: true, message: '此选项不能为空', trigger: 'blur' }]
  167. },
  168. footerBtnText: '下一步'
  169. }
  170. },
  171. props: {
  172. tradeType: {
  173. type: Number
  174. },
  175. value: {
  176. type: String,
  177. default: ''
  178. },
  179. carrierBalanceInfo: {
  180. type: Object,
  181. default: () => ({})
  182. },
  183. carrierWithdrawInfo: {
  184. type: Object,
  185. default: () => ({})
  186. },
  187. readOnly: {
  188. type: Boolean,
  189. default: false
  190. }
  191. },
  192. computed: {
  193. /** 经销 */
  194. isDealer() {
  195. return this.$props.tradeType === 1
  196. },
  197. balanceAuthed() {
  198. return this.carrierBalanceInfo.balanceStatus === 2
  199. },
  200. withdrawAuthed() {
  201. return this.carrierWithdrawInfo.withdrawStatus === 2
  202. },
  203. progress() {
  204. let count = 0
  205. if (this.balanceAuthed) {
  206. count++
  207. }
  208. if (this.withdrawAuthed) {
  209. count++
  210. }
  211. return count
  212. },
  213. stateText() {
  214. let rv = '未完成'
  215. if (this.isDealer) {
  216. if (this.progress === 2) {
  217. rv = '已授权'
  218. } else {
  219. rv = `${this.progress}/2`
  220. }
  221. } else {
  222. if (this.carrierBalanceInfo.balanceStatus === 2) {
  223. rv = '已授权'
  224. }
  225. }
  226. return rv
  227. },
  228. isBindPhone() {
  229. return !!this.$props.value
  230. },
  231. bindPhoneText() {
  232. return this.isBindPhone ? '修改' : '绑定'
  233. },
  234. waring() {
  235. return !this.isBindPhone && this.authClicked
  236. }
  237. },
  238. created() {
  239. this.formStepOne.tel = this.$props.value
  240. },
  241. methods: {
  242. authText(authed) {
  243. let rv = '未授权'
  244. if (authed) {
  245. rv = '已授权'
  246. } else {
  247. if (this.$props.readOnly) {
  248. rv = '未授权'
  249. } else {
  250. rv = '去授权'
  251. }
  252. }
  253. return rv
  254. },
  255. authEvent(type) {
  256. if (this.$props.readOnly) {
  257. return
  258. }
  259. if (!this.isBindPhone) {
  260. this.authClicked = true
  261. return
  262. }
  263. // 转账授权
  264. if (type === 0) {
  265. // 已授权
  266. if (this.carrierBalanceInfo.balanceStatus === 2) {
  267. this.$router.push('accountSetting/balanceProtocol')
  268. } else {
  269. const params = {
  270. source: 2,
  271. backUrl: window.location.href,
  272. jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  273. }
  274. this.$http(this.$interfaces.pay.sign_balance_protocol, params).then(res => {
  275. window.location.href = res
  276. })
  277. }
  278. }
  279. // 提现授权
  280. if (type === 1) {
  281. // 已授权
  282. if (this.carrierWithdrawInfo.withdrawStatus === 2) {
  283. const params = {
  284. jumpUrl: window.location.href,
  285. source: 2
  286. }
  287. this.$http(this.$interfaces.pay.query_withdraw_protocol, params)
  288. .then(res => {
  289. window.location.href = res
  290. })
  291. } else {
  292. const params = {
  293. source: 2,
  294. backUrl: window.location.href,
  295. jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  296. }
  297. this.$http(this.$interfaces.pay.sign_withdraw_protocol, params).then(res => {
  298. window.location.href = res.data
  299. })
  300. }
  301. }
  302. },
  303. bindTelEvent() {
  304. this.$refs.formBindTel.validate((valid) => {
  305. if (valid) {
  306. const params = {
  307. verificationCode: this.formBindTel.code,
  308. phone: this.formBindTel.tel
  309. }
  310. $bindPhone(params).then((res) => {
  311. this.$message.success(res.message)
  312. this.$emit('input', this.formBindTel.tel)
  313. this.formStepOne.tel = this.formBindTel.tel
  314. this.bindTelDialogVisible = false
  315. })
  316. }
  317. })
  318. },
  319. saveTel() {
  320. if (this.isBindPhone) {
  321. this.telDialogVisible = true
  322. if (this.timer) {
  323. clearInterval(this.timer)
  324. this.codeBtn.text = '获取验证码'
  325. this.codeBtn.disabled = false
  326. }
  327. } else {
  328. this.bindTelDialogVisible = true
  329. }
  330. },
  331. getCodeEvent(param) {
  332. // let step = this.stepActive
  333. if (this.codeBtn.disabled) {
  334. return
  335. }
  336. if (param === 'formStepOne') {
  337. this.codeEvent(this.formStepOne.tel, param)
  338. } else if (param === 'formStepTwo') {
  339. this.$refs[param].validateField('newTel', (valid) => {
  340. if (!valid) {
  341. this.codeEvent(this.formStepTwo.newTel, param)
  342. } else {
  343. return null
  344. }
  345. })
  346. } else {
  347. this.$refs[param].validateField('tel', (valid) => {
  348. if (!valid) {
  349. this.codeEvent(this.formBindTel.tel, param)
  350. } else {
  351. return null
  352. }
  353. })
  354. }
  355. },
  356. codeEvent(tel, param) {
  357. let verificationCodeType = 0
  358. if (param === 'formStepTwo' || param === 'formBindTel') {
  359. verificationCodeType = 9
  360. } else {
  361. verificationCodeType = 6
  362. }
  363. const params = {
  364. phone: tel,
  365. verificationCodeType
  366. }
  367. $sendVerificationCode(params)
  368. .then((res) => {
  369. this.$message.success(res.message)
  370. })
  371. .catch((msg) => {
  372. clearInterval(this.timer)
  373. this.codeBtn.text = '获取验证码'
  374. this.codeBtn.disabled = false
  375. })
  376. let time = 60
  377. this.codeBtn.text = time + 's'
  378. this.timer = setInterval(() => {
  379. time--
  380. this.codeBtn.text = time + 's'
  381. this.codeBtn.disabled = true
  382. if (time < 0) {
  383. clearInterval(this.timer)
  384. this.codeBtn.text = '获取验证码'
  385. this.codeBtn.disabled = false
  386. }
  387. }, 1000)
  388. },
  389. footerBtnEvent() {
  390. if (this.stepActive === 1) {
  391. this.$refs.formStepOne.validateField('code', (valid) => {
  392. if (!valid) {
  393. const code = this.formStepOne.code
  394. const params = {
  395. phone: this.formStepOne.tel,
  396. verificationCode: code
  397. }
  398. $unbindPhone(params).then((res) => {
  399. if (res.code === 0) {
  400. this.stepActive = 2
  401. this.footerBtnText = '确认修改'
  402. this.$message.success(res.message)
  403. this.$emit('input', '')
  404. if (this.timer) {
  405. clearInterval(this.timer)
  406. this.codeBtn.text = '获取验证码'
  407. this.codeBtn.disabled = false
  408. }
  409. } else {
  410. this.$message.error(res.message)
  411. }
  412. })
  413. } else {
  414. return null
  415. }
  416. })
  417. } else {
  418. this.$refs.formStepTwo.validate((valid) => {
  419. if (valid) {
  420. const params = {
  421. phone: this.formStepTwo.newTel,
  422. verificationCode: this.formStepTwo.code
  423. }
  424. $bindPhone(params).then((res) => {
  425. if (res.code === 0) {
  426. this.stepActive = 1
  427. this.formStepOne.code = ''
  428. this.formStepTwo.tel = ''
  429. this.formStepTwo.code = ''
  430. this.$message.success(res.message)
  431. this.$emit('input', this.formStepTwo.newTel)
  432. this.telDialogVisible = false
  433. } else {
  434. this.$message.error(res.message)
  435. }
  436. })
  437. }
  438. })
  439. }
  440. },
  441. closeBindTelDialog() {
  442. this.formBindTel.tel = ''
  443. this.formBindTel.code = ''
  444. },
  445. closeEditTelDialog() {
  446. this.formStepOne.code = ''
  447. this.formStepTwo.newTel = ''
  448. this.formStepTwo.code = ''
  449. this.stepActive = 1
  450. if (this.$refs.formStepOne) {
  451. this.$refs.formStepOne.clearValidate()
  452. }
  453. if (this.$refs.formStepTwo) {
  454. this.$refs.formStepTwo.clearValidate()
  455. }
  456. }
  457. }
  458. }
  459. </script>
  460. <style lang="scss" scoped>
  461. @import "submodule/utils/style/variables.scss";
  462. .items {
  463. width: 400px;
  464. }
  465. .getcode-btn {
  466. width: 70px;
  467. text-align: center;
  468. cursor: pointer;
  469. color: $p-color;
  470. }
  471. </style>