bindHome.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="">
  3. <u-popup v-model="show" mode="center" width="80%" :border-radius="10" @close="close">
  4. <view style="padding:30rpx 0rpx;display: flex;flex-direction: column;justify-content: space-between;">
  5. <view class="center text-center padding-bottom-30">
  6. <text>绑定房间</text>
  7. </view>
  8. <view class="flex-sub" style="margin: 20rpx 0;">
  9. <u-checkbox-group>
  10. <u-cell-group>
  11. <u-cell-item @click="check(item)" v-for="(item,index) in roomList" :key="index"
  12. :icon-style="item.checked?iconStyle:''" :icon="item.checked?'home-fill':'home'"
  13. :arrow="false" icon-size="30" :title="item.address">
  14. <u-checkbox slot="right-icon" v-model="item.checked" :name="item.id"></u-checkbox>
  15. </u-cell-item>
  16. </u-cell-group>
  17. </u-checkbox-group>
  18. </view>
  19. <view class="text-sm"
  20. style="display: flex;padding: 5rpx 32rpx 38rpx">
  21. <u-checkbox v-model="checked" size="26" name="checked" :label-disabled="true">
  22. <text style="font-size: 28rpx;">不再提示</text>
  23. </u-checkbox>
  24. </view>
  25. <view style="display: flex;justify-content: center">
  26. <u-button v-if="type==1" :customStyle="createStyle" @click="createRoom">创建新房间</u-button>
  27. <u-button v-else :customStyle="cancelStyle" @click="show=false" >暂不绑定</u-button>
  28. <u-button :customStyle="confirmStyle" @click="confirm">确认绑定</u-button>
  29. </view>
  30. </view>
  31. </u-popup>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: '',
  37. props: ['type'],
  38. data() {
  39. return {
  40. checked: false,
  41. show: false,
  42. roomList: [],
  43. iconStyle: {
  44. 'color': '#2f7ff5'
  45. },
  46. createStyle: {
  47. backgroundColor: '#ff9900',
  48. height: '70rpx',
  49. lineHeight: '70rpx',
  50. width: '210rpx',
  51. fontSize: '28rpx',
  52. color: '#FFFFFF',
  53. marginLeft: '15rpx',
  54. borderRadius: '0'
  55. },
  56. cancelStyle: {
  57. height: '70rpx',
  58. lineHeight: '70rpx',
  59. width: '210rpx',
  60. fontSize: '28rpx',
  61. border: '1rpx solid #afb0b3',
  62. marginRight: '15rpx',
  63. borderRadius: '0'
  64. },
  65. confirmStyle: {
  66. backgroundColor: '#2f7ff5',
  67. height: '70rpx',
  68. lineHeight: '70rpx',
  69. width: '210rpx',
  70. fontSize: '28rpx',
  71. color: '#FFFFFF',
  72. marginLeft: '15rpx',
  73. borderRadius: '0'
  74. }
  75. };
  76. },
  77. created() {
  78. this.initData()
  79. },
  80. methods: {
  81. close(){
  82. if (this.checked) {
  83. uni.setStorageSync('cancelBind', true)
  84. }
  85. },
  86. check(item) {
  87. item.checked = !item.checked
  88. this.$forceUpdate()
  89. },
  90. async initData() {
  91. let cancelBind = uni.getStorageSync('cancelBind') || false
  92. if (cancelBind || this.$isEmpty(this.vuex_member)) {
  93. return
  94. }
  95. let params = {
  96. idCard: this.vuex_member.idcard,
  97. name: this.vuex_member.name,
  98. }
  99. let list = (await this.$http.getHouseUserCondition(params)).data.data
  100. this.roomList = list.filter(item => this.isEmpty(item.memberId))
  101. this.roomList.forEach(item => {
  102. item.checked = false
  103. item.address = item.residentialName + "-" + item.buildingName + "-" + item.unitName + "-" +
  104. item.roomName
  105. })
  106. if (this.$isNotEmpty(this.roomList)) {
  107. this.show = true
  108. }
  109. },
  110. isEmpty(data) {
  111. if (this.$isEmpty(data) || data == -1) {
  112. return true
  113. }
  114. return false
  115. },
  116. confirm() {
  117. let checkList = this.roomList.filter(item => item.checked)
  118. let ids = checkList.map(item => item.id)
  119. if (this.$isEmpty(ids)) {
  120. this.$u.toast('至少选择一项')
  121. return
  122. }
  123. let params = {
  124. memberId: this.vuex_member.id,
  125. ids
  126. }
  127. this.$http.bindRoom(this.vuex_member.id, ids).then(res => {
  128. this.show = false
  129. if (res.data.success) {
  130. this.$u.toast('绑定成功')
  131. this.$emit('reload')
  132. } else {
  133. this.$u.toast('操作失败')
  134. }
  135. })
  136. }
  137. }
  138. };
  139. </script>
  140. <style lang="scss" scoped>
  141. </style>