index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="device-layout">
  3. <div class="plate">
  4. <template v-if="tabActive===4">
  5. <div class="d-item" v-for="(item,i) in mydevice.list" :key="i" >
  6. <img :src="`${$cdn}images/banner_pro.png`" alt="">
  7. <img v-if="item.spaceEndTime" class="king" :src="`${$cdn}images/icon-huiyuan.png`" alt="">
  8. <div class="eight-right">
  9. <p class="i-title">ID:{{item.childName}}</p>
  10. <p class="i-dec">云存储空间</p>
  11. <div class="capacity">
  12. <div class="c-line">
  13. <div class="active" :style="{width:getBar(item.usedSpace,item.totalSpace)}"></div>
  14. </div>
  15. </div>
  16. <p class="i-dec">{{item.usedSpaceStr}} / {{item.totalSpaceStr}}</p>
  17. <div class="btn-con">
  18. <span class="btn" @click="unbind(item)">解绑</span>
  19. <span class="btn" @click="$router.push({name:'introduce',params:{id:item.childName}})">扩容</span>
  20. <span class="btn primary" v-if="!item.spaceEndTime" @click="$router.push({name:'privilege',params: {
  21. cameraId: item.id,
  22. childName: item.childName
  23. }})">升级</span>
  24. <span class="btn" @click="$router.push({name:'introduce',params:{id:item.childName}})" v-else >续期</span>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <template v-else>
  30. <div class="d-item" v-for="(item,i) in mydevice.list" :key="i">
  31. <img :src="`${$cdn}images/t_product.png`" alt="">
  32. <div class="item-right">
  33. <p class="i-title">ID:{{item.childName}}</p>
  34. <p class="i-dec">剩余点数:</p>
  35. <div class="btn-con">
  36. <span>{{item.balance}}</span>
  37. <div>
  38. <span class="btn" @click="unbind(item)">解绑</span>
  39. <span class="btn primary" @click="$router.push({name:'introtow',params:{id:item.childName}})">充值</span>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <div class="scene-nothing" v-if="!total">
  46. <img src="@/assets/images/nothing.png">
  47. <div>居然还没有新时代空间建模神器<br/>赶紧入手吧</div>
  48. </div>
  49. <div class="paging" v-if="total">
  50. <Paging @clickHandle="pageChange" :current="currentPage" :total="total" :equable="pageSize"/>
  51. </div>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { mapState } from 'vuex'
  57. import Paging from '@/components/Paging'
  58. export default {
  59. components: { Paging },
  60. data () {
  61. let tabList = [
  62. {
  63. name: '四维看看Pro',
  64. id: 4
  65. }, {
  66. name: '四维看看Lite',
  67. id: 0
  68. }
  69. ]
  70. return {
  71. tabList,
  72. tabActive: 4,
  73. currentPage: 1,
  74. total: 0,
  75. searchKey: '',
  76. pageSize: 8
  77. }
  78. },
  79. computed: {
  80. ...mapState({
  81. token: state => state.user.token,
  82. mydevice: state => {
  83. let type = Object.prototype.toString.call(state.user.mydevice)
  84. if (type === '[object Object]') {
  85. return state.user.mydevice
  86. }
  87. let condition = state.user.mydevice && state.user.mydevice !== 'null' && type !== '[object Array]'
  88. return (condition ? JSON.parse(state.user.mydevice) : {})
  89. }
  90. })
  91. },
  92. methods: {
  93. getPercent (a, b) {
  94. let temp = a / b
  95. if (temp < 1) {
  96. return '<1'
  97. }
  98. return Math.round(temp)
  99. },
  100. getBar (a, b) {
  101. let temp = a / b
  102. if (temp < 1) {
  103. return '1%'
  104. }
  105. return Math.round(temp) + '%'
  106. },
  107. async unbind (item) {
  108. this.$toast.showConfirm('warn', '确定要解绑当前设备吗?', async () => {
  109. let params = {
  110. cameraId: item.id
  111. }
  112. let res = await this.$http({
  113. method: 'post',
  114. data: params,
  115. headers: {
  116. token: this.token
  117. },
  118. url: '/user/camera/unbind'
  119. })
  120. let data = res.data
  121. if (data.code === 0) {
  122. return this.$toast.show('warn', '解绑成功', () => {
  123. this.getList()
  124. })
  125. }
  126. return this.$toast.show('error', `解绑失败,${data.msg}`)
  127. })
  128. },
  129. pageChange (data) {
  130. this.currentPage = data
  131. },
  132. addDevice () {
  133. let val = this.tabActive === 4 ? 1 : 0
  134. this.$toast.showBinding(val, () => {
  135. this.getList()
  136. })
  137. },
  138. async getList (searchKey = '') {
  139. window.scrollTo(0, 0)
  140. let params = {
  141. cameraType: this.tabActive,
  142. childName: searchKey,
  143. pageNum: searchKey ? 1 : this.currentPage,
  144. pageSize: this.pageSize
  145. }
  146. await this.$store.dispatch('getUserDevice', params)
  147. if (!this.mydevice.total && searchKey) {
  148. return this.$toast.show('warn', '没有找到对应的设备', () => {
  149. this.getList()
  150. })
  151. }
  152. this.pageSize = this.mydevice.pageSize
  153. this.total = this.mydevice.total || 0
  154. }
  155. },
  156. mounted () {
  157. this.getList()
  158. this.$bus.$on('selectdevice', id => {
  159. this.tabActive = id
  160. })
  161. },
  162. watch: {
  163. currentPage () {
  164. this.getList()
  165. },
  166. tabActive (newVal) {
  167. this.currentPage === 1 ? this.getList() : this.currentPage = 1
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. $theme-color: #1fe4dc;
  174. .btn{
  175. width: 72px;
  176. display: inline-block;
  177. border: solid 1px #ddd;
  178. line-height: 32px;
  179. height: 32px;
  180. text-align: center;
  181. border-radius: 2px;
  182. }
  183. .primary{
  184. background-color: $theme-color;
  185. border-color: $theme-color;
  186. }
  187. .device-layout{
  188. background: #f6f9fd;
  189. .plate{
  190. .scene-nothing{
  191. background: #fff;
  192. text-align: center;
  193. padding:40px 0;
  194. img{
  195. padding-bottom: 22px;
  196. }
  197. div{
  198. font-size: 14px;
  199. color: #969696;
  200. }
  201. }
  202. .d-item{
  203. position: relative;
  204. background: #fff;
  205. margin: 10px 0;
  206. padding: 10px 0;
  207. img{
  208. position: absolute;
  209. width: 30px;
  210. top: 50%;
  211. left: 15%;
  212. transform: translate(-50%, -50%);
  213. }
  214. .king{
  215. top: 21%;
  216. left: 19.5%;
  217. }
  218. .item-right,.eight-right{
  219. height: 90px;
  220. margin-left: 30%;
  221. margin-right: 16px;
  222. .i-title{
  223. font-size: 16px;
  224. color: #2d2d2d;
  225. margin-bottom: 10px;
  226. font-weight: bold;
  227. }
  228. .i-dec{
  229. margin-bottom: 10px;
  230. font-size: 14px;
  231. color: #777;
  232. }
  233. .capacity{
  234. margin: 5px 0;
  235. .c-line{
  236. width: 64%;
  237. height: 8px;
  238. background-color: #ccc;
  239. .active{
  240. background-color:$theme-color;
  241. height: 100%;
  242. }
  243. }
  244. }
  245. .btn-con{
  246. display: flex;
  247. width: 100%;
  248. justify-content: space-between;
  249. }
  250. }
  251. .eight-right{
  252. height: 130px;
  253. }
  254. }
  255. }
  256. .paging {
  257. // border-left: #e5e5e5 1px solid;
  258. height: 100%;
  259. padding-bottom: 20px;
  260. & /deep/ .layout {
  261. text-align: center;
  262. margin-top: 20px;
  263. }
  264. & /deep/ .layout a:not(:last-child) {
  265. margin: 10px 8px;
  266. font-size: 16px;
  267. display: inline-block;
  268. font-weight: 500;
  269. cursor: pointer;
  270. user-select: none;
  271. color: #999;
  272. position: relative;
  273. transition: color 0.3s;
  274. }
  275. & /deep/ .layout a:not(:last-child).active::after,
  276. & /deep/ .layout a:not(:last-child).active,
  277. & /deep/ .layout a:not(:last-child):hover,
  278. & /deep/ .layout a:not(:last-child):hover::after {
  279. color: #111111;
  280. transform: scaleX(1);
  281. }
  282. & /deep/ .layout a:not(:last-child)::after {
  283. content: "";
  284. height: 3px;
  285. width: 140%;
  286. background-color: #111;
  287. display: block;
  288. margin-left: -20%;
  289. margin-top: 3px;
  290. transform-origin: 50% 50%;
  291. transform: scaleX(0);
  292. will-change: transform;
  293. transition: transform 0.3s;
  294. }
  295. }
  296. }
  297. </style>