linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<template>
    <view class="list-container">
 
        <view class="item" v-for="(item, index) in list" :key="index">
            <view class="line">
                <view class="l">租客:{{item.name}} (<text>{{`共${item.num}人`}}</text>)</view>
                <view class="r">
                    <u-icon name="trash-fill" color="#ff0000" size="18" @click="deleteRental(item)"></u-icon>
                </view>
            </view>
 
            <view class="line">
                <view class="l">{{item.rentalTime}} - {{item.dueTime}}</view>
                <view class="r status">
                    {{ findObjValue(item.status, status) }}
                </view>
            </view>
 
            <view class="list-btn flex j-c-s-b">
                <!-- <u-button icon="edit-pen" class="btn-item" type="primary" plain text="修改"
                    :disabled="item.status == 1 || item.status == 2" @click="pushPage(item)"></u-button>
                <u-button icon="calendar" class="btn-item" type="primary" plain text="续租" :disabled="item.status == 2"
                    @click="xzHandleClick(item)"></u-button>
                <u-button icon="order" class="btn-item" type="primary" plain text="终止"
                    :disabled="item.status == 1 || item.status == 2" @click="terminate(item)"></u-button> -->
                    <view class="btn-item">
                        <u-button class="bgc-main" type="primary" size='small' text="修改"
                            :disabled="item.status == 1 || item.status == 2" @click="pushPage(item)"></u-button>
                    </view>
                    <view class="btn-item">
                        <u-button class="bgc-main" type="primary" size='small' text="续租"
                            :disabled="item.status == 2" @click="xzHandleClick(item)"></u-button>
                    </view>
                    
                    <view class="btn-item">
                        <u-button class="bgc-main" type="primary" size='small' text="终止"
                            :disabled="item.status == 1 || item.status == 2" @click="terminate(item)"></u-button>
                    </view>
            </view>
 
        </view>
 
        <view class="tip">
            <u-divider text="已经到底了"></u-divider>
        </view>
 
        <u-datetime-picker v-model="currentTime" v-if="isPickerShow" :closeOnClickOverlay="true" @close="isPickerShow = false" :show="isPickerShow" @cancel="isPickerShow = false" mode="date"
            @confirm="dueTimeConfirm"></u-datetime-picker>
        <u-datetime-picker v-model="currentTime" v-if="istPickerShow" :closeOnClickOverlay="true" @close="istPickerShow = false" :show="istPickerShow" @cancel="istPickerShow = false" mode="date"
            @confirm="terminateTimeConfirm"></u-datetime-picker>
        <u-modal :show="isModelShow" width="auto" :showCancelButton="true" title="提示" content="请确认是否删除当前租户信息"
            @cancel="isModelShow = false" @confirm="deleteRentalConfirm"></u-modal>
        <u-toast ref="uToast"></u-toast>
    </view>
</template>
 
<script>
    import {
        deleteRentalInfo,
        updateDueTime
    } from "@/api/houseRental/houseRental.js";
    export default {
        props: {
            list: {
                type: Array,
                default: () => []
            }
        },
        data() {
            return {
                isPickerShow: false,
                istPickerShow: false,
                currentRentalId: '',
                isModelShow: false,
                status: [{
                        name: '未到期',
                        value: 0
                    },
                    {
                        name: '已到期',
                        value: 1
                    },
                    {
                        name: '已终止',
                        value: 2
                    },
                ],
                currentTime: '',
                currentRentInfo: {}
            }
        },
        methods: {
            findObjValue(value, obj) {
                const res = obj.find(item => {
                    return item.value == value
                })
                return res.name
            },
            deleteRental(item) {
                this.currentRentalId = item.housingRentalId
                this.isModelShow = true
            },
            async deleteRentalConfirm() {
                const {
                    code,
                    data
                } = await deleteRentalInfo(this.currentRentalId)
                if (code !== 200) {
                    uni.showToast({
                        title: "删除失败",
                        icon: "error",
                        duration: 1500
                    })
                    return
                }
                this.isModelShow = false
                this.$emit('refreshData')
            },
            pushPage(item) {
                console.log("item===>",item);
                // const {
                //     houseCode
                // } = this.$route.query
                const {
                    id,
                    houseCode
                } = item
                this.$u.func.globalNavigator(
                    `/subPackage/bs/views/rentDetail?houseCode=${houseCode}&id=${id}`)
            },
            xzHandleClick(item) {
                this.currentRentalId = item.housingRentalId
                this.currentRentInfo = item
                this.currentTime = item.dueTime
                this.isPickerShow = true
                
            },
            async dueTimeConfirm(e) {
                // 判断当前选中的时间是否小于租房时间
                const {
                    rentalTime
                } = this.currentRentInfo
                const rentDate = new Date(rentalTime).getTime()
                if (rentDate > e.value) {
                    this.$refs.uToast.show({
                        type: 'warning',
                        message: "续租时间不可小于租房时间",
                        position: 'top',
                        iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
                    })
                    return
                }
                const time = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
                const res = await updateDueTime({
                    id: this.currentRentalId,
                    dueTime: time
                })
                if (res.code !== 200) {
                    uni.showToast({
                        title: "续租失败",
                        icon: "error",
                        duration: 1500
                    })
                    return
                }
                this.isPickerShow = false
                this.$emit('refreshData')
            },
            terminate(item) {
                this.currentRentalId = item.housingRentalId
                this.istPickerShow = true
            },
            async terminateTimeConfirm(e) {
                const {
                    rentalTime
                } = this.currentRentInfo
                const rentDate = new Date(rentalTime).getTime()
                if (rentDate > e.value) {
                    this.$refs.uToast.show({
                        type: 'warning',
                        message: "终止时间不可小于租房时间",
                        position: 'top',
                        iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
                    })
                    return
                }
                const time = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
                const res = await updateDueTime({
                    id: this.currentRentalId,
                    terminationTime: time
                })
                if (res.code !== 200) {
                    uni.showToast({
                        title: "终止失败",
                        icon: "error",
                        duration: 1500
                    })
                    return
                }
                this.istPickerShow = false
                this.$emit('refreshData')
            }
        }
    }
</script>
 
<style scoped lang="scss">
    .list-container {
 
        .item {
            background-color: #ffffff;
            margin: 20rpx 0;
 
            .line {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 20rpx;
 
                &:nth-child(1) {
                    border: 1rpx solid #F6F6F6;
                }
 
                .l {
                    // font-weight: 700;
 
                    text {
                        color: #0682EF;
                    }
                }
 
                .status {
                    color: #6dc160
                }
 
            }
 
            .list-btn {
                padding: 24rpx;
                .btn-item {
                    width: 180rpx;
                    // margin: 0 10rpx;
                    // border: 0;
                    // color: #009FFF;
                    // font-weight: 700;
                }
            }
        }
 
        .tip {}
 
    }
</style>