authorize.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <div>
  3. <div class="defbb p-spac">
  4. 平台账户授权 [
  5. <span class="gray-color" :class="{ 'green-color': true }">{{
  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">{{ bindPhone }}</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. 去授权
  28. </div>
  29. </div>
  30. <div class="center justify-between p-spacd2 defbb">
  31. <div>提现授权</div>
  32. <div
  33. class="pointer p-color"
  34. :class="{ 'gray-color': !isBindPhone }"
  35. @click="authEvent(1)"
  36. >
  37. 去授权
  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. orgInfo: {
  171. type: Object,
  172. default: function() {
  173. return {}
  174. }
  175. }
  176. },
  177. computed: {
  178. stateText() {
  179. return '未完成'
  180. },
  181. isBindPhone() {
  182. return !!this.bindPhone
  183. },
  184. bindPhoneText() {
  185. return this.isBindPhone ? '修改' : '绑定'
  186. },
  187. waring() {
  188. return !this.isBindPhone && this.authClicked
  189. }
  190. },
  191. created() {
  192. this.formStepOne.tel = this.bindPhone
  193. },
  194. methods: {
  195. authEvent(type) {
  196. this.authClicked = true
  197. if (type === 0) {
  198. if (this.orgInfo.contractNo) {
  199. const params = {
  200. bizUserId: this.orgInfo.bizUserId,
  201. jumpUrl: window.location.href,
  202. source: 2
  203. }
  204. $signContractQuery(params).then(res => {
  205. if (res.code === 0) {
  206. window.location.href = res.data
  207. }
  208. })
  209. } else {
  210. const params = {
  211. bizUserId: this.orgInfo.bizUserId,
  212. orgId: this.orgInfo.orgId,
  213. source: 2,
  214. backUrl: window.location.href,
  215. jumpUrl: location.href
  216. // jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  217. }
  218. $signContract(params).then(res => {
  219. if (res.code === 0) {
  220. window.open(res.data.data)
  221. }
  222. })
  223. }
  224. }
  225. if (type === 1) {
  226. if (this.orgInfo.protocolNo) {
  227. this.$router.push('accountSetting/balanceProtocol')
  228. } else {
  229. const params = {
  230. bizUserId: this.orgInfo.bizUserId,
  231. orgId: this.orgInfo.orgId,
  232. source: 2,
  233. backUrl: window.location.href,
  234. jumpUrl: location.href
  235. // jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  236. }
  237. $signBalanceProtocol(params).then(res => {
  238. if (res.code === 0) {
  239. window.open(res.data)
  240. }
  241. })
  242. }
  243. }
  244. },
  245. bindTelEvent() {
  246. this.$refs.formBindTel.validate((valid) => {
  247. if (valid) {
  248. const params = {
  249. bizUserId: this.bizUserId,
  250. verificationCode: this.formBindTel.code,
  251. phone: this.formBindTel.tel
  252. }
  253. $bindPhone(params).then((res) => {
  254. this.$message.success(res.message)
  255. this.bindPhone = this.formBindTel.tel
  256. this.formStepOne.tel = this.formBindTel.tel
  257. this.bindTelDialogVisible = false
  258. })
  259. }
  260. })
  261. },
  262. saveTel() {
  263. if (this.isBindPhone) {
  264. this.telDialogVisible = true
  265. if (this.timer) {
  266. clearInterval(this.timer)
  267. this.codeBtn.text = '获取验证码'
  268. this.codeBtn.disabled = false
  269. }
  270. } else {
  271. this.bindTelDialogVisible = true
  272. }
  273. },
  274. getCodeEvent(param) {
  275. // let step = this.stepActive
  276. if (this.codeBtn.disabled) {
  277. return
  278. }
  279. if (param === 'formStepOne') {
  280. this.codeEvent(this.formStepOne.tel, param)
  281. } else if (param === 'formStepTwo') {
  282. this.$refs[param].validateField('newTel', (valid) => {
  283. if (!valid) {
  284. this.codeEvent(this.formStepTwo.newTel, param)
  285. } else {
  286. return null
  287. }
  288. })
  289. } else {
  290. this.$refs[param].validateField('tel', (valid) => {
  291. if (!valid) {
  292. this.codeEvent(this.formBindTel.tel, param)
  293. } else {
  294. return null
  295. }
  296. })
  297. }
  298. },
  299. codeEvent(tel, param) {
  300. let verificationCodeType = 0
  301. if (param === 'formStepTwo' || param === 'formBindTel') {
  302. verificationCodeType = 9
  303. } else {
  304. verificationCodeType = 6
  305. }
  306. const params = {
  307. phone: tel,
  308. bizUserId: this.bizUserId,
  309. verificationCodeType
  310. }
  311. $sendVerificationCode(params)
  312. .then((res) => {
  313. this.$message.success(res.message)
  314. })
  315. .catch((msg) => {
  316. clearInterval(this.timer)
  317. this.codeBtn.text = '获取验证码'
  318. this.codeBtn.disabled = false
  319. })
  320. let time = 60
  321. this.codeBtn.text = time + 's'
  322. this.timer = setInterval(() => {
  323. time--
  324. this.codeBtn.text = time + 's'
  325. this.codeBtn.disabled = true
  326. if (time < 0) {
  327. clearInterval(this.timer)
  328. this.codeBtn.text = '获取验证码'
  329. this.codeBtn.disabled = false
  330. }
  331. }, 1000)
  332. },
  333. footerBtnEvent() {
  334. if (this.stepActive === 1) {
  335. this.$refs.formStepOne.validateField('code', (valid) => {
  336. if (!valid) {
  337. const code = this.formStepOne.code
  338. const params = {
  339. phone: this.formStepOne.tel,
  340. bizUserId: this.bizUserId,
  341. verificationCode: code
  342. }
  343. $unbindPhone(params).then((res) => {
  344. if (res.code === 0) {
  345. this.stepActive = 2
  346. this.footerBtnText = '确认修改'
  347. this.$message.success(res.message)
  348. this.bindPhone = ''
  349. if (this.timer) {
  350. clearInterval(this.timer)
  351. this.codeBtn.text = '获取验证码'
  352. this.codeBtn.disabled = false
  353. }
  354. } else {
  355. this.$message.error(res.message)
  356. }
  357. })
  358. } else {
  359. return null
  360. }
  361. })
  362. } else {
  363. this.$refs.formStepTwo.validate((valid) => {
  364. if (valid) {
  365. const params = {
  366. phone: this.formStepTwo.newTel,
  367. bizUserId: this.bizUserId,
  368. verificationCode: this.formStepTwo.code
  369. }
  370. $bindPhone(params).then((res) => {
  371. if (res.code === 0) {
  372. this.stepActive = 1
  373. this.formStepOne.code = ''
  374. this.formStepTwo.tel = ''
  375. this.formStepTwo.code = ''
  376. this.$message.success(res.message)
  377. this.bindPhone = this.formStepTwo.newTel
  378. this.telDialogVisible = false
  379. } else {
  380. this.$message.error(res.message)
  381. }
  382. })
  383. }
  384. })
  385. }
  386. },
  387. closeBindTelDialog() {
  388. this.formBindTel.tel = ''
  389. this.formBindTel.code = ''
  390. },
  391. closeEditTelDialog() {
  392. this.formStepOne.code = ''
  393. this.formStepTwo.newTel = ''
  394. this.formStepTwo.code = ''
  395. this.stepActive = 1
  396. if (this.$refs.formStepOne) {
  397. this.$refs.formStepOne.clearValidate()
  398. }
  399. if (this.$refs.formStepTwo) {
  400. this.$refs.formStepTwo.clearValidate()
  401. }
  402. }
  403. }
  404. }
  405. </script>
  406. <style lang="scss" scoped>
  407. @import "submodule/utils/style/variables.scss";
  408. .items {
  409. width: 400px;
  410. }
  411. .getcode-btn {
  412. width: 70px;
  413. text-align: center;
  414. cursor: pointer;
  415. color: $p-color;
  416. }
  417. </style>