authorize.vue 13 KB

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