authorize.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <div class="defbb">
  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">
  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 defbt">
  21. <div>转账授权</div>
  22. <div
  23. class="pointer p-color"
  24. :class="{ 'gray-color': !isBindPhone,'green-color':balanceAuthed}"
  25. @click="authEvent(0)"
  26. >
  27. <i class="el-icon-loading
  28. " v-if="$reqState($interfaces.pay.sign_balance_protocol).ing"></i>{{balanceAuthed?'已授权':'去授权'}}
  29. </div>
  30. </div>
  31. <div class="center justify-between p-spacd2 defbt" v-if="isDealer">
  32. <div>提现授权</div>
  33. <div
  34. class="pointer p-color"
  35. :class="{ 'gray-color': !isBindPhone,'green-color':withdrawAuthed }"
  36. @click="authEvent(1)"
  37. >
  38. <i class="el-icon-loading
  39. " v-if="$reqState($interfaces.pay.sign_balance_protocol).ing"></i>{{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. },
  188. computed: {
  189. /** 经销 */
  190. isDealer() {
  191. return this.$props.tradeType === 1
  192. },
  193. balanceAuthed() {
  194. return this.carrierBalanceInfo.balanceStatus === 2
  195. },
  196. withdrawAuthed() {
  197. return this.carrierWithdrawInfo.withdrawStatus === 2
  198. },
  199. progress() {
  200. let count = 0
  201. if (this.balanceAuthed) {
  202. count++
  203. }
  204. if (this.withdrawAuthed) {
  205. count++
  206. }
  207. return count
  208. },
  209. stateText() {
  210. let rv = '未完成'
  211. if (this.isDealer) {
  212. if (this.progress === 2) {
  213. rv = '已授权'
  214. } else {
  215. rv = `${this.progress}/2`
  216. }
  217. } else {
  218. if (this.carrierBalanceInfo.balanceStatus === 2) {
  219. rv = '已授权'
  220. }
  221. }
  222. return rv
  223. },
  224. isBindPhone() {
  225. return !!this.$props.value
  226. },
  227. bindPhoneText() {
  228. return this.isBindPhone ? '修改' : '绑定'
  229. },
  230. waring() {
  231. return !this.isBindPhone && this.authClicked
  232. }
  233. },
  234. created() {
  235. this.formStepOne.tel = this.$props.value
  236. },
  237. methods: {
  238. authEvent(type) {
  239. if (!this.isBindPhone) {
  240. this.authClicked = true
  241. return
  242. }
  243. // 转账授权
  244. if (type === 0) {
  245. // 已授权
  246. if (this.carrierBalanceInfo.balanceStatus === 2) {
  247. this.$router.push('accountSetting/balanceProtocol')
  248. } else {
  249. const params = {
  250. source: 2,
  251. backUrl: window.location.href,
  252. jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  253. }
  254. this.$http(this.$interfaces.pay.sign_balance_protocol, params).then(res => {
  255. window.location.href = res
  256. })
  257. }
  258. }
  259. // 提现授权
  260. if (type === 1) {
  261. // 已授权
  262. if (this.carrierWithdrawInfo.withdrawStatus === 2) {
  263. const params = {
  264. jumpUrl: window.location.href,
  265. source: 2
  266. }
  267. $signContractQuery(params).then(res => {
  268. if (res.code === 0) {
  269. window.location.href = res.data
  270. }
  271. })
  272. } else {
  273. const params = {
  274. source: 2,
  275. backUrl: window.location.href,
  276. jumpUrl: location.href.split('/#')[0] + '/#/signSuccess'
  277. }
  278. this.$http(this.$interfaces.pay.sign_withdraw_protocol, params).then(res => {
  279. window.location.href = res
  280. })
  281. }
  282. }
  283. },
  284. bindTelEvent() {
  285. this.$refs.formBindTel.validate((valid) => {
  286. if (valid) {
  287. const params = {
  288. verificationCode: this.formBindTel.code,
  289. phone: this.formBindTel.tel
  290. }
  291. $bindPhone(params).then((res) => {
  292. this.$message.success(res.message)
  293. this.$props.value = this.formBindTel.tel
  294. this.formStepOne.tel = this.formBindTel.tel
  295. this.bindTelDialogVisible = false
  296. })
  297. }
  298. })
  299. },
  300. saveTel() {
  301. if (this.isBindPhone) {
  302. this.telDialogVisible = true
  303. if (this.timer) {
  304. clearInterval(this.timer)
  305. this.codeBtn.text = '获取验证码'
  306. this.codeBtn.disabled = false
  307. }
  308. } else {
  309. this.bindTelDialogVisible = true
  310. }
  311. },
  312. getCodeEvent(param) {
  313. // let step = this.stepActive
  314. if (this.codeBtn.disabled) {
  315. return
  316. }
  317. if (param === 'formStepOne') {
  318. this.codeEvent(this.formStepOne.tel, param)
  319. } else if (param === 'formStepTwo') {
  320. this.$refs[param].validateField('newTel', (valid) => {
  321. if (!valid) {
  322. this.codeEvent(this.formStepTwo.newTel, param)
  323. } else {
  324. return null
  325. }
  326. })
  327. } else {
  328. this.$refs[param].validateField('tel', (valid) => {
  329. if (!valid) {
  330. this.codeEvent(this.formBindTel.tel, param)
  331. } else {
  332. return null
  333. }
  334. })
  335. }
  336. },
  337. codeEvent(tel, param) {
  338. let verificationCodeType = 0
  339. if (param === 'formStepTwo' || param === 'formBindTel') {
  340. verificationCodeType = 9
  341. } else {
  342. verificationCodeType = 6
  343. }
  344. const params = {
  345. phone: tel,
  346. verificationCodeType
  347. }
  348. $sendVerificationCode(params)
  349. .then((res) => {
  350. this.$message.success(res.message)
  351. })
  352. .catch((msg) => {
  353. clearInterval(this.timer)
  354. this.codeBtn.text = '获取验证码'
  355. this.codeBtn.disabled = false
  356. })
  357. let time = 60
  358. this.codeBtn.text = time + 's'
  359. this.timer = setInterval(() => {
  360. time--
  361. this.codeBtn.text = time + 's'
  362. this.codeBtn.disabled = true
  363. if (time < 0) {
  364. clearInterval(this.timer)
  365. this.codeBtn.text = '获取验证码'
  366. this.codeBtn.disabled = false
  367. }
  368. }, 1000)
  369. },
  370. footerBtnEvent() {
  371. if (this.stepActive === 1) {
  372. this.$refs.formStepOne.validateField('code', (valid) => {
  373. if (!valid) {
  374. const code = this.formStepOne.code
  375. const params = {
  376. phone: this.formStepOne.tel,
  377. verificationCode: code
  378. }
  379. $unbindPhone(params).then((res) => {
  380. if (res.code === 0) {
  381. this.stepActive = 2
  382. this.footerBtnText = '确认修改'
  383. this.$message.success(res.message)
  384. this.$props.value = ''
  385. if (this.timer) {
  386. clearInterval(this.timer)
  387. this.codeBtn.text = '获取验证码'
  388. this.codeBtn.disabled = false
  389. }
  390. } else {
  391. this.$message.error(res.message)
  392. }
  393. })
  394. } else {
  395. return null
  396. }
  397. })
  398. } else {
  399. this.$refs.formStepTwo.validate((valid) => {
  400. if (valid) {
  401. const params = {
  402. phone: this.formStepTwo.newTel,
  403. verificationCode: this.formStepTwo.code
  404. }
  405. $bindPhone(params).then((res) => {
  406. if (res.code === 0) {
  407. this.stepActive = 1
  408. this.formStepOne.code = ''
  409. this.formStepTwo.tel = ''
  410. this.formStepTwo.code = ''
  411. this.$message.success(res.message)
  412. this.$props.value = this.formStepTwo.newTel
  413. this.telDialogVisible = false
  414. } else {
  415. this.$message.error(res.message)
  416. }
  417. })
  418. }
  419. })
  420. }
  421. },
  422. closeBindTelDialog() {
  423. this.formBindTel.tel = ''
  424. this.formBindTel.code = ''
  425. },
  426. closeEditTelDialog() {
  427. this.formStepOne.code = ''
  428. this.formStepTwo.newTel = ''
  429. this.formStepTwo.code = ''
  430. this.stepActive = 1
  431. if (this.$refs.formStepOne) {
  432. this.$refs.formStepOne.clearValidate()
  433. }
  434. if (this.$refs.formStepTwo) {
  435. this.$refs.formStepTwo.clearValidate()
  436. }
  437. }
  438. }
  439. }
  440. </script>
  441. <style lang="scss" scoped>
  442. @import "submodule/utils/style/variables.scss";
  443. .items {
  444. width: 400px;
  445. }
  446. .getcode-btn {
  447. width: 70px;
  448. text-align: center;
  449. cursor: pointer;
  450. color: $p-color;
  451. }
  452. </style>