device.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='设备管理' bgColor="transparent"></cus-header>
  4. <block v-if="list.length">
  5. <div class="box" v-for="(item,index) in list" :key="index">
  6. <div class="name">{{item.board}}</div>
  7. <div class="btn" @tap="toUnBind(item)">解绑设备</div>
  8. </div>
  9. </block>
  10. <block v-else>
  11. <page-empty :height="'calc(100vh - 200px)'"></page-empty>
  12. </block>
  13. <div class="zt_btn" @tap="bindDevice">新增设备</div>
  14. </view>
  15. </template>
  16. <script>
  17. import pageEmpty from '@/components/pageEmpty/index.vue'
  18. export default {
  19. components:{pageEmpty},
  20. data(){
  21. return {
  22. agentId:'',
  23. list:[]
  24. }
  25. },
  26. onLoad(option) {
  27. this.agentId = option.agentId;
  28. this.getList();
  29. },
  30. methods:{
  31. getList(){
  32. this.$api.get(`/device/bind/${this.agentId}`).then(res=>{
  33. if(res.data.code!==0) return this.$showToast(res.data.msg)
  34. this.list = res.data.data;
  35. })
  36. },
  37. bindDevice(){
  38. uni.scanCode({
  39. success: (res) => {
  40. let result = JSON.parse(res.result);
  41. if(res.errMsg==='scanCode:ok'){
  42. this.$api.post('/device/bindAdd',{
  43. ...result,
  44. "type": "",
  45. "userId": 0,
  46. "agentId": this.agentId
  47. }).then(res=>{
  48. if(res.data.code!==0) return this.$showToast(res.data.msg)
  49. this.$showToast('新增设备成功');
  50. setTimeout(()=>{
  51. this.getList();
  52. },1000)
  53. })
  54. }
  55. }
  56. })
  57. },
  58. toUnBind(item){
  59. uni.showModal({
  60. title:'温馨提示',
  61. content:'确定要解绑该设备吗?',
  62. success: (res) => {
  63. this.$api.post('/device/unbind',{deviceId:item.id}).then(res=>{
  64. if(res.data.code!==0) return this.$showToast(res.data.msg)
  65. this.$showToast('解绑成功');
  66. setTimeout(()=>{
  67. this.getList();
  68. },1000)
  69. })
  70. }
  71. })
  72. }
  73. }
  74. }
  75. </script>
  76. <style scoped lang="less">
  77. .page{
  78. background: linear-gradient( 180deg, #E0EEFF 0%, #F6FCFF 100%);
  79. padding: 0 30rpx 200rpx;
  80. box-sizing: border-box;
  81. .box{
  82. background: #FFFFFF;
  83. border-radius: 16rpx;
  84. margin-top: 20rpx;
  85. .name{
  86. padding: 36rpx 24rpx;
  87. border-bottom: 1px solid #E2E2E2;
  88. font-family: PingFangSC, PingFang SC;
  89. font-weight: 400;
  90. font-size: 30rpx;
  91. color: #111111;
  92. line-height: 32rpx;
  93. }
  94. .btn{
  95. font-family: PingFang-SC, PingFang-SC;
  96. font-weight: bold;
  97. font-size: 28rpx;
  98. color: #0066FE;
  99. line-height: 32rpx;
  100. text-align: center;
  101. padding: 34rpx 0;
  102. }
  103. }
  104. .zt_btn{
  105. position: fixed;
  106. bottom: 64rpx;
  107. width: calc(100% - 120rpx);
  108. left: 60rpx;
  109. }
  110. }
  111. </style>