add.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div>
  3. <el-button size="small" type="primary" icon="el-icon-plus" @click="onShow">新 建</el-button>
  4. <el-drawer
  5. title="创建用户"
  6. :visible.sync="drawer"
  7. size="664px"
  8. direction="rtl"
  9. append-to-body
  10. :show-close="false"
  11. @close="onClose">
  12. <div class="drawer__panel">
  13. <el-row>
  14. <el-form :model="form" :rules="rules" ref="form" size="mini" label-position="right">
  15. <el-col :span="24">
  16. <el-form-item label="手机号码" label-width="80px" prop="phonenumber">
  17. <el-popover
  18. placement="bottom"
  19. trigger="manual"
  20. v-model="visible1"
  21. width="500">
  22. <searchInput ref="searchInput" :param="pepoleParam" :radio="true" @onSelect="setLeader" @onCancel="visible1 = false"></searchInput>
  23. <el-input type="text" v-model.number="form.phonenumber" size="small" placeholder="请输入手机号" slot="reference" @input="phoneChange"></el-input>
  24. </el-popover>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="24">
  28. <el-form-item label="账号" label-width="80px" prop="accountno">
  29. <el-input v-model="form.accountno" :disabled="!!isSelectPhone" autocomplete="off" placeholder="编辑账号"></el-input>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="24">
  33. <el-form-item label="用户名称" label-width="80px" prop="name">
  34. <el-input v-model="form.name" :disabled="!!isSelectPhone" autocomplete="off" placeholder="输入用户名称"></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="24" v-if="isSelectPhone">
  38. <el-form-item label="用户类型" label-width="80px" prop="usertype">
  39. <el-select v-model="form.usertype" style="width:100%" placeholder="请选择">
  40. <el-option
  41. v-for="item in selectType"
  42. :label="item.remarks"
  43. :value="item.value"
  44. :key="item.index"
  45. ></el-option>
  46. </el-select>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="24">
  50. <el-form-item label="授权角色" label-width="80px" prop="roleids">
  51. <!-- <el-input v-model="form.sex" autocomplete="off" placeholder="输入性别"></el-input> -->
  52. <el-select v-model="form.roleids" style="width:100%" placeholder="请选择" multiple>
  53. <el-option
  54. v-for="item in options"
  55. :key="item.index"
  56. :label="item.rolename"
  57. :value="item.roleid">
  58. <span style="float: left">{{ item.rolename }}</span>
  59. <span style="float: right; color: #8492a6; font-size: 12px">{{ item.remarks?item.remarks:'暂无描述' }}</span>
  60. </el-option>
  61. </el-select>
  62. </el-form-item>
  63. </el-col>
  64. </el-form>
  65. </el-row>
  66. </div>
  67. <div class="fixed__btn__panel">
  68. <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
  69. <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
  70. </div>
  71. </el-drawer>
  72. </div>
  73. </template>
  74. <script>
  75. import searchInput from '@/template/searchInput/index.vue'
  76. export default {
  77. components:{searchInput},
  78. data () {
  79. return {
  80. drawer:false,
  81. visible1:false,
  82. timer:null,
  83. isDisabled:false,
  84. isSelectPhone:'',
  85. selectType:[],
  86. rules:{
  87. phonenumber: [
  88. { required: true, message: '请输入手机号码', trigger: 'change' },
  89. { pattern:/^1[3-9]\d{9}$/, message: '请输入正确手机号码',trigger: 'change' }
  90. ],
  91. name: [
  92. { required: true, message: '请输入用户名称', trigger: 'blur' },
  93. ],
  94. roleids: [
  95. { required: true, message: '请选择授权角色', trigger: 'change' }
  96. ],
  97. usertype: [
  98. { required: true, message: '请选择用户类型', trigger: 'change' }
  99. ],
  100. },
  101. form:{
  102. "userid": 0,
  103. "name": "",
  104. "phonenumber": "",
  105. "status": 1,
  106. "remarks":"",
  107. "roleids":[],
  108. "accountno":'',
  109. },
  110. options:[],
  111. pepoleParam: {
  112. "classname": "webmanage.users.users",
  113. "method": "query_notinmysiteuserList",
  114. "content": {
  115. "pageNumber": 1,
  116. "pageSize": 99999,
  117. "where": {
  118. "condition": ""
  119. }
  120. }
  121. }
  122. }
  123. },
  124. watch: {
  125. drawer (val) {
  126. if (!val) {
  127. this.$refs.form.resetFields()
  128. this.isSelectPhone = ''
  129. }
  130. }
  131. },
  132. methods:{
  133. onShow () {
  134. this.drawer = true
  135. this.rolelist()
  136. this.accountTypeList()
  137. },
  138. async accountTypeList() {
  139. let param = {
  140. classname: "sysmanage.develop.optiontype.optiontype",
  141. method: "optiontypeselect",
  142. content: {
  143. pageNumber: 1,
  144. pageSize: 20,
  145. typename: "usertype",
  146. parameter: {},
  147. },
  148. };
  149. const res = await this.$api.requested(param);
  150. res.data.pop()
  151. this.selectType = res.data;
  152. console.log(this.selectType);
  153. },
  154. async rolelist () {
  155. let param = {
  156. "classname": "sysmanage.develop.optiontype.optiontype",
  157. "method": "optiontypeselect",
  158. "content": {
  159. "pageNumber": 1,
  160. "pageSize": 20,
  161. "typename": "role",
  162. "parameter": {
  163. }
  164. }
  165. }
  166. const res = await this.$api.requested(param)
  167. this.options = res.data
  168. },
  169. phoneChange (e) {
  170. if (e.length < 7) return this.visible1 = false
  171. if (this.isSelectPhone && this.isSelectPhone != e) {
  172. this.clearData()
  173. }
  174. this.visible1 = false
  175. if (this.timer) clearTimeout(this.timer)
  176. this.timer = setTimeout(() => {
  177. this.pepoleParam.content.where.condition = e
  178. this.$refs.searchInput.listData(() => {
  179. this.visible1 = true
  180. })
  181. },500)
  182. },
  183. setLeader (data) {
  184. console.log(data);
  185. this.visible1 = false
  186. this.form.userid = data.userid
  187. this.form.name = data.name
  188. this.form.phonenumber = data.phonenumber
  189. this.form.accountno = data.accountno
  190. this.isSelectPhone = data.phonenumber
  191. },
  192. clearData () {
  193. this.form.userid = ''
  194. this.form.name = ''
  195. this.form.accountno = ''
  196. this.isSelectPhone = ''
  197. this.form.usertype = ''
  198. this.form.roleids = []
  199. },
  200. onSubmit () {
  201. this.$refs['form'].validate((valid) => {
  202. if (!valid) return false
  203. if (!this.isSelectPhone) delete this.form.usertype
  204. this.$api.requested(this.isSelectPhone ? {
  205. "accesstoken": "be50a88845d9eee3fe75a924642cff22",
  206. "classname": "webmanage.users.users",
  207. "method": "addUserSite",
  208. "content": {
  209. "userid": this.form.userid,
  210. "roleids":this.form.roleids,
  211. "usertype":this.form.usertype
  212. }
  213. } : {
  214. "classname": "webmanage.users.users",
  215. "method": "insertormodify_user",
  216. "content": this.form
  217. }).then(res=>{
  218. if (res.code === 1) {
  219. this.$notify({
  220. title: '成功',
  221. message: '账号添加成功',
  222. type: 'success'
  223. });
  224. this.drawer = false
  225. this.$emit('onSuccess')
  226. } else {
  227. this.$notify({
  228. title: '失败',
  229. message: res.msg,
  230. type: 'error'
  231. });
  232. }
  233. })
  234. });
  235. },
  236. onClose () {
  237. this.$refs['form'].resetFields()
  238. }
  239. }
  240. }
  241. </script>
  242. <style scoped>
  243. .dialog-footer{
  244. margin-top:32px;
  245. text-align: center;
  246. }
  247. </style>