addManagemenCard.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template >
  2. <div class="addAccess">
  3. <el-form ref="form" :model="formData" :rules="formRules" label-width="110px">
  4. <el-form-item label="所属社区" prop="communityId">
  5. <el-select v-model="formData.communityId" placeholder="请选择社区" clearable>
  6. <el-option v-for="(item, index) in communityArr" :key="index" :label="item.communityName" :value="item.id"></el-option>
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="员工" prop="userId">
  10. <el-cascader
  11. ref="userName"
  12. placeholder="请选择员工"
  13. v-model="formData.userId"
  14. :props="defaultProps"
  15. :options="findUser"
  16. @change="findUserToggle"
  17. ></el-cascader>
  18. </el-form-item>
  19. <el-form-item label="发卡" prop="cardNo">
  20. <div class="disCarInput">
  21. <div class="disCardButton is-active" @click="getReadCard()">读取卡</div>
  22. <div class="disCardButton" @click="formatCard()">格式化卡</div>
  23. </div>
  24. <div class="disCarInput">卡号:{{ formData.cardNo }}</div>
  25. </el-form-item>
  26. <el-form-item label="到期时间" prop="expirationTime">
  27. <el-date-picker
  28. v-model="formData.expirationTime"
  29. value-format="yyyyMMdd"
  30. type="date"
  31. placeholder="选择日期"
  32. class="width100"
  33. >
  34. </el-date-picker>
  35. </el-form-item>
  36. </el-form>
  37. </div>
  38. </template>
  39. <script >
  40. import axios from 'axios';
  41. export default {
  42. props: ['params'],
  43. data() {
  44. return {
  45. defaultProps: {
  46. value: 'id', // 唯一标识
  47. label: 'label', // 标签显示
  48. children: 'children',
  49. emitPath: false
  50. },
  51. formData: {
  52. communityId: '',
  53. expirationTime: '',
  54. cardNo: '',
  55. cardType: 2,
  56. userId: '',
  57. username: ''
  58. },
  59. formRules: {
  60. communityId: [this.$valid.selectRequired('所属社区')],
  61. userId: [this.$valid.selectRequired('员工')],
  62. expirationTime: [this.$valid.selectRequired('到期时间')],
  63. cardNo: [
  64. {
  65. required: true,
  66. message: `卡号不能为空`,
  67. trigger: 'change',
  68. validator(rule, value, cb) {
  69. if (!value) {
  70. cb(new Error());
  71. } else {
  72. cb();
  73. }
  74. }
  75. }
  76. ]
  77. },
  78. communityArr: [],
  79. findUser: []
  80. };
  81. },
  82. methods: {
  83. getorgTree() {
  84. this.$http
  85. .get('/sc-community/assets/community/list')
  86. .then((data) => {
  87. this.communityArr = data.data;
  88. })
  89. .catch(function () {});
  90. },
  91. getUserList() {
  92. this.$http.get('/sc-user-center/user/findUserList').then(({ data, status, msg }) => {
  93. this.findUser = data;
  94. });
  95. },
  96. findUserToggle() {
  97. this.formData.username = this.$refs.userName.getCheckedNodes()[0].label;
  98. },
  99. submit() {
  100. this.$refs.form.validate((valid) => {
  101. if (valid) {
  102. let installData = JSON.parse(JSON.stringify(this.formData));
  103. this.gateIds.map((item, index) => {
  104. installData.gateIds.push({ deviceId: item });
  105. });
  106. this.writeCard(installData);
  107. }
  108. });
  109. },
  110. //验证绑定
  111. queryBinding(cardNo) {
  112. this.$http.get('/sc-gate-web/gateCard/queryBinding', { cardNo: cardNo }).then(({ data, status, msg }) => {
  113. if (status == 0) {
  114. if (data == 0) {
  115. this.formData.cardNo = cardNo;
  116. } else {
  117. this.$message.warning('此卡已绑定,请更换卡或格式化卡');
  118. }
  119. }
  120. });
  121. },
  122. //读卡
  123. getReadCard() {
  124. new Promise((resolve) => {
  125. this.$http.get('/card/load').then(({ data, status, msg }) => {
  126. if (status == 0) {
  127. if (!!data) {
  128. // this.$message.success(msg);
  129. resolve && resolve(data);
  130. } else {
  131. this.$message.warning('没有读取到卡号');
  132. }
  133. } else {
  134. this.$message.error('读取失败');
  135. }
  136. });
  137. }).then((res) => {
  138. this.queryBinding(res);
  139. });
  140. },
  141. //格式化
  142. formatCard() {
  143. this.$http.get('/card/format').then(({ data, status, msg }) => {
  144. if (status == 0) {
  145. this.$message.success(data);
  146. }
  147. });
  148. },
  149. writeCard(installData) {
  150. let ids = () => {
  151. let newAr = [],
  152. devNo = [];
  153. installData.gateIds.map((item) => {
  154. newAr.push(item.deviceId);
  155. });
  156. let newObj = this.gateList.filter((item, index) => {
  157. return newAr.includes(item.id);
  158. });
  159. newObj.map((item) => {
  160. devNo.push(item.deviceNo);
  161. });
  162. return devNo;
  163. };
  164. let inFrom = {
  165. depId: installData.communityId,
  166. expire_date: installData.expirationTime,
  167. guids: ids().join(',')
  168. };
  169. new Promise((resolve) => {
  170. this.$http.post('/card/issue/manage', [inFrom]).then(({ data, status, msg }) => {
  171. if (status == 0) {
  172. this.$message.success(msg);
  173. resolve && resolve();
  174. } else {
  175. this.$message.error(msg);
  176. }
  177. });
  178. }).then((res) => {
  179. this.isOk(installData);
  180. });
  181. },
  182. isOk(installData) {
  183. var loading = this.$loading();
  184. this.$http
  185. .post('/sc-gate-web/gateCard/add', installData)
  186. .then(({ status, msg }) => {
  187. if (status == 0) {
  188. this.$message.success(msg);
  189. this.params.callback();
  190. this.$emit('close');
  191. } else {
  192. this.$message.error(msg);
  193. }
  194. loading.close();
  195. })
  196. .catch(() => {
  197. loading.close();
  198. });
  199. }
  200. },
  201. created() {
  202. this.getorgTree();
  203. this.getUserList();
  204. }
  205. };
  206. </script>
  207. <style lang="scss" scoped>
  208. @import '@assets/css/public-style.scss';
  209. .formContent-item_title {
  210. line-height: rem(20);
  211. }
  212. .form-item-flex {
  213. display: flex;
  214. .form-item-flex-input {
  215. width: rem(165) !important;
  216. margin-left: rem(20);
  217. margin-bottom: 0 !important;
  218. &:first-child {
  219. margin: 0;
  220. }
  221. }
  222. }
  223. .disCarInput {
  224. display: inline-block;
  225. font-size: 12px;
  226. line-height: rem(30);
  227. margin-left: rem(20);
  228. &:first-child {
  229. margin: 0;
  230. }
  231. }
  232. .el-checkbox {
  233. margin-bottom: rem(20);
  234. }
  235. .disCardButton {
  236. padding: 0 rem(15);
  237. text-align: center;
  238. font-size: rem(14);
  239. height: rem(30);
  240. box-sizing: border-box;
  241. border-radius: rem(2);
  242. border: 1px solid #e0e1e3;
  243. color: #535766;
  244. display: inline-block;
  245. cursor: pointer;
  246. &.is-active {
  247. color: #0eaeff;
  248. border-color: #0eaeff;
  249. }
  250. &:active {
  251. color: #0eaeff6b;
  252. border-color: #0eaeff6b;
  253. }
  254. &:not(:last-child) {
  255. margin-right: rem(20);
  256. }
  257. }
  258. .buttonSelect {
  259. padding: 0 rem(15);
  260. text-align: center;
  261. font-size: rem(14);
  262. height: rem(30);
  263. box-sizing: border-box;
  264. border-radius: rem(2);
  265. border: 1px solid #e0e1e3;
  266. color: #535766;
  267. display: inline-block;
  268. cursor: pointer;
  269. &.is-active,
  270. &.is-checked {
  271. color: #0eaeff;
  272. border-color: #0eaeff;
  273. }
  274. &:not(:last-child) {
  275. margin-right: rem(20);
  276. }
  277. }
  278. /deep/ .el-radio-button .el-radio-button__inner,
  279. /deep/ .el-checkbox-button .el-checkbox-button__inner {
  280. border: none;
  281. box-sizing: border-box;
  282. padding: 0;
  283. line-height: rem(24);
  284. margin-top: rem(2);
  285. display: block;
  286. }
  287. /deep/ .el-radio-button__orig-radio:checked + .el-radio-button__inner,
  288. /deep/ .el-checkbox-button.is-checked .el-checkbox-button__inner {
  289. color: #0eaeff;
  290. background-color: white;
  291. box-shadow: none;
  292. }
  293. </style>