StaffAdd.vue 13 KB

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