bindHome.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="">
  3. <u-popup v-model="show" mode="center" width="80%" :border-radius="10" >
  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 style="display: flex;justify-content: center;padding-top: 50rpx;">
  20. <u-button v-if="type==1" :customStyle="createStyle" @click="createRoom">创建新房间</u-button>
  21. <u-button v-else :customStyle="cancelStyle" @click="cancel">暂不绑定</u-button>
  22. <u-button :customStyle="confirmStyle" @click="confirm">确认绑定</u-button>
  23. </view>
  24. </view>
  25. </u-popup>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. name: '',
  31. props:['type'],
  32. data() {
  33. return {
  34. show: false,
  35. roomList: [],
  36. iconStyle: {
  37. 'color': '#2f7ff5'
  38. },
  39. createStyle:{
  40. backgroundColor: '#ff9900',
  41. height: '70rpx',
  42. lineHeight: '70rpx',
  43. width: '210rpx',
  44. fontSize: '28rpx',
  45. color: '#FFFFFF',
  46. marginLeft: '15rpx',
  47. borderRadius: '0'
  48. },
  49. cancelStyle: {
  50. height: '70rpx',
  51. lineHeight: '70rpx',
  52. width: '210rpx',
  53. fontSize: '28rpx',
  54. border: '1rpx solid #afb0b3',
  55. marginRight: '15rpx',
  56. borderRadius: '0'
  57. },
  58. confirmStyle: {
  59. backgroundColor: '#2f7ff5',
  60. height: '70rpx',
  61. lineHeight: '70rpx',
  62. width: '210rpx',
  63. fontSize: '28rpx',
  64. color: '#FFFFFF',
  65. marginLeft: '15rpx',
  66. borderRadius: '0'
  67. }
  68. };
  69. },
  70. created() {
  71. this.initData()
  72. },
  73. methods: {
  74. check(item) {
  75. item.checked = !item.checked
  76. this.$forceUpdate()
  77. },
  78. async initData() {
  79. let cancelBind=uni.getStorageSync('cancelBind') || false
  80. if (cancelBind || this.$isEmpty(this.vuex_member)) {
  81. return
  82. }
  83. let params = {
  84. phone: this.vuex_member.phone,
  85. name: this.vuex_member.name,
  86. }
  87. let list = (await this.$http.getHouseUserCondition(params)).data.data
  88. this.roomList = list.filter(item => this.isEmpty(item.memberId))
  89. this.roomList.forEach(item=>{
  90. item.checked=false
  91. item.address=item.residentialName+"-"+item.buildingName+"-"+item.unitName+"-"+item.roomName
  92. })
  93. if (this.$isNotEmpty(this.roomList)) {
  94. this.show = true
  95. }
  96. },
  97. isEmpty(data) {
  98. if (this.$isEmpty(data) || data == -1) {
  99. return true
  100. }
  101. return false
  102. },
  103. cancel(){
  104. uni.setStorageSync('cancelBind',true)
  105. this.show=false
  106. },
  107. confirm(){
  108. let checkList=this.roomList.filter(item=>item.checked)
  109. let ids= checkList.map(item=>item.id)
  110. if (this.$isEmpty(ids)) {
  111. this.$u.toast('至少选择一项')
  112. return
  113. }
  114. let params={
  115. memberId:this.vuex_member.id,
  116. ids
  117. }
  118. this.$http.bindRoom(this.vuex_member.id,ids).then(res=>{
  119. this.show=false
  120. if (res.data.success) {
  121. this.$u.toast('绑定成功')
  122. }else{
  123. this.$u.toast('操作失败')
  124. }
  125. })
  126. }
  127. }
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. </style>