make-phone-call.uvue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view class="uni-hello-text uni-center">请在下方输入电话号码</view>
  6. <input class="input uni-common-mt" type="number" name="input" @input="bindInput" />
  7. <view class="uni-btn-v uni-common-mt">
  8. <button @tap="makePhoneCall" type="primary" :disabled="disabled">拨打</button>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script lang="uts">
  14. export default {
  15. data() {
  16. return {
  17. title: 'makePhoneCall',
  18. disabled: true,
  19. inputValue: ''
  20. }
  21. },
  22. methods: {
  23. bindInput: function (e : UniInputEvent) {
  24. this.inputValue = e.detail.value
  25. if (this.inputValue.length > 0) {
  26. this.disabled = false
  27. } else {
  28. this.disabled = true
  29. }
  30. },
  31. makePhoneCall: function () {
  32. uni.makePhoneCall({
  33. phoneNumber: this.inputValue,
  34. success: () => {
  35. console.log("成功拨打电话")
  36. },
  37. fail: (err) => {
  38. console.log(err.errCode)
  39. uni.showToast({
  40. title: '错误码:' + err.errCode.toString(),
  41. icon: "error"
  42. })
  43. }
  44. })
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. .input {
  51. height: 60px;
  52. line-height: 60px;
  53. font-size: 39px;
  54. border-bottom: 1px solid #E2E2E2;
  55. text-align: center;
  56. }
  57. </style>