StaffAdd.vue 14 KB

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