index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view style="padding: 30px 10px 10px;;margin-top: 20px;">
  3. <view style="text-align: right;margin: 0 20px 10px;">
  4. <image src="../../static/img/control/switch-user.png" style="width: 30px;height: 30px;"
  5. @click="isOutLoginShow()">
  6. </u-image>
  7. </view>
  8. <view class="controlDiv" v-for="item in data" @longpress="longpress(item)">
  9. <zai-lattice v-if="item.runningStatus === 0" class="controlBody" backgroundColor="#dae3dd" shadow
  10. progressColor='#cecece' type="img" :progressPercent='item.dosagePct' :title='item.deviceName'
  11. :num='item.dosage' :unit='item.dosageUnit' src="../../static/img/control/close.png"
  12. @click="latticeClick(item)" titleColor='#969696' unitColor="#969696" numColor="#969696" />
  13. <zai-lattice v-if="item.runningStatus === 1" class="controlBody" backgroundColor="#f6fff9" shadow
  14. progressColor='#26a495' type="img" :progressPercent='item.dosagePct' :title='item.deviceName'
  15. :num='item.dosage' :unit='item.dosageUnit' src="../../static/img/control/open.png"
  16. @click="latticeClick(item)" titleColor='#26a495' />
  17. </view>
  18. <view class="controlDiv">
  19. <zai-lattice :showNow="false" class="controlBody" backgroundColor="#dae3dd" titleColor='#26a495' shadow
  20. progressColor='#ffffff' type="img" title='新增' src="../../static/img/control/plus.png"
  21. @click="toForm()" />
  22. </view>
  23. <view>
  24. <u-action-sheet :actions="list" :title="title" :show="show" @close="close" @select="selectClick">
  25. </u-action-sheet>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import zaiLattice from "../../components/zai-lattice";
  31. export default {
  32. components: {
  33. zaiLattice
  34. },
  35. data() {
  36. return {
  37. openOrCloseButton: true,
  38. title: '操作',
  39. list: [{
  40. name: '编辑',
  41. type: 1,
  42. subname: "修改名称",
  43. color: '#000000',
  44. fontSize: '20'
  45. },
  46. {
  47. name: '电量统计',
  48. type: 5,
  49. subname: "月度统计",
  50. color: '#000000',
  51. fontSize: '20'
  52. },
  53. {
  54. name: '用时统计',
  55. type: 2,
  56. subname: "月度统计",
  57. color: '#000000',
  58. fontSize: '20'
  59. },
  60. {
  61. name: '定时设置',
  62. type: 3,
  63. subname: "智能启停",
  64. color: '#000000',
  65. fontSize: '20'
  66. },
  67. {
  68. name: '删除',
  69. type: 4,
  70. subname: "直接删除",
  71. color: '#000000',
  72. fontSize: '20'
  73. }
  74. ],
  75. show: false,
  76. data: [],
  77. form: {
  78. deviceInfoId: null,
  79. deviceId: null,
  80. useNoId: null,
  81. isOpenOrClose: null
  82. }
  83. }
  84. },
  85. onLoad() {
  86. this.getList()
  87. const value1 = uni.getStorageSync('userId');
  88. const value2 = uni.getStorageSync('token');
  89. if (!value1 && !value2) {
  90. this.$goto('../login/login');
  91. }
  92. },
  93. onShow() {
  94. this.getList()
  95. },
  96. onHide() {
  97. },
  98. onPullDownRefresh() {
  99. this.getList()
  100. uni.stopPullDownRefresh();
  101. },
  102. methods: {
  103. toForm() {
  104. this.$goto('form')
  105. },
  106. selectClick(index) {
  107. if (index.type === 1) {
  108. this.edit()
  109. } else if (index.type === 2) {
  110. this.$goto('stat?type=sc')
  111. } else if (index.type === 3) {
  112. this.$goto('timing')
  113. } else if (index.type === 4) {
  114. this.delete()
  115. } else if (index.type === 5) {
  116. this.$goto("stat?type=nh")
  117. }
  118. },
  119. async getList() {
  120. const {
  121. data: res
  122. } = await this.$httpRequest({
  123. url: '/api/control/list?userId=' + uni.getStorageSync('userId'),
  124. method: 'get',
  125. isNotErrorMsg: true
  126. });
  127. if (res.code === 200) {
  128. this.data = res.data
  129. console.log(this.data)
  130. } else {
  131. }
  132. },
  133. async openOrClose(item) {
  134. if (item.runningStatus === 0) {
  135. this.form.isOpenOrClose = 1
  136. } else {
  137. this.form.isOpenOrClose = 0
  138. }
  139. const {
  140. data: res
  141. } = await this.$httpRequest({
  142. url: '/api/control/openOrClose',
  143. method: 'post',
  144. data: this.form
  145. });
  146. setTimeout(() => {
  147. if (res.code === 200 && item.runningStatus === 0 || res.code === 500 && item
  148. .runningStatus === 1) {
  149. item.runningStatus = 1
  150. item.dosagePct = 100
  151. } else if (res.code === 500 && item.runningStatus === 0 || res.code === 200 && item
  152. .runningStatus === 1) {
  153. item.runningStatus = 0
  154. item.dosagePct = 0
  155. }
  156. this.openOrCloseButton = true
  157. }, 2000)
  158. },
  159. latticeClick(item) {
  160. if (this.openOrCloseButton) {
  161. this.openOrCloseButton = false
  162. this.form.deviceInfoId = item.id
  163. this.form.deviceId = item.deviceId
  164. this.form.useNoId = item.deviceUseNo
  165. if (item.runningStatus === 0) {
  166. item.dosagePct = 100
  167. } else {
  168. item.dosagePct = 0
  169. }
  170. this.openOrClose(item)
  171. }
  172. },
  173. longpress(item) {
  174. uni.setStorageSync("deviceInfo", item)
  175. this.show = true
  176. },
  177. isOutLoginShow() {
  178. uni.showModal({
  179. title: '提示',
  180. content: '是否退回到登录页面',
  181. confirmColor: '#26a495', //删除字体的颜色
  182. cancelColor: '#343047', //取消字体的颜色
  183. success: function(res) {
  184. if (res.confirm) {
  185. uni.clearStorageSync()
  186. uni.reLaunch({
  187. url: '../login/login'
  188. })
  189. } else if (res.cancel) {}
  190. }
  191. });
  192. },
  193. edit() {
  194. var that = this
  195. uni.showModal({
  196. title: '编辑',
  197. placeholderText: "修改名称",
  198. editable: true,
  199. confirmColor: '#26a495', //删除字体的颜色
  200. cancelColor: '#000000', //取消字体的颜色
  201. success: function(res) {
  202. if (res.confirm) {
  203. var data = uni.getStorageSync("deviceInfo")
  204. data.deviceName = res.content
  205. that.editDeviceInfo(data)
  206. uni.redirectTo({
  207. url: 'index'
  208. });
  209. } else if (res.cancel) {}
  210. }
  211. });
  212. },
  213. delete() {
  214. var that = this
  215. uni.showModal({
  216. title: '提示',
  217. content: "确认删除吗?",
  218. confirmColor: '#26a495', //删除字体的颜色
  219. cancelColor: '#000000', //取消字体的颜色
  220. success: function(res) {
  221. if (res.confirm) {
  222. var id = uni.getStorageSync("deviceInfo").id
  223. that.deleteDeviceInfo(id)
  224. } else if (res.cancel) {}
  225. }
  226. });
  227. },
  228. async deleteDeviceInfo(id) {
  229. const {
  230. data: res
  231. } = await this.$httpRequest({
  232. url: '/api/control/delete?deviceInfoId=' + id,
  233. method: 'get',
  234. });
  235. if (res.code === 200) {
  236. this.getList()
  237. } else {
  238. }
  239. },
  240. async editDeviceInfo(data) {
  241. const {
  242. data: res
  243. } = await this.$httpRequest({
  244. url: '/api/control/editDevice',
  245. method: 'put',
  246. data: data
  247. });
  248. if (res.code === 200) {
  249. } else {
  250. }
  251. },
  252. open() {
  253. // console.log('open');
  254. },
  255. close() {
  256. this.show = false
  257. // console.log('close');
  258. }
  259. }
  260. }
  261. </script>
  262. <style>
  263. page {
  264. background: linear-gradient(to bottom right, #ececec, #ececec);
  265. }
  266. .controlDiv {
  267. float: left;
  268. width: 50%;
  269. margin-bottom: 20px;
  270. border-radius: 10px;
  271. }
  272. </style>