index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view>
  3. <cu-custom
  4. ref="custom"
  5. id="custom"
  6. bgImage="https://yostest175549.obs.cn-east-2.myhuaweicloud.com:443/202306151686796745663B52544232.png"
  7. :isBack="isBack"
  8. >
  9. <block slot="backText">返回</block>
  10. <block slot="content"> 设备中心 </block>
  11. </cu-custom>
  12. <My_search
  13. :heightReduction="heightReduction"
  14. ref="Search"
  15. @onFilter="onFilter"
  16. @startSearch="startSearch"
  17. :filter="filter"
  18. >
  19. <template slot="left">
  20. <view
  21. class="change"
  22. hover-class="navigator-hover"
  23. @click="changePage(PageCur == '设备列表' ? '设备地图' : '设备列表')"
  24. >
  25. {{ PageCur == "设备列表" ? "地图" : "列表" }}
  26. </view>
  27. </template>
  28. </My_search>
  29. <list
  30. ref="设备列表"
  31. :tabHeight="tabHeight"
  32. :empty="empty"
  33. :list="list"
  34. v-show="PageCur == '设备列表'"
  35. />
  36. <my-map
  37. ref="设备地图"
  38. :tabHeight="tabHeight"
  39. :markers="markers"
  40. v-show="PageCur == '设备地图'"
  41. />
  42. </view>
  43. </template>
  44. <script>
  45. import list from "./list.vue";
  46. import myMap from "./my-map.vue";
  47. export default {
  48. components: { list, myMap },
  49. props: {
  50. tabHeight: Number,
  51. },
  52. name: "facility",
  53. data() {
  54. return {
  55. condition: "",
  56. empty: false,
  57. isBack: true,
  58. uninitialized: true,
  59. PageCur: "设备列表",
  60. list: [],
  61. markers: [],
  62. where: {
  63. condition: "",
  64. status: "",
  65. },
  66. filter: [
  67. {
  68. label: "状态",
  69. list: [
  70. {
  71. status: "全部",
  72. value: "",
  73. },
  74. {
  75. status: "在线",
  76. value: "在线",
  77. },
  78. {
  79. status: "离线",
  80. value: "离线",
  81. },
  82. {
  83. status: "禁用",
  84. value: "禁用",
  85. },
  86. ],
  87. key: "status",
  88. selectKey: "value",
  89. showKey: "status",
  90. default: "0",
  91. selectIndex: 1,
  92. },
  93. ],
  94. heightReduction: 0,
  95. };
  96. },
  97. onLoad(options) {
  98. if (options.status) this.where.status = options.status;
  99. this.getlist();
  100. this.$Http.updateFacilityList = this.getlist.bind(this);
  101. setTimeout(() => this.loadElement(), 100);
  102. },
  103. methods: {
  104. init() {
  105. this.getlist();
  106. this.PageCur = "设备地图";
  107. this.isBack = false;
  108. this.heightReduction = 45;
  109. setTimeout(
  110. () =>
  111. this.loadElement(true, {
  112. mode: "minus",
  113. num: 50,
  114. }),
  115. 100
  116. );
  117. },
  118. changePage(page) {
  119. this.PageCur = page;
  120. this.loadElement();
  121. },
  122. loadElement(forcedUpdating, data) {
  123. let page = this.$refs[this.PageCur];
  124. if (page.uninitialized || forcedUpdating) page.init();
  125. },
  126. getlist() {
  127. return new Promise((resolve) => {
  128. this.$Http
  129. .basic({
  130. id: 20230711144102,
  131. content: {
  132. nocache: true,
  133. pageNumber: 1,
  134. pageSize: 99999,
  135. where: this.where,
  136. },
  137. })
  138. .then((res) => {
  139. console.log("设备列表", res);
  140. if (this.cutoff(res.msg)) return;
  141. resolve(res.msg == "成功");
  142. this.empty = res.data.length == 0;
  143. this.$refs.Search.onFinish();
  144. this.markers = res.data
  145. .filter((v) => v.latitude)
  146. .map((v) => {
  147. v.id = v.w_deviceid - 0;
  148. v.title = v.devicename;
  149. v.label = {
  150. content: v.devicename,
  151. textAlign: "center",
  152. bgColor:"#fff"
  153. };
  154. if (this.usePort == "h5") {
  155. v.iconPath = require("../../static/img/location.png");
  156. }
  157. v.customCallout = { display: "BYCLICK", anchorY: -10 };
  158. return v;
  159. });
  160. this.list = res.data.map((v) => {
  161. switch (v.status) {
  162. case "在线":
  163. v.bgColor = "#3C9CFF";
  164. break;
  165. case "禁用":
  166. v.bgColor = "#F56C6C";
  167. break;
  168. default:
  169. v.bgColor = "#F9AE3D";
  170. break;
  171. }
  172. return v;
  173. });
  174. });
  175. });
  176. },
  177. startSearch(condition) {
  178. if (condition == this.where.condition) return;
  179. this.where.condition = condition;
  180. this.getlist();
  181. },
  182. onFilter(where) {
  183. console.log("开始筛选", where);
  184. where.condition = this.where.condition;
  185. this.where = where;
  186. this.getlist();
  187. },
  188. },
  189. };
  190. </script>
  191. <style lang="scss" scoped>
  192. /deep/.My_search {
  193. padding-left: 0 !important;
  194. }
  195. .change {
  196. height: 30px;
  197. line-height: 30px;
  198. text-align: center;
  199. margin-left: 5px;
  200. font-size: 14px;
  201. color: #ffffff;
  202. border-radius: 4px;
  203. padding: 0 10px;
  204. margin-right: 5px;
  205. border-radius: 4px;
  206. }
  207. </style>