simDetail.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="sim-details-page">
  3. <cu-custom :isBack="true">
  4. <template slot="content">
  5. <view class="nav-title">SIM卡详情</view>
  6. </template>
  7. </cu-custom>
  8. <!-- 加载动画 -->
  9. <view v-if="loading" class="loading-container">
  10. <u-loading mode="circle"></u-loading>
  11. <text class="loading-text">加载中...</text>
  12. </view>
  13. <!-- 页面内容 -->
  14. <view v-else>
  15. <view class="sim-first sim-board">
  16. <view class="title">数据SIM卡流量</view>
  17. <view class="sim-item">
  18. <text class="label">ICCID:</text>
  19. <span class="val">{{ simData.iccid }}</span>
  20. <image
  21. @click="copy(simData.iccid)"
  22. src="/static/images/device/copy.svg"
  23. mode=""
  24. class="info-img"
  25. ></image>
  26. </view>
  27. <view class="sim-item">
  28. <text class="label">总流量:</text>
  29. <span class="val">{{ simData.total }}</span>
  30. </view>
  31. <view class="sim-item">
  32. <text class="label">状态:</text>
  33. <text class="val">{{ simData.status }}</text>
  34. </view>
  35. <view class="sim-item">
  36. <text class="label">到期时间:</text>
  37. <text class="val">{{ simData.expire }}</text>
  38. </view>
  39. <view class="sim-item">
  40. <text class="label">厂商名称:</text>
  41. <text class="val">{{ simData.company }}</text>
  42. </view>
  43. <view class="sim-info-count">
  44. <view class="sim-item">
  45. <text class="label">已使用:</text
  46. ><text
  47. :style="{
  48. color:
  49. simData.used > parseInt(simData.total) ? '#f56c6c' : '#14A478',
  50. }"
  51. >{{ simData.used.toFixed(2) }}M</text
  52. >/{{ simData.total }}
  53. </view>
  54. <view class="sim-item">
  55. <text class="label">剩余:</text>
  56. <text
  57. class="val"
  58. :style="{
  59. color: '#14A478',
  60. }"
  61. >{{ (parseInt(simData.total) - simData.used).toFixed(2) }}M</text
  62. >
  63. </view>
  64. </view>
  65. </view>
  66. <view v-if="simIccidObj.photo_iccid || simIccidObj.is_editor" class="sim-board sim-second">
  67. <view class="title">图片SIM卡流量</view>
  68. <view class="sim-item">
  69. <text class="label">ICCID:</text>
  70. <span v-if="!isEditing" class="val">{{ simData.iccid }}</span>
  71. <input
  72. v-else
  73. v-model="editingIccid"
  74. type="text"
  75. class="edit-input"
  76. placeholder="请输入新的ICCID"
  77. />
  78. <image
  79. @click="copy(isEditing ? editingIccid : simData.iccid)"
  80. src="/static/images/device/copy.svg"
  81. mode=""
  82. class="info-img"
  83. ></image>
  84. <image
  85. v-if="!isEditing"
  86. @click="toggleEdit"
  87. src="/static/images/device/edit.svg"
  88. mode=""
  89. class="info-img"
  90. ></image>
  91. <button v-else @click="saveEditIccid" class="save-btn">确定</button>
  92. </view>
  93. </view>
  94. <view class="footer-board">
  95. <u-button type="success" class="sub-btn" @click="goBack"
  96. >确定</u-button
  97. >
  98. </view>
  99. </view>
  100. </view>
  101. </template>
  102. <script>
  103. export default {
  104. onLoad(options) {
  105. this.loading = true
  106. const deviceInfo = JSON.parse(decodeURIComponent(options.deviceInfo));
  107. console.log(deviceInfo, "deviceInfo");
  108. this.deviceInfo = deviceInfo;
  109. this.getIccidByd_id();
  110. },
  111. data() {
  112. return {
  113. deviceInfo: {},
  114. simData: {
  115. iccid: "",
  116. total: "",
  117. status: "",
  118. expire: "",
  119. company: "",
  120. used: 0,
  121. },
  122. isEditing: false,
  123. editingIccid: "",
  124. showSimData: false,
  125. empty: false,
  126. simIccidObj: {},
  127. loading: false,
  128. };
  129. },
  130. methods: {
  131. getIccidByd_id() {
  132. this.$myRequest({
  133. url: "/api/api_gateway?method=forecast.send_control.device_sim_new",
  134. data: {
  135. d_id: this.deviceInfo.d_id,
  136. },
  137. }).then((res) => {
  138. console.log('getIccidByd_id:', res);
  139. if (
  140. res.data_iccid ||
  141. res.photo_iccid ||
  142. res.is_editor
  143. ) {
  144. console.log(res, '1111')
  145. this.empty = false;
  146. this.simIccidObj = res;
  147. if (res.data_iccid) {
  148. this.active = "data_iccid";
  149. console.log(222)
  150. this.getSimData(res.data_iccid);
  151. } else {
  152. if (res.photo_iccid || res.is_editor) {
  153. this.active = "photo_iccid";
  154. if (res.photo_iccid) {
  155. this.getSimData(res.photo_iccid);
  156. } else {
  157. this.loading = false;
  158. }
  159. }
  160. }
  161. } else {
  162. this.empty = true;
  163. this.loading = false;
  164. }
  165. });
  166. },
  167. getSimData(iccid) {
  168. this.$myRequest({
  169. url: "/api/api_gateway?method=forecast.send_control.sim_query_new",
  170. data: {
  171. iccid: iccid
  172. }
  173. }).then(res => {
  174. console.log('simData:', res)
  175. this.loading = false
  176. this.simData = res
  177. if (res.code) {
  178. this.showSimData = false
  179. // this.$message.error(res.data.data.msg)
  180. } else {
  181. this.showSimData = true
  182. this.simData = res
  183. this.editIccid = res.iccid
  184. }
  185. })
  186. },
  187. copy(item) {
  188. console.log(item);
  189. uni.setClipboardData({
  190. data: item,
  191. success: function () {
  192. console.log("success");
  193. },
  194. });
  195. },
  196. toggleEdit() {
  197. this.isEditing = !this.isEditing;
  198. if (this.isEditing) {
  199. this.editingIccid = this.simData.iccid;
  200. }
  201. },
  202. saveIccid() {
  203. this.simData.iccid = this.editingIccid;
  204. this.isEditing = false;
  205. },
  206. saveEditIccid() {
  207. this.$myRequest({
  208. url: '/api/api_gateway?method=forecast.send_control.device_sim_update',
  209. data: {
  210. d_id: this.deviceInfo.d_id,
  211. simid: this.editingIccid
  212. }
  213. }).then(res => {
  214. if (res.code) {
  215. this.isEditSim = false
  216. this.loading = true
  217. // this.$message.success(res.data.data.msg)
  218. this.simIccidObj.photo_iccid = this.editingIccid
  219. this.getSimData(this.editingIccid)
  220. } else {
  221. // this.$message.error(res.data.data.msg)
  222. }
  223. this.isEditing = false;
  224. })
  225. },
  226. goBack() {
  227. uni.navigateBack({
  228. delta: 1,
  229. })
  230. },
  231. },
  232. };
  233. </script>
  234. <style lang="scss">
  235. .sim-details-page {
  236. background:
  237. linear-gradient(180deg, #ffffff00 0%, #f5f6fa 23.64%, #f5f6fa 100%),
  238. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  239. min-height: 100vh;
  240. padding: 0 32rpx;
  241. padding-top: 98rpx;
  242. box-sizing: border-box;
  243. }
  244. /* 加载动画样式 */
  245. .loading-container {
  246. display: flex;
  247. flex-direction: column;
  248. align-items: center;
  249. justify-content: center;
  250. height: 60vh;
  251. width: 100%;
  252. }
  253. .loading-text {
  254. font-size: 28rpx;
  255. color: #666;
  256. margin-top: 32rpx;
  257. }
  258. .sim-board {
  259. padding: 32rpx;
  260. border-radius: 16rpx;
  261. background: #fff;
  262. margin-top: 46rpx;
  263. margin-bottom: 24rpx;
  264. .title {
  265. color: #020305;
  266. font-size: 32rpx;
  267. font-weight: 500;
  268. margin-bottom: 24rpx;
  269. }
  270. .sim-item {
  271. font-size: 28rpx;
  272. display: flex;
  273. align-items: center;
  274. margin-bottom: 24rpx;
  275. .label {
  276. color: #999999;
  277. }
  278. .val {
  279. color: #303133;
  280. }
  281. .copy-icon,
  282. .edit-icon {
  283. width: 32rpx;
  284. height: 32rpx;
  285. }
  286. }
  287. .sim-info-count {
  288. display: flex;
  289. justify-content: space-between;
  290. }
  291. }
  292. .footer-board {
  293. border-top: 2rpx solid #e4e7ed;
  294. background: #fff;
  295. position: fixed;
  296. bottom: 0;
  297. left: 0;
  298. right: 0;
  299. height: 164rpx;
  300. padding: 16rpx 32rpx 0 32rpx;
  301. .sub-btn {
  302. width: 100%;
  303. background: #0bbc58;
  304. border-radius: 16rpx;
  305. }
  306. }
  307. .info-img {
  308. width: 32rpx;
  309. height: 32rpx;
  310. margin-left: 16rpx;
  311. background: #0bbc581a;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. }
  316. .edit-input {
  317. flex: 1;
  318. height: 48rpx;
  319. border: 2rpx solid #0bbc58;
  320. border-radius: 8rpx;
  321. padding: 0 16rpx;
  322. font-size: 28rpx;
  323. color: #303133;
  324. background-color: #f5f7fa;
  325. }
  326. .save-btn {
  327. margin-left: 16rpx;
  328. padding: 8rpx 20rpx;
  329. background-color: #0bbc58;
  330. color: #fff;
  331. border: none;
  332. border-radius: 8rpx;
  333. font-size: 24rpx;
  334. height: 48rpx;
  335. line-height: 28rpx;
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. }
  340. </style>