健康同学微信公众号h5项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 satır
10KB

  1. <template>
  2. <div class="familyNumber">
  3. <van-nav-bar title="亲情号码" left-arrow :borvan-tabbarder="true" @click-left="onNavBack">
  4. <van-icon name="plus" slot="right" @click="onAddNumber" />
  5. </van-nav-bar>
  6. <div class="management" v-show="isPageShow">
  7. <div v-if="listData.length > 0">
  8. <van-cell v-for="(item, index) in listData" :key="index">
  9. <van-swipe-cell>
  10. <div class="conArea">
  11. <div class="con" @click="conClick(item)">
  12. <span class="cell">{{ item.relationship }}</span>
  13. <span>
  14. {{ item.phone }}
  15. <i>(快捷键 {{ item.PressKey == '' ? '无' : item.PressKey }})</i>
  16. <van-icon name="lock" v-if="!item.Editable && item.AppType == familyNumberModel.appType.manufactor" />
  17. </span>
  18. </div>
  19. <em class="fs30" v-show="!isUnicom"
  20. ><span>{{ item.SOS == 1 ? 'SOS' : '' }}</span></em
  21. >
  22. <!-- 增加物联网卡提示,标识亲情号码是否已经下发同步成功 0,1 同步成功, 2同步中-->
  23. <em class="fs30" v-show="isUnicom" @click="onClickEm">
  24. <span>{{ item.SOS == 1 ? 'SOS' : '' }}</span>
  25. {{ item.status >= 2 ? '同步中' : '' }}
  26. </em>
  27. </div>
  28. <template slot="right">
  29. <van-button square type="danger" text="删除" @click="onDelete(item)" />
  30. </template>
  31. </van-swipe-cell>
  32. </van-cell>
  33. </div>
  34. <div class="newsNotData" v-else>您还没添加亲情号码,赶紧去添加吧~</div>
  35. <div class="tips-container" v-if="isUnicom">
  36. <div class="inside-tips">
  37. <p>注:</p>
  38. <p>1)由于网络因素影响,亲情号码设置后,最长需要等待10分钟后才可拨打。</p>
  39. <p>
  40. 2)设备最多可设置{{
  41. setPhoneNumber
  42. }}个亲情号码,添加首月无法删除,次月起每月最多允许删除1个亲情号,请慎重操作。
  43. </p>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import { DeviceCommandModel, FamilyNumberModel } from '@/config/models';
  51. import DialogService from '@/services/dialog-service';
  52. import ToastService from '@/services/toast-service';
  53. import APICommand from '@/api/command';
  54. export default {
  55. computed: {
  56. familyNumberModel() {
  57. return FamilyNumberModel;
  58. },
  59. // 获取物联网卡号码,非空为物联网卡,空则为普通电话卡,不显示提示
  60. isUnicom() {
  61. return this.$store.getters.uniPhone !== '';
  62. },
  63. // 截取物联网卡前3个数字,148是移动,其它是联通,移动可设5个亲情号码,联通可设10个
  64. setPhoneNumber() {
  65. const startNumber = this.$store.getters.uniPhone.slice(0, 3);
  66. return startNumber === '148' ? 5 : 10;
  67. }
  68. },
  69. data() {
  70. return {
  71. listData: [],
  72. numberMax: 30,
  73. familyNameList: [], //亲情号码名字
  74. familyShortKeyList: [], //亲情号码快捷键
  75. uniWhiteList: [], //第三方物联网卡列表
  76. // 测试数据,不需要后可删除
  77. testList: [{ phone: '15111511', status: 2 }],
  78. isPageShow: false
  79. };
  80. },
  81. methods: {
  82. // 点击标识
  83. onClickEm() {
  84. DialogService.confirm({
  85. title: '温馨提示',
  86. message: '请再保存一次号码,进行白名单同步。'
  87. });
  88. },
  89. // 返回
  90. onNavBack() {
  91. this.$router.push({ name: 'Myself' });
  92. },
  93. onAddNumber() {
  94. // TODO iot平台
  95. if (this.listData.length >= this.numberMax) {
  96. DialogService.confirm({
  97. title: `亲情号码最多只能设置${this.numberMax}个`
  98. });
  99. } else {
  100. this.$router.push({
  101. name: 'addFamilyNumber',
  102. query: { serialNo: this.$store.getters.serialNo }
  103. });
  104. }
  105. },
  106. conClick(item) {
  107. if (item.AppType !== FamilyNumberModel.appType.manufactor) {
  108. this.$router.push({
  109. name: 'changeFamilyNumber',
  110. query: {
  111. id: item.Id,
  112. serialNo: this.$store.getters.serialNo,
  113. relationship: item.relationship,
  114. sos: item.SOS,
  115. shortKey: item.PressKey
  116. }
  117. });
  118. } else {
  119. this.tipsOnEditable();
  120. }
  121. },
  122. tipsOnEditable() {
  123. DialogService.confirm({
  124. title: '抱歉,该记录不可操作',
  125. message: '该记录为教师端所设,家长端不可以操作',
  126. className: 'device_confirm'
  127. });
  128. },
  129. getCommandList() {
  130. ToastService.loading({ message: '数据加载中...' });
  131. APICommand.commandList({
  132. deviceId: this.$store.getters.deviceId
  133. })
  134. .then(res => {
  135. let item = res.data;
  136. let listData = [];
  137. if (item.items.length > 0) {
  138. let cmdData = item.items.filter(val => val.cmdCode == DeviceCommandModel.familyNum);
  139. if (cmdData.length) {
  140. let parseValue = JSON.parse(cmdData[0].cmdValue);
  141. parseValue.WhiteList.forEach(val => {
  142. listData.push(val);
  143. });
  144. }
  145. console.log('随手精灵亲情号码列表::', listData);
  146. // 判断是否是小台风物联网卡
  147. // 1. 是,查询小台风第三方亲情号卡列表,合并相同亲情号码的列表
  148. if (this.isUnicom) {
  149. let that = this;
  150. console.log('小台风白名单列表::', that.uniWhiteList);
  151. if (that.uniWhiteList.length > 0) {
  152. // 如果小台风白名单列表有数据,就开始拿一一对应亲情号码的状态赋予到随手精灵亲亲号码的列表
  153. listData.map(item => {
  154. // 先判断小台风白名单列表是否有一一对应的亲亲号码,有那就拿相应的状态,无则同步状态默认给2,即同步中
  155. item.status = that.uniWhiteList.find(u => u.phone === item.phone)
  156. ? that.uniWhiteList.find(u => u.phone === item.phone).status
  157. : 2;
  158. });
  159. that.listData = listData;
  160. } else {
  161. that.listData = listData;
  162. }
  163. } else {
  164. // 2. 否,照旧
  165. this.listData = listData;
  166. }
  167. ToastService.success({
  168. message: '加载完成'
  169. });
  170. this.isPageShow = true;
  171. }
  172. })
  173. .catch(err => {
  174. console.log(err);
  175. this.isPageShow = true;
  176. })
  177. .finally(() => ToastService.clear());
  178. },
  179. // 如果是小台风物联网卡,获取第三方物联网卡同步的亲情号码列表
  180. getIotCardWiteList() {
  181. APICommand.GetIotCardWiteList(this.$store.getters.serialNo).then(res => {
  182. this.uniWhiteList = res.data.data.items || [];
  183. });
  184. },
  185. onDelete(item) {
  186. if (item.AppType !== FamilyNumberModel.appType.manufactor) {
  187. const req = this.listData.filter(val => val.Id !== item.Id);
  188. let cmdCode = DeviceCommandModel.familyNum;
  189. let cmdValue = {
  190. WhiteList: req
  191. };
  192. this.sendCommand(cmdCode, JSON.stringify(cmdValue));
  193. ToastService.success({
  194. message: '操作成功'
  195. });
  196. } else {
  197. this.tipsOnEditable();
  198. }
  199. },
  200. sendCommand(cmdCode, cmdValue) {
  201. ToastService.loading({ message: '删除中,请稍后...' });
  202. /* let url = `/api/Command/SendCommand`;
  203. let jsonData = {
  204. deviceId: this.$store.getters.deviceId,
  205. userId: this.$store.getters.userId,
  206. serialNo: this.$store.getters.serialNo,
  207. cmdCode,
  208. cmdValue
  209. }; */
  210. /* this.$axios
  211. .post(url, jsonData) */
  212. APICommand.SetIotWhiteList({
  213. deviceId: this.$store.getters.deviceId,
  214. userId: this.$store.getters.userId,
  215. serialNo: this.$store.getters.serialNo,
  216. cmdCode,
  217. cmdValue
  218. })
  219. .then(res => {
  220. let item = res.data;
  221. if (item.stateCode == 1) {
  222. ToastService.success({
  223. message: '操作成功'
  224. });
  225. } else {
  226. DialogService.confirm({
  227. title: '操作失败,请重新设置'
  228. });
  229. }
  230. this.getCommandList();
  231. })
  232. .catch(() => {
  233. ToastService.clear();
  234. });
  235. },
  236. setFamilyNum() {
  237. let _this = this;
  238. if (_this.listData == null || this.listData.length == 0) {
  239. this.$store.commit('familyNameList', '');
  240. } else {
  241. _this.listData
  242. .filter(val => {
  243. return val.PressKey !== '5';
  244. })
  245. .forEach(f => {
  246. _this.familyNameList.push(f.relationship);
  247. this.$store.commit('familyNameList', _this.familyNameList);
  248. });
  249. }
  250. },
  251. // 缓存亲情号码快捷键
  252. setFamilyShortKey() {
  253. let _this = this;
  254. if (_this.listData == null || this.listData.length == 0) {
  255. this.$store.commit('familyShortKeyList', '');
  256. } else {
  257. _this.listData
  258. .filter(val => {
  259. return val.PressKey != '';
  260. })
  261. .forEach(f => {
  262. _this.familyShortKeyList.push(f.PressKey);
  263. this.$store.commit('familyShortKeyList', _this.familyShortKeyList);
  264. });
  265. }
  266. }
  267. },
  268. created() {
  269. let that = this;
  270. this.getIotCardWiteList();
  271. setTimeout(() => {
  272. that.getCommandList();
  273. }, 300);
  274. }
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. .familyNumber {
  279. position: relative;
  280. height: 100vh;
  281. overflow: hidden;
  282. font-size: 32px;
  283. .management {
  284. position: relative;
  285. height: calc(100vh - 160px);
  286. overflow: scroll;
  287. .newsNotData {
  288. height: 400px;
  289. @include flexbox(center, center, column, nowrap);
  290. font-size: 32px;
  291. }
  292. .conArea {
  293. .con {
  294. height: 100px;
  295. @include flexbox(center, flex-start, column, nowrap);
  296. }
  297. }
  298. .tips-container {
  299. padding: 20px;
  300. .inside-tips {
  301. padding: 40px;
  302. border-radius: 30px;
  303. border: 1px solid green;
  304. }
  305. }
  306. }
  307. }
  308. </style>
  309. >