StaffAdd.vue 13 KB

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