修复倒计时bug会被取消的bug

This commit is contained in:
weipengfei 2023-08-11 15:28:33 +08:00
parent 1a61a73237
commit 1545bf867f
3 changed files with 631 additions and 586 deletions

View File

@ -151,7 +151,6 @@
</u-form-item> </u-form-item>
</block> </block>
</u--form> </u--form>
</view> </view>
</template> </template>

View File

@ -71,8 +71,14 @@
this.id = options.id; this.id = options.id;
this.initCompany(); this.initCompany();
this.initContractTypeList(); this.initContractTypeList();
let time = uni.getStorageSync('ctime' + this.id);
if(time>0&&(time - Date.now())/1000>0){
this.startTimer((time - Date.now())/1000);
}
},
onUnload() {
if(this.timerCount>0) uni.setStorageSync('ctime'+this.id, this.timerCount*1000+Date.now());
}, },
onShow() {},
computed: { computed: {
cTimerCount() { cTimerCount() {
return this.timerCount; return this.timerCount;
@ -129,14 +135,7 @@
}); });
this.initCompany(); this.initCompany();
if (this.userInfo.contract.check_status == 3) { if (this.userInfo.contract.check_status == 3) {
this.timerCount = 60; this.startTimer();
this.timer = setInterval(() => {
this.timerCount--;
if (this.timerCount == 0) {
clearInterval(this.timer);
this.initCompany();
}
}, 1000);
} }
uni.hideLoading(); uni.hideLoading();
Toast('合同已发送'); Toast('合同已发送');
@ -149,14 +148,7 @@
// //
async getPostsms() { async getPostsms() {
if (this.timerCount == 0) { if (this.timerCount == 0) {
this.timerCount = 60; this.startTimer();
this.timer = setInterval(() => {
this.timerCount--;
if (this.timerCount == 0) {
clearInterval(this.timer);
this.initCompany();
}
}, 1000);
let res = await postsms({ let res = await postsms({
id: this.id id: this.id
}) })
@ -164,6 +156,17 @@
this.navTo('/subpkg/submit/submit'); this.navTo('/subpkg/submit/submit');
} }
}, },
//
startTimer(time=60){
this.timerCount = time.toFixed(0);
this.timer = setInterval(() => {
this.timerCount--;
if (this.timerCount <= 0) {
clearInterval(this.timer);
this.loadUserDetail();
}
}, 1000);
},
navTo(url) { navTo(url) {
url ? url ?
uni.navigateTo({ uni.navigateTo({

View File

@ -11,13 +11,15 @@
<view class="text"> <view class="text">
<view class="basic_name"> <view class="basic_name">
<view class="name">{{userInfo.name}}</view> <view class="name">{{userInfo.name}}</view>
<image class="icon" <image class="icon" :src="userInfo.sex==1?'../../static/icons/man.png':'../../static/icons/woman.png'">
:src="userInfo.sex==1?'../../static/icons/man.png':'../../static/icons/woman.png'">
</image> </image>
<!-- <view class="role" v-if="userInfo.roles">{{userInfo.roles[0]}}</view> --> <!-- <view class="role" v-if="userInfo.roles">{{userInfo.roles[0]}}</view> -->
</view> </view>
<view class="id_card"> <view class="id_card">
身份证号:{{userInfo.id_card}} <view>身份证号:{{userInfo.id_card}}</view>
<!-- <view class="update" @click="updateShow(userInfo.id_card, 'id_card')">
<uni-icons type="compose" color="#F9AA32"></uni-icons>
</view> -->
</view> </view>
<view class="phone"> <view class="phone">
联系电话:{{userInfo.phone}} 联系电话:{{userInfo.phone}}
@ -28,11 +30,11 @@
是否为小队长: 是否为小队长:
<u-radio-group v-model="userInfo.is_captain" style="margin-left: 16rpx;" disabled> <u-radio-group v-model="userInfo.is_captain" style="margin-left: 16rpx;" disabled>
<u-radio :customStyle="{marginRight: '16px'}" <u-radio :customStyle="{marginRight: '16px'}"
v-for="(item, index) in [{value:1,label:'是'},{value:0,label:'否'}]" :key="index" v-for="(item, index) in [{value:1,label:'是'},{value:0,label:'否'}]" :key="index" :label="item.label"
:label="item.label" :name="item.value"> :name="item.value">
</u-radio> </u-radio>
</u-radio-group> </u-radio-group>
<view class="update" @click="updateShow(userInfo.is_captain)"> <view class="update" @click="updateShow(userInfo.is_captain, 'is_captain')">
<uni-icons type="compose" color="#F9AA32"></uni-icons> <uni-icons type="compose" color="#F9AA32"></uni-icons>
</view> </view>
</view> </view>
@ -40,21 +42,35 @@
负责区域:<text>{{(userInfo.street_name||'')+(userInfo.village_name||'')}}</text> 负责区域:<text>{{(userInfo.street_name||'')+(userInfo.village_name||'')}}</text>
<text v-for="(item, index) in userInfo.brigade_name">{{item.brigade_name}}</text> <text v-for="(item, index) in userInfo.brigade_name">{{item.brigade_name}}</text>
</view> </view>
<u-popup :show="show" :round="10" mode="center"> <u-popup :show="show.is_captain" :round="10" mode="center">
<view class="popup"> <view class="popup">
<view class="p_title">修改信息</view> <view class="p_title">修改信息</view>
<view class="p_body"> <view class="p_body">
是否为小队长: 是否为小队长:
<u-radio-group v-model="updateForm.is_captain" style="margin: 16rpx;"> <u-radio-group v-model="updateForm.is_captain" style="margin: 16rpx;">
<u-radio :customStyle="{marginRight: '16px'}" <u-radio :customStyle="{marginRight: '16px'}"
v-for="(item, index) in [{value:1,label:'是'},{value:0,label:'否'}]" :key="index" v-for="(item, index) in [{value:1,label:'是'},{value:0,label:'否'}]" :key="index" :label="item.label"
:label="item.label" :name="item.value"> :name="item.value">
</u-radio> </u-radio>
</u-radio-group> </u-radio-group>
</view> </view>
<view class="p_button"> <view class="p_button">
<view @click="show=false">取消</view> <view @click="show.is_captain=false">取消</view>
<view @click="updateInfo">确认</view> <view @click="updateInfo('is_captain')">确认</view>
</view>
</view>
</u-popup>
<u-popup :show="show.id_card" :round="10" mode="center">
<view class="popup">
<view class="p_title">修改信息</view>
<u--form style="padding: 0 28rpx;">
<u-form-item label="身份证号:" labelWidth="auto" labelPosition="top">
<u--input style="border:1px solid #3175f9;" v-model="updateForm.id_card"></u--input>
</u-form-item>
</u--form>
<view class="p_button">
<view @click="show.id_card=false">取消</view>
<view @click="updateInfo('id_card')">确认</view>
</view> </view>
</view> </view>
</u-popup> </u-popup>
@ -137,8 +153,8 @@
</view> </view>
</view> </view>
</view> </view>
<picker v-if="!userInfo.is_contract&&!userInfo.contract||(userInfo.contract&&userInfo.contract.check_status==0)" :range="contractTypeList" range-key="name" <picker v-if="!userInfo.is_contract&&!userInfo.contract||(userInfo.contract&&userInfo.contract.check_status==0)"
@change="changeType"> :range="contractTypeList" range-key="name" @change="changeType">
<button class="btn">生成合同</button> <button class="btn">生成合同</button>
</picker> </picker>
<view v-if="userInfo.contract&&userInfo.contract.check_status==1"> <view v-if="userInfo.contract&&userInfo.contract.check_status==1">
@ -216,12 +232,16 @@
return { return {
id: '', id: '',
skeleton: true, skeleton: true,
show: false, show: {
is_captain: false,
id_card: false,
},
typeShow: false, typeShow: false,
timer: null, // timer: null, //
timerCount: 0, // timerCount: 0, //
updateForm: { updateForm: {
is_captain: 0, is_captain: 0,
id_card: '',
}, },
userInfo: { userInfo: {
qualification: {}, qualification: {},
@ -235,8 +255,14 @@
if (options.id) this.id = options.id; if (options.id) this.id = options.id;
this.initContractTypeList(); this.initContractTypeList();
this.loadUserDetail(); this.loadUserDetail();
let time = uni.getStorageSync('time' + this.id);
if(time>0&&(time - Date.now())/1000>0){
this.startTimer((time - Date.now())/1000);
}
},
onUnload() {
if(this.timerCount>0) uni.setStorageSync('time'+this.id, this.timerCount*1000+Date.now());
}, },
onShow() {},
computed: { computed: {
cTimerCount() { cTimerCount() {
return this.timerCount; return this.timerCount;
@ -261,19 +287,24 @@
url: url, url: url,
}) : Toast('暂未开放') }) : Toast('暂未开放')
}, },
updateShow(value) { updateShow(value, type) {
this.updateForm.is_captain = value; this.updateForm[type] = value;
this.show = true; this.show[type] = true;
}, },
// //
async updateInfo() { async updateInfo(type) {
let res = await loginSetInfo({ try {
let form = {
user_id: this.userInfo.id, user_id: this.userInfo.id,
is_captain: this.updateForm.is_captain };
}); form[type] = this.updateForm[type];
this.userInfo.is_captain = this.updateForm.is_captain; let res = await loginSetInfo(form);
this.userInfo[type] = this.updateForm[type];
Toast('更新成功'); Toast('更新成功');
this.show = false; this.show = false;
} catch (e) {
Toast(e.msg || '更新失败')
}
}, },
changeType(e) { changeType(e) {
// console.log(this.contractTypeList[e.detail.value]); // console.log(this.contractTypeList[e.detail.value]);
@ -293,7 +324,7 @@
// //
async createContract(data) { async createContract(data) {
uni.showLoading({ uni.showLoading({
title:'合同生成中', title: '合同生成中',
mask: true mask: true
}) })
let res = await userInitiateContract({ let res = await userInitiateContract({
@ -307,9 +338,9 @@
}, },
// //
async addContract(data) { async addContract(data) {
try{ try {
uni.showLoading({ uni.showLoading({
title:'合同发送中', title: '合同发送中',
mask: true mask: true
}) })
let res = await userDraftingcontracts({ let res = await userDraftingcontracts({
@ -317,40 +348,47 @@
}); });
this.loadUserDetail(); this.loadUserDetail();
if (this.userInfo.contract.check_status == 3) { if (this.userInfo.contract.check_status == 3) {
this.timerCount = 60; this.startTimer();
this.timer = setInterval(() => {
this.timerCount--;
if (this.timerCount == 0) {
clearInterval(this.timer);
this.loadUserDetail();
}
}, 1000);
} }
uni.hideLoading(); uni.hideLoading();
Toast('合同已发送'); Toast('合同已发送');
this.navTo('/subpkg/submit/submit'); this.navTo('/subpkg/submit/submit');
}catch(e){ } catch (e) {
uni.hideLoading(); uni.hideLoading();
Toast('合同发送失败'); Toast(e.msg || '合同发送失败');
} }
}, },
// //
async getPostsms() { async getPostsms() {
try {
uni.showLoading({
title: '发送中',
mask: true
})
if (this.timerCount == 0) { if (this.timerCount == 0) {
this.timerCount = 60; this.startTimer();
let res = await userPostsms({
id: this.userInfo.id
})
uni.hideLoading();
Toast('短信已发送');
this.navTo('/subpkg/submit/submit');
}
} catch (e) {
uni.hideLoading();
Toast(e.msg || '合同发送失败');
}
},
//
startTimer(time=60){
this.timerCount = time.toFixed(0);
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.timerCount--; this.timerCount--;
if (this.timerCount == 0) { if (this.timerCount <= 0) {
clearInterval(this.timer); clearInterval(this.timer);
this.loadUserDetail(); this.loadUserDetail();
} }
}, 1000); }, 1000);
let res = await userPostsms({
id: this.userInfo.id
})
Toast('短信已发送');
this.navTo('/subpkg/submit/submit');
}
}, },
loadUserDetail() { loadUserDetail() {
if (!this.id) return; if (!this.id) return;
@ -415,6 +453,7 @@
} }
.text { .text {
flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
@ -447,6 +486,10 @@
} }
} }
.id_card {
display: flex;
justify-content: space-between;
}
} }
} }