vCode.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. <!-- #ifndef APP-NVUE -->
  7. <up-input placeholder="完工验证码" v-model="code" :focus="downTime == 59">
  8. <!-- #endif -->
  9. <!-- #ifdef APP-NVUE -->
  10. <up-input placeholder="完工验证码" v-model="code" :focus="downTime == 59">
  11. <!-- #endif -->
  12. <template #suffix>
  13. <up-button @tap="getCode" :disabled="downTime != 0" :text="tips" type="success" size="mini">{{
  14. downTime == 0 ? '重新发送验证码' : downTime +
  15. '秒重新获取' }}</up-button>
  16. </template>
  17. <!-- #ifndef APP-NVUE -->
  18. </up-input>
  19. <!-- #endif -->
  20. <!-- #ifdef APP-NVUE -->
  21. </up-input>
  22. <!-- #endif -->
  23. </view>
  24. </view>
  25. </up-modal>
  26. </template>
  27. <script setup>
  28. import { getCurrentInstance, ref, defineProps, defineEmits } from 'vue';
  29. const emit = defineEmits(['callBack'])
  30. const { $Http } = getCurrentInstance().proxy;
  31. const props = defineProps({
  32. sa_workorderid: {
  33. type: [Number, String],
  34. },
  35. callBack: {
  36. type: Function
  37. }
  38. });
  39. let code = ref(''),
  40. showModal = ref(false),
  41. downTime = ref(''),
  42. interval = null,
  43. uModal = ref(null);
  44. function completion(e) {
  45. if (code.value.trim() == '') {
  46. uModal.value.loading = false;
  47. return uni.showToast({
  48. title: '请输入完工验证码',
  49. icon: 'none'
  50. });
  51. }
  52. $Http.basic({
  53. "id": "20230215173203",
  54. "content": {
  55. "sa_workorderid": props.sa_workorderid,
  56. "code": code.value
  57. }
  58. }).then(res1 => {
  59. console.log("校验验证码", res1)
  60. if (res1.code == 1) {
  61. $Http.basic({
  62. "id": "20230209144903",
  63. "content": { "sa_workorderid": props.sa_workorderid }
  64. }).then(res => {
  65. console.log("完结工单", res)
  66. if (res.code == 1) {
  67. setTimeout(() => {
  68. showModal.value = false;
  69. code.value = '';
  70. downTime.value = '';
  71. clearInterval(interval);
  72. }, 300)
  73. emit('callBack', true)
  74. } else {
  75. uni.showToast({
  76. title: res.msg,
  77. icon: 'none'
  78. });
  79. uModal.value.loading = false;
  80. }
  81. })
  82. } else {
  83. uni.showToast({
  84. title: res1.msg,
  85. icon: 'none'
  86. });
  87. uModal.value.loading = false;
  88. }
  89. })
  90. }
  91. function openModal() {
  92. if (downTime.value == '') {
  93. getCode().then(res => {
  94. if (res) showModal.value = true;
  95. })
  96. } else {
  97. showModal.value = true;
  98. }
  99. }
  100. // 获取完工验证码
  101. function getCode() {
  102. if (downTime.value != '') return;
  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. resolve(res.code == 1);
  112. downTime.value = 60;
  113. if (res.code == 1) {
  114. if (res.data.msg.includes("手机验证码为")) {
  115. uni.showToast({
  116. title: res.data.msg,
  117. icon: 'none'
  118. });
  119. code.value = res.data.msg.split(":")[1].trim();
  120. }
  121. interval = setInterval(() => {
  122. downTime.value--;
  123. if (downTime.value <= 0) {
  124. clearInterval(interval);
  125. downTime.value = '';
  126. }
  127. }, 1000);
  128. } else {
  129. downTime.value = '';
  130. uni.showToast({
  131. title: res.msg,
  132. icon: 'none'
  133. });
  134. }
  135. })
  136. })
  137. }
  138. // 将内部方法暴露给模板使用
  139. defineExpose({
  140. openModal
  141. });
  142. </script>