GreenCode.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <div>
  3. <!--补全身份证-->
  4. <div class="fyy-popup-1" v-show="editIdcardVisible">
  5. <div class="fyy-popup-bg"></div>
  6. <div class="fyy-popup-ceter">
  7. <div class="fyy-popup-inner">
  8. <h4>请补全身份信息</h4>
  9. <form class="mui-input-group">
  10. <div class="mui-input-row">
  11. <label>姓名</label>
  12. <input type="text" v-model="name" placeholder="请输入姓名">
  13. </div>
  14. <div class="mui-input-row">
  15. <label>身份证号</label>
  16. <input type="text" v-model="idCard" placeholder="请输入身份证号" style="text-transform: uppercase;">
  17. </div>
  18. </form>
  19. <a herf=""><span class="mui-icon mui-icon-help"></span>用于获取健康码及实名认证服务</a>
  20. </div>
  21. <div class="fyy-popup-button">
  22. <div class="mui-col-xs-6">
  23. <button type="button" class="mui-btn" @click="editIdcardVisible=false">取消</button>
  24. </div>
  25. <div class="mui-col-xs-6">
  26. <button type="button" class="mui-btn mui-btn-primary" @click="updateIdCard">确认</button>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <!--二维码展示-->
  32. <div class="fyy-popup-1" style="z-index: 999" v-show="qrcodeVisible">
  33. <div class="fyy-popup-bg" @click="qrcodeVisible=false"></div>
  34. <div class="fyy-popup-ceter fyy-popup-f">
  35. <div class="fyy-popup-inner">
  36. <div class="fyy-popup-title">
  37. <div class="mui-col-xs-4">
  38. <label>姓名</label>
  39. <h5 v-text="showMsg(name,'name')"></h5>
  40. </div>
  41. <div class="mui-col-xs-8">
  42. <label>身份证<span :class="(hideMsg?'icon-yanjing_bi ':'icon-hj ')+'mui-icon iconfont mui-pull-right'" @click="hideMsg=!hideMsg"></span></label>
  43. <h5 v-text="showMsg(idCard,'idCard')"></h5>
  44. </div>
  45. </div>
  46. <div class="fyy-popup-ma">
  47. <img :src="qrCodeImg" id="qrcode">
  48. <h6>更新于 {{qrcodeDetail.date}}</h6>
  49. </div>
  50. <form class="mui-input-group fyy-popup-data">
  51. <div class="mui-input-row">
  52. <label>数据来源</label>
  53. <span v-text="qrcodeDetail.sjly"></span>
  54. </div>
  55. <div class="mui-input-row" v-show="qrcodeDetail.healthyCode!='00'">
  56. <label>原因</label>
  57. <span v-text="qrcodeDetail.reason"></span>
  58. </div>
  59. </form>
  60. </div>
  61. </div>
  62. </div>
  63. <!-- <loading :visible="isLoading"></loading> -->
  64. </div>
  65. </template>
  66. <script>
  67. import * as API_Master from '@/apis/Master/index'
  68. import * as API_Health from '@/apis/Common/health'
  69. import Loading from '@/components/Loading.vue'
  70. import QRCode from 'qrcodejs2'
  71. import {
  72. convertCanvasToImage,
  73. checkIdCard,
  74. substrMb
  75. } from '@/utils'
  76. import {
  77. mapGetters,
  78. mapMutations
  79. } from 'vuex'
  80. export default {
  81. name: 'GreenCode',
  82. components: {
  83. Loading,
  84. },
  85. props: {
  86. personId: {
  87. require: true,
  88. default: '',
  89. },
  90. },
  91. data() {
  92. return {
  93. isLoading: false,
  94. name: "",
  95. idCard: undefined,
  96. statusName: '正常',
  97. statusTitleColor: '#33BB00',
  98. editIdcardVisible: false,
  99. qrcodeVisible: false,
  100. qrcodeDetail: {
  101. healthyCode: '11',
  102. date: '',
  103. reason: '',
  104. sjly: '',
  105. },
  106. qrcodeColor: {
  107. '00': {
  108. background: '#FFFFFF',
  109. foreground: '#33BB00',
  110. title: '正常',
  111. name: '绿码',
  112. },
  113. '01': {
  114. background: '#FFFFFF',
  115. foreground: '#FFBB00',
  116. title: '异常',
  117. name: '黄码',
  118. },
  119. '10': {
  120. background: '#FFFFFF',
  121. foreground: '#FF6666',
  122. title: '异常',
  123. name: '红码',
  124. },
  125. '11': {
  126. background: '#FFFFFF',
  127. foreground: '#CCCCCC',
  128. title: '异常',
  129. name: '灰码',
  130. },
  131. },
  132. qrCodeImg: '',
  133. hideMsg: true,
  134. }
  135. },
  136. created() {
  137. },
  138. methods: {
  139. //获取当前健康码的其作定义对象
  140. getCode() {
  141. return this.qrcodeColor[this.qrcodeDetail.healthyCode];
  142. },
  143. getGreenCodeByName(name,idCard) {
  144. this.idCard = undefined;
  145. //传过来的身份证号码才会处理
  146. this.isLoading = true;
  147. API_Health.getGreenCodeByName(name,idCard).then(response => {
  148. this.isLoading = false;
  149. this.idCard = idCard;
  150. this.name = name;
  151. if (response.hasIdCard) {
  152. this.qrcodeDetail = response;
  153. //生成二维码
  154. this.$nextTick(() => {
  155. this.qrcode();
  156. });
  157. //修改系统色
  158. this.$emit('callBack', this.qrcodeColor[this.qrcodeDetail.healthyCode]);
  159. }
  160. }).catch(error => {
  161. this.isLoading = false;
  162. //mui.toast(error);
  163. })
  164. },
  165. //获取绿码信息
  166. getGreenCode() {
  167. if (this.qrcodeDetail.date) {
  168. return;
  169. }
  170. //传过来的身份证号码才会处理
  171. this.isLoading = true;
  172. API_Health.getGreenCode(this.personId).then(response => {
  173. this.isLoading = false;
  174. this.idCard = response.idCard;
  175. this.name = response.name;
  176. if (response.hasIdCard) {
  177. this.qrcodeDetail = response;
  178. //生成二维码
  179. this.$nextTick(() => {
  180. this.qrcode();
  181. });
  182. //修改系统色
  183. this.$emit('callBack', this.qrcodeColor[this.qrcodeDetail.healthyCode]);
  184. }
  185. }).catch(error => {
  186. this.isLoading = false;
  187. //mui.toast(error);
  188. })
  189. },
  190. //显示绿码
  191. showGreenCode() {
  192. if (this.qrcodeDetail.date) {
  193. this.qrcodeVisible = true;
  194. } else {
  195. if (this.idCard === undefined) {
  196. mui.alert(
  197. '<div style="text-align:left;">可能由以下原因导致:<br/>1.该用户的身份证号尚未申请湖北健康码;<br/>2.该用户的姓名和身份证号与申请湖北健康码时填写的信息不一致;<br/>3.新申请的湖北健康码,系统数据同步有延时,请等待两天后再次尝试。</div>',
  198. '健康码获取失败',
  199. function() {
  200. }
  201. );
  202. } else {
  203. if (this.person_data.id == this.personId) {
  204. this.editIdcardVisible = true;
  205. }
  206. }
  207. }
  208. },
  209. //生成二维码
  210. qrcode() {
  211. console.log(this.qrcodeColor[this.qrcodeDetail.healthyCode]['foreground']);
  212. let qrcode = new QRCode('qrcode', {
  213. width: 200,
  214. height: 200,
  215. text: window.location.href.split("#")[0] + '/business/#/common/health/cert?personId=' + this.personId,
  216. correctLevel: QRCode.CorrectLevel.M,
  217. // render: 'canvas' // 设置渲染方式(有两种方式 table和canvas,默认是canvas)
  218. colorLight: this.qrcodeColor[this.qrcodeDetail.healthyCode]['background'],
  219. colorDark: this.qrcodeColor[this.qrcodeDetail.healthyCode]['foreground']
  220. })
  221. var canvas = document.getElementsByTagName('canvas')[0];
  222. this.qrCodeImg = convertCanvasToImage(canvas);
  223. },
  224. //更新身份证号
  225. updateIdCard() {
  226. var _this = this
  227. var checkIdCardResult = checkIdCard(this.idCard);
  228. if (checkIdCardResult !== true) {
  229. mui.toast(checkIdCardResult);
  230. } else if (!this.name) {
  231. mui.toast('请输入姓名');
  232. } else {
  233. this.isLoading = true;
  234. API_Master.updateIdCard(this.idCard, this.name).then(response => {
  235. _this.isLoading = false;
  236. _this.editIdcardVisible = false;
  237. //获取绿码,并不会显示
  238. _this.getGreenCode();
  239. this.$emit('updateIdCardAsynCallBack', {
  240. idCard: this.idCard,
  241. name: this.name
  242. });
  243. }).catch(error => {
  244. this.isLoading = false;
  245. mui.toast(error);
  246. })
  247. }
  248. },
  249. //显示与隐藏信息
  250. showMsg(str, type) {
  251. if (str) {
  252. } else {
  253. return
  254. }
  255. if (this.hideMsg) {
  256. if (type == 'name') {
  257. return substrMb(str, 0, 2) + '**';
  258. } else if (type == 'idCard') {
  259. return substrMb(str, 0, 1) + '****************' + substrMb(str, str.length - 1, 1);
  260. } else {
  261. return str;
  262. }
  263. } else {
  264. return str;
  265. }
  266. },
  267. },
  268. computed: {
  269. ...mapGetters({
  270. person_data: 'person_data',
  271. person_popedom: 'person_popedom',
  272. })
  273. },
  274. watch: {}
  275. }
  276. </script>
  277. <style scoped src="@/assets/css/xpwyfyy.css"></style>
  278. <style scoped src="@/assets/css/sczpfyy.css"></style>
  279. <style src="@/assets/css/iconfont.css"></style>
  280. <style scoped>
  281. .fyy-popup-bg{
  282. position: fixed;
  283. z-index: 998;
  284. top: 0;
  285. right: 0;
  286. bottom: 0;
  287. left: 0;
  288. background-color: rgba(0, 0, 0, .3);
  289. }
  290. .fyy-popup-ceter{
  291. position: fixed;
  292. z-index: 999;
  293. top: 20%;
  294. left:0;
  295. right:0;
  296. margin: 30px;
  297. background: #ffffff;
  298. border-radius: 4px;
  299. }
  300. .fyy-popup-inner .mui-input-row{
  301. border-bottom:1px #eee solid
  302. }
  303. .fyy-popup-inner h4{
  304. font-size:18px;
  305. text-align: center;
  306. padding: 20px 15px;
  307. border-bottom: 1px #ddd solid;
  308. margin: 0;
  309. font-weight: bold;
  310. }
  311. .fyy-popup-inner a{
  312. padding:10px 15px;
  313. font-size:12px;
  314. color:#999;
  315. display: flex;
  316. }
  317. .fyy-popup-inner a .mui-icon{
  318. font-size:14px
  319. }
  320. .fyy-popup-button{
  321. display: flex;
  322. padding:10px
  323. }
  324. .fyy-popup-button .mui-col-xs-6{
  325. padding:0 5px
  326. }
  327. .fyy-popup-button button{
  328. width:100%
  329. }
  330. .fyy-popup-title{
  331. display: flex;
  332. padding:10px 15px
  333. }
  334. .fyy-popup-ma{
  335. margin:0 auto;
  336. padding:0 15px;
  337. text-align: center;
  338. }
  339. .fyy-popup-ma img{
  340. width:100%
  341. }
  342. .fyy-popup-data span{
  343. line-height: 50px;
  344. }
  345. .fyy-popup-f label{
  346. color:#666
  347. }
  348. .fyy-popup-f{
  349. top:15%
  350. }
  351. </style>