merchantList.vue 6.1 KB

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