StaffAdd.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. console.log(this.$store.state.option.user.data)
  112. return this.$store.state.option.user.data
  113. }
  114. },
  115. mounted () {
  116. this.$nextTick(() => {
  117. window.addEventListener('click', () => {
  118. console.log(1)
  119. this.showChooseSex = false
  120. }, false)
  121. })
  122. },
  123. methods: {
  124. setSwitchType (type) {
  125. this.switchType = type
  126. },
  127. openChoose () {
  128. this.showChooseSex = !this.showChooseSex
  129. },
  130. chooseSex (info) {
  131. this.sex = info
  132. this.showChooseSex = false
  133. },
  134. onRemind: function (str) {
  135. this.remindText = str
  136. this.timeoutCount ++
  137. },
  138. // 验证手机
  139. checkPhone () {
  140. if (!this.newUserPhone || this.newUserPhone === '') {
  141. this.newPhoneCheck = false
  142. this.onRemind('请输入手机号码')
  143. } else {
  144. if ((/^1\d{10}$/).test(this.newUserPhone)) {
  145. this.$http.get('/basic/user/telEnable', {params: {tel: this.newUserPhone}})
  146. .then(response => {
  147. if (response.data) {
  148. this.newPhoneCheck = true
  149. } else {
  150. this.newPhoneCheck = false
  151. this.onRemind('手机号码' + this.newUserPhone + '已被注册')
  152. }
  153. })
  154. } else {
  155. this.newPhoneCheck = false
  156. this.onRemind('请输入正确的手机号码')
  157. }
  158. }
  159. },
  160. // 验证邮箱
  161. checkEmail () {
  162. if (!this.newUserEmail || this.newUserEmail === '') {
  163. this.onRemind('请输入邮箱')
  164. this.newEmailCheck = false
  165. } else {
  166. if ((/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(this.newUserEmail)) {
  167. this.$http.get('/basic/user/emailEnable', {params: {email: this.newUserEmail}})
  168. .then(response => {
  169. if (response.data) {
  170. this.newEmailCheck = true
  171. } else {
  172. this.newEmailCheck = false
  173. this.onRemind('邮箱' + this.newUserEmail + '已被注册')
  174. }
  175. })
  176. } else {
  177. this.newEmailCheck = false
  178. this.onRemind('请输入正确的邮箱')
  179. }
  180. }
  181. },
  182. // 绑定未注册用户
  183. addNewUser () {
  184. if (!this.newUserName ||this.newUserName === '') {
  185. this.onRemind('请输入用户名')
  186. } else if (!this.newUserPhone || this.newUserPhone === '') {
  187. this.onRemind('请输入手机号码')
  188. this.newPhoneCheck = false
  189. } else if (!this.newUserEmail || this.newUserEmail === '') {
  190. this.onRemind('请输入邮箱')
  191. this.newEmailCheck = false
  192. } else {
  193. if (this.newEmailCheck && this.newPhoneCheck) {
  194. this.$http.post('/basic/user', {userEmail: this.newUserEmail, userName: this.newUserName, userSex: this.sex, userTel: this.newUserPhone})
  195. .then(response => {
  196. if (response) {
  197. this.onRemind('增加用户成功' + this.newUserName)
  198. this.$router.push('/mobile/user/staff')
  199. }
  200. })
  201. } else {
  202. this.checkPhone()
  203. this.checkEmail()
  204. }
  205. }
  206. },
  207. // 取消绑定
  208. cancelBind () {
  209. this.$router.push('/mobile/user/staff')
  210. },
  211. // 搜索已注册用户
  212. addApply () {
  213. if (this.searchKeyword) {
  214. this.$http.get('/basic/user/searchUser', {params: {keyWord: this.searchKeyword}}).then(response => {
  215. if (response.data) {
  216. this.showSearchUser = true
  217. this.newUserInfo = response.data
  218. this.bindUser = true
  219. this.illegalError = false
  220. this.reBindError = false
  221. if (this.newUserInfo.userUU === this.userInfo.userUU) {
  222. //不可自己绑定自己
  223. this.illegalError = true
  224. this.bindUser = false
  225. } else {
  226. for (var i = 0; i < this.newUserInfo.enterprises.length; i++) {
  227. if (this.newUserInfo.enterprises[i].current) {
  228. for (var j = 0; j < this.userInfo.enterprises.length; j++) {
  229. //该用户已绑定到当前企业,不可重复绑定
  230. if (this.newUserInfo.enterprises[i].uu === this.userInfo.enterprises[j].uu) {
  231. this.reBindError = true
  232. this.bindUser = false
  233. }
  234. }
  235. }
  236. }
  237. }
  238. } else {
  239. // 未搜索到结果
  240. this.showSearchUser = false
  241. this.bindUser = false
  242. this.reBindError = false
  243. this.illegalError = false
  244. }
  245. })
  246. }
  247. },
  248. // 确定绑定已注册用户
  249. sureBindNewUser () {
  250. let isFlag = false
  251. if (this.newUserInfo.enterprises.length) {
  252. this.newUserInfo.enterprises.forEach(item => {
  253. if (item.uu === this.user.data.enterprise.uu) {
  254. isFlag = true
  255. }
  256. })
  257. }
  258. if (isFlag) {
  259. this.onRemind('该用户已绑定到当前企业,不可重复绑定!')
  260. } else {
  261. this.$http.get('/basic/user/bindUser', {params: {userUU: this.newUserInfo.userUU}})
  262. .then(response => {
  263. if (response) {
  264. this.onRemind('增加用户成功' + this.newUserInfo.userName)
  265. this.$router.push('/mobile/user/staff')
  266. }
  267. })
  268. }
  269. }
  270. }
  271. }
  272. </script>
  273. <style lang="scss" scoped>
  274. $base-color: #3f84f6;
  275. #mobile-staff-center {
  276. .staff-head {
  277. height: .82rem;
  278. line-height: .82rem;
  279. text-align: center;
  280. background: #fff;
  281. span {
  282. font-size: .29rem;
  283. &:last-child {
  284. margin-left: 2.6rem;
  285. }
  286. &.active {
  287. color: $base-color;
  288. border-bottom: 1px solid $base-color;
  289. }
  290. }
  291. }
  292. .staff-record {
  293. .search-content {
  294. overflow: hidden;
  295. padding: .25rem 0;
  296. text-align: center;
  297. input {
  298. width: 6.9rem;
  299. border: 1px solid #376ff3;
  300. }
  301. }
  302. .list-content{
  303. margin: 0 auto;
  304. padding: 0 .20rem;
  305. .staff-adds {
  306. margin: 0.25rem auto 0;
  307. padding: 0 .24rem;
  308. width: 6.64rem;
  309. background-color: #ffffff;
  310. border-radius: .05rem;
  311. li{
  312. overflow: hidden;
  313. height: 1.18rem;
  314. line-height: 1.18rem;
  315. border-bottom: 1px solid #d9d9d9;
  316. list-style: none;
  317. span {
  318. display: inline-block;
  319. float: left;
  320. width: 1rem;
  321. font-size: .28rem;
  322. color: #3f84f6;
  323. }
  324. input{
  325. float: left;
  326. width: 4.85rem;
  327. border: none;
  328. outline: none;
  329. }
  330. div.sex-filter {
  331. float: left;
  332. position: relative;
  333. margin-top: .3rem;
  334. width: .73rem;
  335. height: .58rem;
  336. line-height: .58rem;
  337. border-radius: .05rem;
  338. border: solid 1px #b4b4b4;
  339. .select-wrap {
  340. width: .73rem;
  341. height: .58rem;
  342. text-align: center;
  343. i{
  344. font-size: .1rem;
  345. font-weight: bold;
  346. color: $base-color;
  347. }
  348. }
  349. ul.select-list{
  350. width: .73rem;
  351. position: absolute;
  352. left: -0.02rem;
  353. top: .59rem;
  354. border: solid 1px #b4b4b4;
  355. border-top: none;
  356. -webkit-box-shadow: 0 1px 5px 0 #aaa;
  357. box-shadow: 0 1px 5px 0 #aaa;
  358. border-radius: .04rem;
  359. li{
  360. background: #fff;
  361. text-align: center;
  362. padding: 0 .13rem;
  363. font-size: .28rem;
  364. height: .53rem;
  365. line-height: .53rem;
  366. }
  367. }
  368. }
  369. &:last-child {
  370. border-bottom: none;
  371. }
  372. }
  373. }
  374. .staff-footer{
  375. overflow: hidden;
  376. margin-top: .6rem;
  377. div.handle{
  378. float: left;
  379. width: 3.24rem;
  380. height: .77rem;
  381. line-height: .77rem;
  382. font-size: .32rem;
  383. color: #fff;
  384. text-align: center;
  385. border-radius: .08rem;
  386. &:first-child{
  387. margin: 0 .28rem 0 .2rem;
  388. background-color: #acaaab;
  389. }
  390. &:last-child{
  391. background-color: #3f84f6 ;
  392. }
  393. }
  394. }
  395. .staff-list {
  396. margin: 0 auto;
  397. padding: .35rem .24rem .15rem;
  398. width: 6.64rem;
  399. background-color: #ffffff;
  400. border-radius: .05rem;
  401. .list-item {
  402. overflow: hidden;
  403. margin-bottom: .1rem;
  404. span{
  405. float: left;
  406. font-size: .28rem;
  407. color: #3f84f6;
  408. &:first-child{
  409. width: 1.3rem;
  410. }
  411. &:last-child{
  412. width: 4.8rem;
  413. color: #666;
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. }
  421. </style>