StaffAdd.vue 14 KB

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