vCode.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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>
  8. </view>
  9. </up-modal>
  10. </template>
  11. <script setup>
  12. import { getCurrentInstance, ref, defineProps, defineEmits } from 'vue';
  13. const emit = defineEmits(['callBack'])
  14. const { $Http } = getCurrentInstance().proxy;
  15. const props = defineProps({
  16. sa_workorderid: {
  17. type: [Number, String],
  18. },
  19. callBack: {
  20. type: Function
  21. }
  22. });
  23. let code = ref(''),
  24. showModal = ref(false),
  25. interval = null,
  26. uModal = ref(null);
  27. function completion(e) {
  28. if (code.value.trim() == '') {
  29. uModal.value.loading = false;
  30. return uni.showToast({
  31. title: '请输入客户确认码',
  32. icon: 'none'
  33. });
  34. }
  35. $Http.basic({
  36. "id": "20230215173203",
  37. "content": {
  38. "sa_workorderid": props.sa_workorderid,
  39. "code": code.value
  40. }
  41. }).then(res1 => {
  42. console.log("校验验证码", res1)
  43. if (res1.code == 1) {
  44. $Http.basic({
  45. "id": "20230209144903",
  46. "content": { "sa_workorderid": props.sa_workorderid }
  47. }).then(res => {
  48. console.log("完结工单", res)
  49. if (res.code == 1) {
  50. uni.showToast({
  51. title: '工单成功完结',
  52. icon: 'none'
  53. });
  54. setTimeout(() => {
  55. showModal.value = false;
  56. code.value = '';
  57. clearInterval(interval);
  58. }, 300)
  59. emit('callBack', true)
  60. } else {
  61. uni.showToast({
  62. title: res.msg,
  63. icon: 'none'
  64. });
  65. uModal.value.loading = false;
  66. }
  67. })
  68. } else {
  69. uni.showToast({
  70. title: res1.msg,
  71. icon: 'none'
  72. });
  73. uModal.value.loading = false;
  74. }
  75. })
  76. }
  77. function openModal() {
  78. getCode()
  79. showModal.value = true;
  80. }
  81. // 获取客户确认码
  82. function getCode() {
  83. return new Promise((resolve) => {
  84. $Http.basic({
  85. id: 20230215173103,
  86. "content": {
  87. "sa_workorderid": props.sa_workorderid
  88. }
  89. }).then(res => {
  90. console.log("获取验证码结果", res)
  91. resolve(res.code == 1);
  92. if (res.code == 1 && res.data.msg.includes("手机验证码为")) {
  93. uni.showToast({
  94. title: '客户确认码已发送至客户手机',
  95. icon: 'none'
  96. });
  97. code.value = res.data.msg.split(":")[1].trim();
  98. } else {
  99. uni.showToast({
  100. title: res.msg,
  101. icon: 'none'
  102. });
  103. }
  104. })
  105. })
  106. }
  107. // 将内部方法暴露给模板使用
  108. defineExpose({
  109. openModal
  110. });
  111. </script>