StaffAdd.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <div class="seek">
  3. <div class="com-mobile-header mobile-center-header">
  4. <a @click="goLastPage"><i class="iconfont icon-fanhui"></i></a>
  5. <p>新增账户</p>
  6. <p class="en-name"><img :src="`/images/mobile/center/${user.data.enterprise.uu ? 'en' : 'self'}.png`" alt="">{{currentEnName}}</p>
  7. </div>
  8. <div class="mobile-fix-content mobile-centerfix-content" id="mobile-staff-center">
  9. <div class="staff-head">
  10. <span class="inline-block" :class="{'active': switchType === 'addNoRegister'}" @click="setSwitchType('addNoRegister')">添加未注册用户</span>
  11. <span class="inline-block" :class="{'active': switchType === 'addRegister'}" @click="setSwitchType('addRegister')">添加已注册用户</span>
  12. </div>
  13. <div class="staff-record" v-if="switchType == 'addNoRegister'" >
  14. <div class="list-content">
  15. <ul class="staff-adds">
  16. <li><span>姓名:</span><input type="text" v-model="newUserName" maxlength="10" placeholder="请输入用户名"></li>
  17. <li style="overflow: visible;"><span>性别:</span>
  18. <div class="sex-filter">
  19. <div class="select-wrap" @click.stop="openChoose">{{sex === 'M' ? '男' : '女'}}<i class="iconfont icon-arrow-down"></i></div>
  20. <ul class="select-list" v-if="showChooseSex">
  21. <li v-show="sex != 'M'" @click="chooseSex('M')">男</li>
  22. <li v-show="sex != 'F'" @click="chooseSex('F')">女</li>
  23. </ul>
  24. </div>
  25. </li>
  26. <li><span>手机号:</span><input type="text"
  27. v-model="newUserPhone"
  28. @change="checkPhone()"
  29. @input="checkPhone()"
  30. maxlength="11"
  31. placeholder="请输入手机号"></li>
  32. <li><span>邮箱:</span><input type="text"
  33. v-model="newUserEmail"
  34. @change="checkEmail()"
  35. @input="checkEmail()"
  36. placeholder="请输入邮箱"></li>
  37. </ul>
  38. <div class="staff-footer">
  39. <div class="cancel handle" @click="cancelBind">取消</div>
  40. <div class="agree handle" @click="addNewUser">确定</div>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="staff-record" v-if="switchType == 'addRegister'">
  45. <div class="search-content">
  46. <input type="text"
  47. v-model="searchKeyword"
  48. @click="addApply"
  49. placeholder="请输入UU号、手机号或邮箱">
  50. <span @click="addApply"><i class="iconfont icon-sousuo"></i></span>
  51. </div>
  52. <div class="list-content" v-if="showSearchUser">
  53. <div v-if="bindUser">
  54. <div class="staff-list">
  55. <div class="list-item"><span>UU账号:</span><span v-text="newUserInfo.userUU">100000721</span></div>
  56. <div class="list-item"><span>姓名:</span><span v-text="newUserInfo.userName">张洪别</span></div>
  57. <div class="list-item"><span>性别:</span><span v-text="newUserInfo.userSex === 'F' ? '女' : newUserInfo.userSex === 'M' ? '男' : '-'">男</span></div>
  58. <div class="list-item"><span>手机:</span><span v-text="newUserInfo.userTel">12345678901</span></div>
  59. <div class="list-item"><span>邮箱:</span><span v-text="newUserInfo.userEmail">12345678901</span></div>
  60. </div>
  61. <div class="staff-footer">
  62. <div class="cancel handle" @click="cancelBind">取消</div>
  63. <div class="agree handle" @click="sureBindNewUser()">确定绑定</div>
  64. </div>
  65. </div>
  66. <div class="staff-list" v-if="reBindError">
  67. <span>该用户已绑定到当前企业,不可重复绑定!</span>
  68. </div>
  69. <div class="staff-list" v-if="illegalError">
  70. <span>不可对自己进行绑定!</span>
  71. </div>
  72. </div>
  73. <div class="list-content" v-else>
  74. <div class="staff-list">
  75. <span>您查找的用户不存在!</span>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <remind-box :title="remindText" :timeoutCount="timeoutCount"></remind-box>
  81. </div>
  82. </template>
  83. <script>
  84. import { RemindBox } from '~components/mobile/common'
  85. export default {
  86. data () {
  87. return {
  88. switchType: 'addNoRegister',
  89. newUserName: '',
  90. newUserPhone: '',
  91. newUserEmail: '',
  92. showChooseSex: false,
  93. sex: 'M',
  94. remindText: '',
  95. timeoutCount: 0,
  96. newPhoneCheck: false,
  97. newEmailCheck: false,
  98. showSearchUser: true,
  99. searchKeyword: '',
  100. newUserInfo: '',
  101. reBindError: false,
  102. illegalError: false,
  103. bindUser: false
  104. }
  105. },
  106. components: {
  107. RemindBox
  108. },
  109. computed: {
  110. userInfo () {
  111. return this.$store.state.option.user.data
  112. }
  113. },
  114. mounted () {
  115. this.$nextTick(() => {
  116. window.addEventListener('click', () => {
  117. this.showChooseSex = false
  118. }, false)
  119. })
  120. },
  121. methods: {
  122. setSwitchType (type) {
  123. this.switchType = type
  124. },
  125. openChoose () {
  126. this.showChooseSex = !this.showChooseSex
  127. },
  128. chooseSex (info) {
  129. this.sex = info
  130. this.showChooseSex = false
  131. },
  132. onRemind: function (str) {
  133. this.remindText = str
  134. this.timeoutCount ++
  135. },
  136. // 验证手机
  137. checkPhone () {
  138. if (!this.newUserPhone || this.newUserPhone === '') {
  139. this.newPhoneCheck = false
  140. this.onRemind('请输入手机号码')
  141. } else {
  142. if ((/^1\d{10}$/).test(this.newUserPhone)) {
  143. this.$http.get('/basic/user/telEnable', {params: {tel: this.newUserPhone}})
  144. .then(response => {
  145. if (response.data) {
  146. this.newPhoneCheck = true
  147. } else {
  148. this.newPhoneCheck = false
  149. this.onRemind('手机号码' + this.newUserPhone + '已被注册')
  150. }
  151. })
  152. } else {
  153. this.newPhoneCheck = false
  154. this.onRemind('请输入正确的手机号码')
  155. }
  156. }
  157. },
  158. // 验证邮箱
  159. checkEmail () {
  160. if (!this.newUserEmail || this.newUserEmail === '') {
  161. this.onRemind('请输入邮箱')
  162. this.newEmailCheck = false
  163. } else {
  164. if ((/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(this.newUserEmail)) {
  165. this.$http.get('/basic/user/emailEnable', {params: {email: this.newUserEmail}})
  166. .then(response => {
  167. if (response.data) {
  168. this.newEmailCheck = true
  169. } else {
  170. this.newEmailCheck = false
  171. this.onRemind('邮箱' + this.newUserEmail + '已被注册')
  172. }
  173. })
  174. } else {
  175. this.newEmailCheck = false
  176. this.onRemind('请输入正确的邮箱')
  177. }
  178. }
  179. },
  180. // 绑定未注册用户
  181. addNewUser () {
  182. if (!this.newUserName ||this.newUserName === '') {
  183. this.onRemind('请输入用户名')
  184. } else if (!this.newUserPhone || this.newUserPhone === '') {
  185. this.onRemind('请输入手机号码')
  186. this.newPhoneCheck = false
  187. } else if (!this.newUserEmail || this.newUserEmail === '') {
  188. this.onRemind('请输入邮箱')
  189. this.newEmailCheck = false
  190. } else {
  191. if (this.newEmailCheck && this.newPhoneCheck) {
  192. this.$http.post('/basic/user', {userEmail: this.newUserEmail, userName: this.newUserName, userSex: this.sex, userTel: this.newUserPhone})
  193. .then(response => {
  194. if (response) {
  195. this.onRemind('增加用户成功' + this.newUserName)
  196. this.$router.push('/mobile/user/staff')
  197. }
  198. })
  199. } else {
  200. this.checkPhone()
  201. this.checkEmail()
  202. }
  203. }
  204. },
  205. // 取消绑定
  206. cancelBind () {
  207. this.$router.push('/mobile/user/staff')
  208. },
  209. // 搜索已注册用户
  210. addApply () {
  211. if (this.searchKeyword) {
  212. this.$http.get('/basic/user/searchUser', {params: {keyWord: this.searchKeyword}}).then(response => {
  213. if (response.data) {
  214. this.showSearchUser = true
  215. this.newUserInfo = response.data
  216. this.bindUser = true
  217. this.illegalError = false
  218. this.reBindError = false
  219. if (this.newUserInfo.userUU === this.userInfo.userUU) {
  220. //不可自己绑定自己
  221. this.illegalError = true
  222. this.bindUser = false
  223. } else {
  224. for (var i = 0; i < this.newUserInfo.enterprises.length; i++) {
  225. if (this.newUserInfo.enterprises[i].current) {
  226. for (var j = 0; j < this.userInfo.enterprises.length; j++) {
  227. //该用户已绑定到当前企业,不可重复绑定
  228. if (this.newUserInfo.enterprises[i].uu === this.userInfo.enterprises[j].uu) {
  229. this.reBindError = true
  230. this.bindUser = false
  231. }
  232. }
  233. }
  234. }
  235. }
  236. } else {
  237. // 未搜索到结果
  238. this.showSearchUser = false
  239. this.bindUser = false
  240. this.reBindError = false
  241. this.illegalError = false
  242. }
  243. }).catch (err =>{
  244. if (err) {
  245. this.showSearchUser = false
  246. this.bindUser = false
  247. this.reBindError = false
  248. this.illegalError = false
  249. }
  250. })
  251. }
  252. },
  253. // 确定绑定已注册用户
  254. sureBindNewUser () {
  255. let isFlag = false
  256. if (this.newUserInfo.enterprises.length) {
  257. this.newUserInfo.enterprises.forEach(item => {
  258. if (item.uu === this.user.data.enterprise.uu) {
  259. isFlag = true
  260. }
  261. })
  262. }
  263. if (isFlag) {
  264. this.onRemind('该用户已绑定到当前企业,不可重复绑定!')
  265. } else {
  266. this.$http.get('/basic/user/bindUser', {params: {userUU: this.newUserInfo.userUU}})
  267. .then(response => {
  268. if (response) {
  269. this.onRemind('增加用户成功' + this.newUserInfo.userName)
  270. this.$router.push('/mobile/user/staff')
  271. }
  272. })
  273. }
  274. }
  275. }
  276. }
  277. </script>
  278. <style lang="scss" scoped>
  279. $base-color: #3f84f6;
  280. #mobile-staff-center {
  281. .staff-head {
  282. height: .82rem;
  283. line-height: .82rem;
  284. text-align: center;
  285. background: #fff;
  286. span {
  287. font-size: .29rem;
  288. &:last-child {
  289. margin-left: 2.6rem;
  290. }
  291. &.active {
  292. color: $base-color;
  293. border-bottom: 1px solid $base-color;
  294. }
  295. }
  296. }
  297. .staff-record {
  298. .search-content {
  299. overflow: hidden;
  300. padding: .25rem 0;
  301. text-align: center;
  302. input {
  303. width: 6.9rem;
  304. border: 1px solid #376ff3;
  305. }
  306. }
  307. .list-content{
  308. margin: 0 auto;
  309. padding: 0 .20rem;
  310. .staff-adds {
  311. margin: 0.25rem auto 0;
  312. padding: 0 .24rem;
  313. width: 6.64rem;
  314. background-color: #ffffff;
  315. border-radius: .05rem;
  316. li{
  317. overflow: hidden;
  318. height: 1.18rem;
  319. line-height: 1.18rem;
  320. border-bottom: 1px solid #d9d9d9;
  321. list-style: none;
  322. span {
  323. display: inline-block;
  324. float: left;
  325. width: 1rem;
  326. font-size: .28rem;
  327. color: #3f84f6;
  328. }
  329. input{
  330. float: left;
  331. width: 4.85rem;
  332. border: none;
  333. outline: none;
  334. }
  335. div.sex-filter {
  336. float: left;
  337. position: relative;
  338. margin-top: .3rem;
  339. width: .73rem;
  340. height: .58rem;
  341. line-height: .58rem;
  342. border-radius: .05rem;
  343. border: solid 1px #b4b4b4;
  344. .select-wrap {
  345. width: .73rem;
  346. height: .58rem;
  347. text-align: center;
  348. i{
  349. font-size: .1rem;
  350. font-weight: bold;
  351. color: $base-color;
  352. }
  353. }
  354. ul.select-list{
  355. width: .73rem;
  356. position: absolute;
  357. left: -0.02rem;
  358. top: .59rem;
  359. border: solid 1px #b4b4b4;
  360. border-top: none;
  361. -webkit-box-shadow: 0 1px 5px 0 #aaa;
  362. box-shadow: 0 1px 5px 0 #aaa;
  363. border-radius: .04rem;
  364. li{
  365. background: #fff;
  366. text-align: center;
  367. padding: 0 .13rem;
  368. font-size: .28rem;
  369. height: .53rem;
  370. line-height: .53rem;
  371. }
  372. }
  373. }
  374. &:last-child {
  375. border-bottom: none;
  376. }
  377. }
  378. }
  379. .staff-footer{
  380. overflow: hidden;
  381. margin-top: .6rem;
  382. div.handle{
  383. float: left;
  384. width: 3.24rem;
  385. height: .77rem;
  386. line-height: .77rem;
  387. font-size: .32rem;
  388. color: #fff;
  389. text-align: center;
  390. border-radius: .08rem;
  391. &:first-child{
  392. margin: 0 .28rem 0 .2rem;
  393. background-color: #acaaab;
  394. }
  395. &:last-child{
  396. background-color: #3f84f6 ;
  397. }
  398. }
  399. }
  400. .staff-list {
  401. margin: 0 auto;
  402. padding: .35rem .24rem .15rem;
  403. width: 6.64rem;
  404. background-color: #ffffff;
  405. border-radius: .05rem;
  406. .list-item {
  407. overflow: hidden;
  408. margin-bottom: .1rem;
  409. span{
  410. float: left;
  411. font-size: .28rem;
  412. color: #3f84f6;
  413. &:first-child{
  414. width: 1.3rem;
  415. }
  416. &:last-child{
  417. width: 4.8rem;
  418. color: #666;
  419. }
  420. }
  421. }
  422. }
  423. }
  424. }
  425. }
  426. </style>