merchantList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <!-- 机器销售列表页 -->
  2. <template>
  3. <view class="">
  4. <view v-if="id!=1">
  5. <view v-if="equipmentList.length>0">
  6. <uni-collapse :accordion="true">
  7. <uni-list>
  8. <uni-list-item :title="$t('merchantList.total')" @click="openByAdmin(merchantList[0].name,merchantList[0].id)" />
  9. <view class="titlelist" v-for="equipment in equipmentList" :key="equipment.id">
  10. <uni-list-item :title="getEquipmentTitle(equipment)" @click="openByEquipment(merchantList[0].name,equipment.id)" />
  11. </view>
  12. </uni-list>
  13. <view v-if="btnShow" class="button-container">
  14. <button v-if="upBtn" class="left-button" :disabled="isLoading" @click="previousPage">{{$t('equipmentStatusList.previousPage')}}</button>
  15. <button v-if="nextBtn" class="right-button" :disabled="isLoading" @click="nextPage">{{$t('equipmentStatusList.nextPage')}}</button>
  16. </view>
  17. </uni-collapse>
  18. </view>
  19. <view v-else style="text-align: center;">{{$t('merchantList.data')}}</view>
  20. </view>
  21. <view class="">
  22. <mix-tree :list="list" @treeItemClick="treeItemClick"></mix-tree>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. mapState,
  29. mapActions,
  30. mapMutations
  31. } from 'vuex'
  32. import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
  33. import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
  34. import uniList from '@/components/uni-list/uni-list.vue'
  35. import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
  36. import mixTree from '@/components/mix-tree/mix-tree'
  37. import {
  38. dateUtils
  39. } from '@/common/util.js';
  40. export default {
  41. components: {
  42. uniCollapse,
  43. uniCollapseItem,
  44. uniList,
  45. uniListItem,
  46. mixTree
  47. },
  48. data() {
  49. return {
  50. globalUser:{},
  51. merchantList: [{
  52. equipmentList: []
  53. }],
  54. equipmentList: [],
  55. extraIcon: {
  56. color: '#4cd964',
  57. size: '22',
  58. type: 'spinner'
  59. },
  60. id: null,
  61. pname:null,
  62. list: [],
  63. btnShow:false, // 按钮显示
  64. upBtn:false, // 上一页按钮
  65. nextBtn:true, // 下一页按钮
  66. equipmentTotal:0, // 设备总数
  67. isLoading: false, //是否加载中
  68. }
  69. },
  70. computed: {
  71. ...mapState(['loginUser']),
  72. },
  73. onShow() {
  74. uni.setNavigationBarTitle({title: this.$t('merchantList.title')});
  75. uni.setTabBarItem({ index: 1,text: this.$t('tabs.tab2')});
  76. this.globalUser = uni.getStorageSync("globalUser");
  77. this.id = this.globalUser.id;
  78. this.globalUser.offset = 0;
  79. this.globalUser.limit = 20;
  80. this.globalUser.todayDate = dateUtils.getCurrentDate();
  81. var token = uni.getStorageSync("token");
  82. if (token.length>1) {
  83. this.getEquipmentListData();
  84. this.upBtn = false;
  85. this.nextBtn = true;
  86. }else{
  87. uni.reLaunch({
  88. url: '../Login/Login',
  89. });
  90. }
  91. },
  92. onPullDownRefresh() {
  93. this.getEquipmentListData();
  94. },
  95. methods: {
  96. ...mapActions('chart', ['getEquipmentListByUser', 'getEquipmentListByProvince']),
  97. openByAdmin(pname, adminId) {
  98. uni.navigateTo({
  99. url: '../../packageB/pages/char/elseStatistics?adminId=' + adminId + '&pname=' + pname,
  100. });
  101. },
  102. openByEquipment(pname, equipmentId) {
  103. uni.navigateTo({
  104. url: '../../packageB/pages/char/elseStatistics?equipmentId=' + equipmentId + '&pname=' + pname,
  105. });
  106. },
  107. //点击最后一级时触发该事件
  108. treeItemClick(item) {
  109. let {
  110. id,
  111. name,
  112. parentId
  113. } = item;
  114. if(name=="总销售情况"){
  115. var token = uni.getStorageSync("token");
  116. uni.request({
  117. url: this.serverurl + '/TAdmin/findById',
  118. data: {
  119. "id": id,
  120. },
  121. method: "POST",
  122. header:{
  123. 'token':token
  124. },
  125. success: (res) => {
  126. this.pname = res.data.data.name;
  127. uni.navigateTo({
  128. url: '../../packageB/pages/char/elseStatistics?adminId=' + id + '&pname=' + this.pname,
  129. });
  130. }
  131. })
  132. }else{
  133. var token = uni.getStorageSync("token");
  134. uni.request({
  135. url: this.serverurl + '/TEquipment/findByEquipment',
  136. data: {
  137. "id": id,
  138. },
  139. method: "POST",
  140. header:{
  141. 'token':token
  142. },
  143. success: (res) => {
  144. this.pname = res.data.data.name;
  145. uni.navigateTo({
  146. url: '../../packageB/pages/char/elseStatistics?equipmentId=' + id + '&pname=' + this.pname,
  147. });
  148. }
  149. })
  150. }
  151. console.log(item)
  152. },
  153. getMerchantTitle(merchant) {
  154. return merchant.name ? merchant.name : merchant.username;
  155. },
  156. getEquipmentTitle(equipment) {
  157. return equipment.name ? equipment.name : equipment.clientId;
  158. },
  159. getEquipmentListData() {
  160. if(this.id ==1){
  161. // this.getEquipmentListByProvince(this.globalUser)
  162. // .then(data => {
  163. // this.list = data;
  164. // }, _ => void uni.stopPullDownRefresh());
  165. uni.showToast({
  166. icon: 'none',
  167. title:'暂时无法查看数据',
  168. });
  169. return;
  170. }else{
  171. this.isLoading = true;
  172. this.getEquipmentListByUser(this.globalUser)
  173. .then(data => {
  174. this.merchantList = data;
  175. this.equipmentList = data[0].equipmentList;
  176. this.equipmentTotal = this.merchantList[0].equipmentTotal;
  177. if(this.equipmentTotal > this.globalUser.limit) {
  178. this.btnShow = true;
  179. }
  180. console.log(this.equipmentList);
  181. this.isLoading = false;
  182. var listName = data[0].equipmentList;
  183. var listId = data[0].id;
  184. if(listId!=null && listId!='1'){
  185. uni.setStorageSync("listName",listName);
  186. }
  187. uni.stopPullDownRefresh();
  188. }
  189. , _ => void uni.stopPullDownRefresh());
  190. }
  191. },
  192. // 更改按钮显示状态
  193. changeBtnshow() {
  194. if(this.globalUser.offset != 0) {
  195. this.upBtn = true;
  196. } else {
  197. this.upBtn = false;
  198. }
  199. if(this.globalUser.offset + this.globalUser.limit < this.equipmentTotal) {
  200. this.nextBtn = true;
  201. } else {
  202. this.nextBtn = false;
  203. }
  204. },
  205. // 点击上一页
  206. previousPage() {
  207. this.globalUser.offset = this.globalUser.offset - this.globalUser.limit;
  208. this.getEquipmentListData();
  209. this.changeBtnshow();
  210. },
  211. // 点击下一页
  212. nextPage() {
  213. this.globalUser.offset = this.globalUser.offset + this.globalUser.limit;
  214. this.getEquipmentListData();
  215. this.changeBtnshow();
  216. },
  217. }
  218. }
  219. </script>
  220. <style>
  221. .titlelist {
  222. color: #363D44;
  223. font-size: 16upx;
  224. font-family: "PingFang-SC-Medium";
  225. }
  226. .button-container {
  227. display: flex;
  228. }
  229. .left-button,
  230. .right-button {
  231. flex: 1;
  232. }
  233. </style>