deviceTransfer.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="container">
  3. <view class="content-container">
  4. <view class="shop-container">
  5. <view class="form-label">转移到</view>
  6. <view style="width: 100%" @tap="bindSelectShop">
  7. <text v-if="selectedShop">{{ selectedShop.shop_name }}</text>
  8. <text v-else style="color: #999">请选择转移用户</text>
  9. </view>
  10. <text class="btn-transfer" @tap="bindTransfer">转移</text>
  11. </view>
  12. </view>
  13. <view class="device-list-container">
  14. <view class="block-head">
  15. 设备信息
  16. <text style="font-size: 24rpx">(共{{ devicelist.length }})</text>
  17. </view>
  18. <view class="table">
  19. <view class="tb-head">
  20. <view class="tb-row">
  21. <view class="tb-column col-1">电池编号</view>
  22. <view class="tb-column col-2">型号</view>
  23. <view class="tb-column col-3">操作</view>
  24. </view>
  25. </view>
  26. <view class="tb-body">
  27. <view class="tb-row" v-for="(item, index) in devicelist" :key="index">
  28. <view class="tb-column col-1">{{ item.battery_sn }}</view>
  29. <view class="tb-column col-2">{{ item.dev_name }}</view>
  30. <view class="tb-column col-3">
  31. <text class="del-btn" @tap="bindDelDevice" :data-index="index">删除</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. // pages/deviceTransfer/deviceTransfer.js
  41. var config = require('../../common/config.js');
  42. var http = require('../../common/http.js');
  43. var common = require('../../common/common.js');
  44. var storage = require('../../common/storage.js');
  45. export default {
  46. data() {
  47. return {
  48. devicelist: [],
  49. selectedShop: null
  50. };
  51. }
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */,
  55. onLoad: function (options) {
  56. storage.setSelectedShop(null);
  57. const devicelist = storage.getBatchSelectedDeviceList();
  58. if (!devicelist || devicelist.length === 0) {
  59. uni.navigateBack({
  60. delta: 1
  61. });
  62. }
  63. this.setData({
  64. devicelist: devicelist
  65. });
  66. },
  67. onShow: function () {
  68. const selectedShop = storage.getSelectedShop();
  69. this.setData({
  70. selectedShop: selectedShop
  71. });
  72. },
  73. methods: {
  74. bindSelectShop: function () {
  75. uni.navigateTo({
  76. url: '/pages/selectShop/selectShop'
  77. });
  78. },
  79. bindTransfer: function () {
  80. if (!this.selectedShop) {
  81. common.simpleToast('请选择转移用户');
  82. return;
  83. }
  84. let batteryList = [];
  85. this.devicelist.forEach((item) => {
  86. batteryList.push(item.battery_id);
  87. });
  88. const pData = {
  89. shop_id: this.selectedShop.shop_id,
  90. batteryList: JSON.stringify(batteryList)
  91. };
  92. http.postApi(config.API_BATTERY_TRANSFER, pData, function (resp) {
  93. if (resp.data.code === 200) {
  94. storage.setRefreshDeviceoPage(true);
  95. common.simpleToast('转移成功');
  96. setTimeout(function () {
  97. uni.navigateBack({
  98. delta: 1
  99. });
  100. }, 1500);
  101. } else {
  102. common.simpleToast(resp.data.msg);
  103. }
  104. });
  105. },
  106. bindDelDevice: function (e) {
  107. const index = e.currentTarget.dataset.index;
  108. let devicelist = [];
  109. this.devicelist.forEach((item, idx) => {
  110. if (idx != index) {
  111. devicelist.push(item);
  112. }
  113. });
  114. this.setData({
  115. devicelist: devicelist
  116. });
  117. }
  118. }
  119. };
  120. </script>
  121. <style>
  122. @import './deviceTransfer.css';
  123. </style>