authorize.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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_balance_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, $signContractQuery } 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. $signContractQuery(params).then(res => {
  288. if (res.code === 0) {
  289. window.location.href = res.data
  290. }
  291. })
  292. } else {
  293. const params = {
  294. source: 2,
  295. backUrl: window.location.href,
  296. jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  297. }
  298. this.$http(this.$interfaces.pay.sign_withdraw_protocol, params).then(res => {
  299. window.location.href = res
  300. })
  301. }
  302. }
  303. },
  304. bindTelEvent() {
  305. this.$refs.formBindTel.validate((valid) => {
  306. if (valid) {
  307. const params = {
  308. verificationCode: this.formBindTel.code,
  309. phone: this.formBindTel.tel
  310. }
  311. $bindPhone(params).then((res) => {
  312. this.$message.success(res.message)
  313. this.$emit('input', this.formBindTel.tel)
  314. this.formStepOne.tel = this.formBindTel.tel
  315. this.bindTelDialogVisible = false
  316. })
  317. }
  318. })
  319. },
  320. saveTel() {
  321. if (this.isBindPhone) {
  322. this.telDialogVisible = true
  323. if (this.timer) {
  324. clearInterval(this.timer)
  325. this.codeBtn.text = '获取验证码'
  326. this.codeBtn.disabled = false
  327. }
  328. } else {
  329. this.bindTelDialogVisible = true
  330. }
  331. },
  332. getCodeEvent(param) {
  333. // let step = this.stepActive
  334. if (this.codeBtn.disabled) {
  335. return
  336. }
  337. if (param === 'formStepOne') {
  338. this.codeEvent(this.formStepOne.tel, param)
  339. } else if (param === 'formStepTwo') {
  340. this.$refs[param].validateField('newTel', (valid) => {
  341. if (!valid) {
  342. this.codeEvent(this.formStepTwo.newTel, param)
  343. } else {
  344. return null
  345. }
  346. })
  347. } else {
  348. this.$refs[param].validateField('tel', (valid) => {
  349. if (!valid) {
  350. this.codeEvent(this.formBindTel.tel, param)
  351. } else {
  352. return null
  353. }
  354. })
  355. }
  356. },
  357. codeEvent(tel, param) {
  358. let verificationCodeType = 0
  359. if (param === 'formStepTwo' || param === 'formBindTel') {
  360. verificationCodeType = 9
  361. } else {
  362. verificationCodeType = 6
  363. }
  364. const params = {
  365. phone: tel,
  366. verificationCodeType
  367. }
  368. $sendVerificationCode(params)
  369. .then((res) => {
  370. this.$message.success(res.message)
  371. })
  372. .catch((msg) => {
  373. clearInterval(this.timer)
  374. this.codeBtn.text = '获取验证码'
  375. this.codeBtn.disabled = false
  376. })
  377. let time = 60
  378. this.codeBtn.text = time + 's'
  379. this.timer = setInterval(() => {
  380. time--
  381. this.codeBtn.text = time + 's'
  382. this.codeBtn.disabled = true
  383. if (time < 0) {
  384. clearInterval(this.timer)
  385. this.codeBtn.text = '获取验证码'
  386. this.codeBtn.disabled = false
  387. }
  388. }, 1000)
  389. },
  390. footerBtnEvent() {
  391. if (this.stepActive === 1) {
  392. this.$refs.formStepOne.validateField('code', (valid) => {
  393. if (!valid) {
  394. const code = this.formStepOne.code
  395. const params = {
  396. phone: this.formStepOne.tel,
  397. verificationCode: code
  398. }
  399. $unbindPhone(params).then((res) => {
  400. if (res.code === 0) {
  401. this.stepActive = 2
  402. this.footerBtnText = '确认修改'
  403. this.$message.success(res.message)
  404. this.$emit('input', '')
  405. if (this.timer) {
  406. clearInterval(this.timer)
  407. this.codeBtn.text = '获取验证码'
  408. this.codeBtn.disabled = false
  409. }
  410. } else {
  411. this.$message.error(res.message)
  412. }
  413. })
  414. } else {
  415. return null
  416. }
  417. })
  418. } else {
  419. this.$refs.formStepTwo.validate((valid) => {
  420. if (valid) {
  421. const params = {
  422. phone: this.formStepTwo.newTel,
  423. verificationCode: this.formStepTwo.code
  424. }
  425. $bindPhone(params).then((res) => {
  426. if (res.code === 0) {
  427. this.stepActive = 1
  428. this.formStepOne.code = ''
  429. this.formStepTwo.tel = ''
  430. this.formStepTwo.code = ''
  431. this.$message.success(res.message)
  432. this.$emit('input', this.formStepTwo.newTel)
  433. this.telDialogVisible = false
  434. } else {
  435. this.$message.error(res.message)
  436. }
  437. })
  438. }
  439. })
  440. }
  441. },
  442. closeBindTelDialog() {
  443. this.formBindTel.tel = ''
  444. this.formBindTel.code = ''
  445. },
  446. closeEditTelDialog() {
  447. this.formStepOne.code = ''
  448. this.formStepTwo.newTel = ''
  449. this.formStepTwo.code = ''
  450. this.stepActive = 1
  451. if (this.$refs.formStepOne) {
  452. this.$refs.formStepOne.clearValidate()
  453. }
  454. if (this.$refs.formStepTwo) {
  455. this.$refs.formStepTwo.clearValidate()
  456. }
  457. }
  458. }
  459. }
  460. </script>
  461. <style lang="scss" scoped>
  462. @import "submodule/utils/style/variables.scss";
  463. .items {
  464. width: 400px;
  465. }
  466. .getcode-btn {
  467. width: 70px;
  468. text-align: center;
  469. cursor: pointer;
  470. color: $p-color;
  471. }
  472. </style>