vCode.vue 4.8 KB

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