| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <template>
- <up-modal :show="showModal" title="完工验证" @cancel="showModal = false" @confirm="completion" ref="uModal"
- confirmText="确认完工" showCancelButton :asyncClose="true">
- <view class="slot-content">
- <view style="padding: 20rpx 0 20rpx 0;">
- <!-- #ifndef APP-NVUE -->
- <up-input placeholder="完工验证码" v-model="code" :focus="downTime == 59">
- <!-- #endif -->
- <!-- #ifdef APP-NVUE -->
- <up-input placeholder="完工验证码" v-model="code" :focus="downTime == 59">
- <!-- #endif -->
- <template #suffix>
- <up-button @tap="getCode" :disabled="downTime != 0" :text="tips" type="success" size="mini">{{
- downTime == 0 ? '重新发送验证码' : downTime +
- '秒重新获取' }}</up-button>
- </template>
- <!-- #ifndef APP-NVUE -->
- </up-input>
- <!-- #endif -->
- <!-- #ifdef APP-NVUE -->
- </up-input>
- <!-- #endif -->
- </view>
- </view>
- </up-modal>
- </template>
- <script setup>
- import { getCurrentInstance, ref, defineProps, defineEmits } from 'vue';
- const emit = defineEmits(['callBack'])
- const { $Http } = getCurrentInstance().proxy;
- const props = defineProps({
- sa_workorderid: {
- type: [Number, String],
- },
- callBack: {
- type: Function
- }
- });
- let code = ref(''),
- showModal = ref(false),
- downTime = ref(''),
- interval = null,
- uModal = ref(null);
- function completion(e) {
- if (code.value.trim() == '') {
- uModal.value.loading = false;
- return uni.showToast({
- title: '请输入完工验证码',
- icon: 'none'
- });
- }
- $Http.basic({
- "id": "20230215173203",
- "content": {
- "sa_workorderid": props.sa_workorderid,
- "code": code.value
- }
- }).then(res1 => {
- console.log("校验验证码", res1)
- if (res1.code == 1) {
- $Http.basic({
- "id": "20230209144903",
- "content": { "sa_workorderid": props.sa_workorderid }
- }).then(res => {
- console.log("完结工单", res)
- if (res.code == 1) {
- setTimeout(() => {
- showModal.value = false;
- code.value = '';
- downTime.value = '';
- clearInterval(interval);
- }, 300)
- emit('callBack', true)
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- });
- uModal.value.loading = false;
- }
- })
- } else {
- uni.showToast({
- title: res1.msg,
- icon: 'none'
- });
- uModal.value.loading = false;
- }
- })
- }
- function openModal() {
- if (downTime.value == '') {
- getCode().then(res => {
- if (res) showModal.value = true;
- })
- } else {
- showModal.value = true;
- }
- }
- // 获取完工验证码
- function getCode() {
- if (downTime.value != '') return;
- return new Promise((resolve) => {
- $Http.basic({
- id: 20230215173103,
- "content": {
- "sa_workorderid": props.sa_workorderid
- }
- }).then(res => {
- console.log("获取验证码结果", res)
- resolve(res.code == 1);
- downTime.value = 60;
- if (res.code == 1) {
- if (res.data.msg.includes("手机验证码为")) {
- uni.showToast({
- title: res.data.msg,
- icon: 'none'
- });
- code.value = res.data.msg.split(":")[1].trim();
- }
- interval = setInterval(() => {
- downTime.value--;
- if (downTime.value <= 0) {
- clearInterval(interval);
- downTime.value = '';
- }
- }, 1000);
- } else {
- downTime.value = '';
- uni.showToast({
- title: res.msg,
- icon: 'none'
- });
- }
- })
- })
- }
- // 将内部方法暴露给模板使用
- defineExpose({
- openModal
- });
- </script>
|