deviceTransfer.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="container">
  3. <view class="content-container">
  4. <view class="shop-container">
  5. <view class="form-label">{{$t('转移到')}}</view>
  6. <view style="width: 100%" @tap="bindSelectShop">
  7. <text v-if="selectedShop">{{ selectedShop.shop_name }}</text>
  8. <text v-else style="color: #999">{{$t('请选择转移用户')}}</text>
  9. </view>
  10. <text class="btn-transfer" @tap="bindTransfer">{{$t('转移')}}</text>
  11. </view>
  12. </view>
  13. <view class="device-list-container">
  14. <view class="block-head">
  15. {{$t('设备信息')}}
  16. <text style="font-size: 24rpx">({{ $t('共') + 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">{{$t('电池编号')}}</view>
  22. <view class="tb-column col-2">{{$t('型号')}}</view>
  23. <view class="tb-column col-3">{{$t('操作')}}</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">{{$t('删除')}}</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. // myPages/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. uni.setNavigationBarTitle({
  57. title: this.$t('设备转移')
  58. });
  59. storage.setSelectedShop(null);
  60. const devicelist = storage.getBatchSelectedDeviceList();
  61. if (!devicelist || devicelist.length === 0) {
  62. uni.navigateBack({
  63. delta: 1
  64. });
  65. }
  66. this.setData({
  67. devicelist: devicelist
  68. });
  69. },
  70. onShow: function () {
  71. const selectedShop = storage.getSelectedShop();
  72. this.setData({
  73. selectedShop: selectedShop
  74. });
  75. },
  76. methods: {
  77. bindSelectShop: function () {
  78. uni.navigateTo({
  79. url: '/myPages/pages/selectShop/selectShop'
  80. });
  81. },
  82. bindTransfer: function () {
  83. const that = this
  84. if (!this.selectedShop) {
  85. common.simpleToast(that,that.$t('请选择转移用户'));
  86. return;
  87. }
  88. let batteryList = [];
  89. this.devicelist.forEach((item) => {
  90. batteryList.push(item.battery_id);
  91. });
  92. const pData = {
  93. shop_id: this.selectedShop.shop_id,
  94. batteryList: JSON.stringify(batteryList)
  95. };
  96. http.postApi(config.API_BATTERY_TRANSFER, pData, function (resp) {
  97. if (resp.data.code === 200) {
  98. storage.setRefreshDeviceoPage(true);
  99. common.simpleToast(that,that.$t('转移成功'));
  100. setTimeout(function () {
  101. uni.navigateBack({
  102. delta: 1
  103. });
  104. }, 1500);
  105. } else {
  106. common.simpleToast(that,resp.data.msg);
  107. }
  108. });
  109. },
  110. bindDelDevice: function (e) {
  111. const index = e.currentTarget.dataset.index;
  112. let devicelist = [];
  113. this.devicelist.forEach((item, idx) => {
  114. if (idx != index) {
  115. devicelist.push(item);
  116. }
  117. });
  118. this.setData({
  119. devicelist: devicelist
  120. });
  121. }
  122. }
  123. };
  124. </script>
  125. <style>
  126. @import './deviceTransfer.css';
  127. </style>