vCode.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <up-modal :show="showModal" title="完工验证" @cancel="showModal = false" @confirm="completion" ref="uModal"
  3. confirmText="确认完工" showCancelButton :asyncClose="true">
  4. <view class="slot-content">
  5. <view style="padding: 20rpx 0 20rpx 0;">
  6. <up-code-input v-model="code" :maxlength="6" />
  7. <view style="padding-top: 40rpx;">
  8. <up-button type="primary" :text="countdownTime == 60 ? '发送完工验证码' : countdownTime + 'S后可重新发送'"
  9. @click="handle" />
  10. </view>
  11. </view>
  12. </view>
  13. </up-modal>
  14. </template>
  15. <script setup>
  16. import { getCurrentInstance, ref, defineProps, defineEmits } from 'vue';
  17. const emit = defineEmits(['callBack'])
  18. const { $Http } = getCurrentInstance().proxy;
  19. const props = defineProps({
  20. sa_workorderid: {
  21. type: [Number, String],
  22. },
  23. callBack: {
  24. type: Function
  25. }
  26. });
  27. let code = ref(''),
  28. showModal = ref(false),
  29. interval = null,
  30. uModal = ref(null);
  31. function completion(e) {
  32. if (code.value.trim() == '') {
  33. uModal.value.loading = false;
  34. return uni.showToast({
  35. title: '请输入客户确认码',
  36. icon: 'none'
  37. });
  38. }
  39. $Http.basic({
  40. "id": "20230215173203",
  41. "content": {
  42. "sa_workorderid": props.sa_workorderid,
  43. "code": code.value
  44. }
  45. }).then(res1 => {
  46. console.log("校验验证码", res1)
  47. if (res1.code == 1) {
  48. $Http.basic({
  49. "id": "20230209144903",
  50. "content": { "sa_workorderid": props.sa_workorderid }
  51. }).then(res => {
  52. console.log("完结工单", res)
  53. if (res.code == 1) {
  54. uni.showToast({
  55. title: '工单成功完结',
  56. icon: 'none'
  57. });
  58. setTimeout(() => {
  59. showModal.value = false;
  60. code.value = '';
  61. clearInterval(interval);
  62. }, 300)
  63. emit('callBack', true)
  64. } else {
  65. uni.showToast({
  66. title: res.msg,
  67. icon: 'none'
  68. });
  69. uModal.value.loading = false;
  70. }
  71. })
  72. } else {
  73. uni.showToast({
  74. title: res1.msg,
  75. icon: 'none'
  76. });
  77. uModal.value.loading = false;
  78. }
  79. })
  80. }
  81. function openModal() {
  82. showModal.value = true;
  83. }
  84. // 增加倒计时
  85. let countdown = null,
  86. countdownTime = ref(60);
  87. function handle() {
  88. if (countdownTime.value < 60) return;
  89. countdownTime.value--;
  90. getCode().then(() => {
  91. countdown = setInterval(() => {
  92. if (countdownTime.value > 0) {
  93. countdownTime.value--;
  94. } else {
  95. clearInterval(countdown);
  96. countdownTime.value = 60;
  97. }
  98. }, 1000);
  99. });
  100. }
  101. // 获取客户确认码
  102. function getCode() {
  103. return new Promise((resolve) => {
  104. $Http.basic({
  105. id: 20230215173103,
  106. "content": {
  107. "sa_workorderid": props.sa_workorderid
  108. }
  109. }).then(res => {
  110. console.log("获取验证码结果", res)
  111. uni.showToast({
  112. title: res.code == 1 ? '已发送到现场联系人' : res.msg,
  113. icon: 'none'
  114. });
  115. if (res.code != 1) countdownTime.value = 60;
  116. resolve(res.code == 1);
  117. try {
  118. if (res.code == 1 && res.data.msg.includes("手机验证码为")) {
  119. uni.showToast({
  120. title: '客户确认码已发送至客户手机',
  121. icon: 'none'
  122. });
  123. code.value = res.data.msg.split(":")[1].trim();
  124. }
  125. } catch (error) {
  126. }
  127. })
  128. })
  129. }
  130. // 将内部方法暴露给模板使用
  131. defineExpose({
  132. openModal
  133. });
  134. </script>