addManagemenCard.vue 9.2 KB

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