StaffAdd.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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: false,
  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.onRemind('请输入邮箱')
  158. this.newEmailCheck = false
  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 if (!this.newUserEmail || this.newUserEmail === '') {
  184. this.onRemind('请输入邮箱')
  185. this.newEmailCheck = false
  186. } else {
  187. if (this.newEmailCheck && this.newPhoneCheck) {
  188. this.$http.post('/basic/user', {userEmail: this.newUserEmail, userName: this.newUserName, userSex: this.sex, userTel: this.newUserPhone})
  189. .then(response => {
  190. if (response) {
  191. this.onRemind('增加用户成功' + this.newUserName)
  192. this.$router.push('/mobile/user/staff')
  193. }
  194. })
  195. } else {
  196. this.checkPhone()
  197. this.checkEmail()
  198. }
  199. }
  200. },
  201. // 取消绑定
  202. cancelBind () {
  203. this.$router.push('/mobile/user/staff')
  204. },
  205. // 搜索已注册用户
  206. addApply () {
  207. if (this.searchKeyword) {
  208. this.$http.get('/basic/user/searchUser', {params: {keyWord: this.searchKeyword}}).then(response => {
  209. if (response.data) {
  210. this.searchNoData = false
  211. if (response.data.userUU === this.userInfo.userUU) {
  212. //不可自己绑定自己
  213. this.bindSelf = true
  214. this.showSearchUser = false
  215. } else {
  216. this.showSearchUser = true
  217. this.bindSelf = false
  218. this.newUserInfo = response.data
  219. }
  220. } else {
  221. // 未搜索到结果
  222. this.searchNoData = true
  223. this.showSearchUser = false
  224. this.bindSelf = false
  225. }
  226. }).catch (err =>{
  227. if (err) {
  228. this.searchNoData = true
  229. this.showSearchUser = false
  230. this.bindSelf = false
  231. }
  232. })
  233. }
  234. },
  235. // 确定绑定已注册用户
  236. sureBindNewUser () {
  237. let isFlag = false
  238. if (this.newUserInfo.enterprises) {
  239. if (this.newUserInfo.enterprises.length) {
  240. this.newUserInfo.enterprises.forEach(item => {
  241. if (item.uu === this.user.data.enterprise.uu) {
  242. isFlag = true
  243. }
  244. })
  245. }
  246. }
  247. if (isFlag) {
  248. this.onRemind('该用户已绑定到当前企业,不可重复绑定!')
  249. } else {
  250. this.$http.get('/basic/user/bindUser', {params: {userUU: this.newUserInfo.userUU}})
  251. .then(response => {
  252. if (response) {
  253. this.onRemind('增加' + this.newUserInfo.userName +'用户成功')
  254. this.$router.push('/mobile/user/staff')
  255. }
  256. })
  257. }
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. $base-color: #3f84f6;
  264. #mobile-staff-center {
  265. .staff-head {
  266. height: .82rem;
  267. line-height: .82rem;
  268. text-align: center;
  269. background: #fff;
  270. span {
  271. font-size: .29rem;
  272. &:last-child {
  273. margin-left: 2.6rem;
  274. }
  275. &.active {
  276. color: $base-color;
  277. border-bottom: 1px solid $base-color;
  278. }
  279. }
  280. }
  281. .staff-record {
  282. .search-content {
  283. overflow: hidden;
  284. padding: .25rem 0;
  285. text-align: center;
  286. input {
  287. width: 6.9rem;
  288. border: 1px solid #376ff3;
  289. }
  290. }
  291. .list-content{
  292. margin: 0 auto;
  293. padding: 0 .20rem;
  294. .staff-adds {
  295. margin: 0.25rem auto 0;
  296. padding: 0 .24rem;
  297. width: 6.64rem;
  298. background-color: #ffffff;
  299. border-radius: .05rem;
  300. li{
  301. overflow: hidden;
  302. height: 1.18rem;
  303. line-height: 1.18rem;
  304. border-bottom: 1px solid #d9d9d9;
  305. list-style: none;
  306. span {
  307. display: inline-block;
  308. float: left;
  309. width: 1rem;
  310. font-size: .28rem;
  311. color: #3f84f6;
  312. }
  313. input{
  314. float: left;
  315. width: 4.85rem;
  316. border: none;
  317. outline: none;
  318. }
  319. div.sex-filter {
  320. float: left;
  321. position: relative;
  322. margin-top: .3rem;
  323. width: .73rem;
  324. height: .58rem;
  325. line-height: .58rem;
  326. border-radius: .05rem;
  327. border: solid 1px #b4b4b4;
  328. .select-wrap {
  329. width: .73rem;
  330. height: .58rem;
  331. text-align: center;
  332. i{
  333. font-size: .1rem;
  334. font-weight: bold;
  335. color: $base-color;
  336. }
  337. }
  338. ul.select-list{
  339. width: .73rem;
  340. position: absolute;
  341. left: -0.02rem;
  342. top: .59rem;
  343. border: solid 1px #b4b4b4;
  344. border-top: none;
  345. -webkit-box-shadow: 0 1px 5px 0 #aaa;
  346. box-shadow: 0 1px 5px 0 #aaa;
  347. border-radius: .04rem;
  348. li{
  349. background: #fff;
  350. text-align: center;
  351. padding: 0 .13rem;
  352. font-size: .28rem;
  353. height: .53rem;
  354. line-height: .53rem;
  355. }
  356. }
  357. }
  358. &:last-child {
  359. border-bottom: none;
  360. }
  361. }
  362. }
  363. .staff-footer{
  364. overflow: hidden;
  365. margin-top: .6rem;
  366. div.handle{
  367. float: left;
  368. width: 3.24rem;
  369. height: .77rem;
  370. line-height: .77rem;
  371. font-size: .32rem;
  372. color: #fff;
  373. text-align: center;
  374. border-radius: .08rem;
  375. &:first-child{
  376. margin: 0 .28rem 0 .2rem;
  377. background-color: #acaaab;
  378. }
  379. &:last-child{
  380. background-color: #3f84f6 ;
  381. }
  382. }
  383. }
  384. .staff-list {
  385. margin: 0 auto;
  386. padding: .35rem .24rem .15rem;
  387. width: 6.64rem;
  388. background-color: #ffffff;
  389. border-radius: .05rem;
  390. .list-item {
  391. overflow: hidden;
  392. margin-bottom: .1rem;
  393. span{
  394. float: left;
  395. font-size: .28rem;
  396. color: #3f84f6;
  397. &:first-child{
  398. width: 1.3rem;
  399. }
  400. &:last-child{
  401. width: 4.8rem;
  402. color: #666;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. </style>