merchantList.vue 5.9 KB

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