addUser.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <template>
  2. <div class="form-submit">
  3. <div class="i-layout-page-header">
  4. <PageHeader class="product_tabs" hidden-breadcrumb>
  5. <div slot="title">
  6. <router-link :to="{ path: `${roterPre}/erp/user` }">
  7. <!-- <Button icon="ios-arrow-back" size="small" class="mr20"
  8. >返回</Button
  9. > -->
  10. <div class="font-sm after-line">
  11. <span class="iconfont iconfanhui"></span>
  12. <span class="pl10">返回</span>
  13. </div>
  14. </router-link>
  15. <span v-text="
  16. $route.query.id !== '0' ? '编辑用户' : '添加用户'
  17. " class="mr20 ml16"></span>
  18. </div>
  19. </PageHeader>
  20. </div>
  21. <Card :bordered="false" dis-hover class="ivu-mt">
  22. <Form class="formValidate mt20" ref="formValidate" :rules="ruleValidate" :model="formValidate"
  23. :label-width="labelWidth" :label-position="labelPosition" @submit.native.prevent>
  24. <Row :gutter="24" type="flex">
  25. <FormItem label="用户头像:" prop="avatar" v-if="avshow">
  26. <Row>
  27. <Col span="24">
  28. <div v-if="formValidate.avatar" class="upload-list">
  29. <div class="upload-item">
  30. <img v-lazy="formValidate.avatar" />
  31. <Button shape="circle" icon="ios-close" @click="delImage"></Button>
  32. </div>
  33. </div>
  34. <Button v-else class="upload-select" type="dashed" icon="ios-add"
  35. @click="modalPicTap('dan', 'avatar', 1)"></Button>
  36. </Col>
  37. </Row>
  38. <Row>
  39. <Col class="tips">
  40. 建议上传大小:宽200px,高200px
  41. </Col>
  42. </Row>
  43. </FormItem>
  44. <Col span="24">
  45. <FormItem label="用户名称:" prop="staff_name">
  46. <Input v-model="formValidate.staff_name" placeholder="请输入用户名称" v-width="'400'" />
  47. </FormItem>
  48. </Col>
  49. <!-- is_manager -->
  50. <Col span="24">
  51. <FormItem label="是否管理:">
  52. <i-switch v-model="formValidate.is_manager" :true-value="1" :false-value="0" size="large">
  53. <span slot="open">是</span>
  54. <span slot="close">否</span>
  55. </i-switch>
  56. </FormItem>
  57. </Col>
  58. <!-- is_system -->
  59. <Col span="24">
  60. <FormItem label="是否系统用户:">
  61. <i-switch v-model="formValidate.is_system" :true-value="1" :false-value="0" size="large">
  62. <span slot="open">是</span>
  63. <span slot="close">否</span>
  64. </i-switch>
  65. </FormItem>
  66. </Col>
  67. <Col span="24">
  68. <FormItem label="登录账号:" prop="account" >
  69. <Input v-model="formValidate.account" placeholder="请输入账号" v-width="'400'" :disabled="formValidate.id != 0"/>
  70. </FormItem>
  71. </Col>
  72. <Col span="24">
  73. <FormItem label="登录密码:" prop="pwd" label-for="pwd" v-if="formValidate.id == 0">
  74. <Input v-model="formValidate.pwd" placeholder="请输入登录密码" v-width="'400'" type="password" />
  75. </FormItem>
  76. </Col>
  77. <Col span="24">
  78. <FormItem label="绑定用户:" prop="nickname" label-for="nickname" v-if="ushow">
  79. <Input v-model="formValidate.nickname" @on-clear="clearSpread" clearable placeholder="请选择商城用户"
  80. icon="ios-arrow-down" @on-focus="editSpread" v-width="'400'" @on-blur="showUser"></Input>
  81. </FormItem>
  82. </Col>
  83. <Col span="24">
  84. <FormItem label="绑定客服:" prop="kefu" label-for="kefu" v-if="kshow">
  85. <Input v-model="formValidate.kefu" @on-clear="clearSpreadKefu" clearable placeholder="请选择客服"
  86. icon="ios-arrow-down" @on-focus="editSpreadKefu" v-width="'400'"
  87. @on-blur="showKefu"></Input>
  88. </FormItem>
  89. </Col>
  90. <Col span="24">
  91. <FormItem label="绑定后台:" prop="admin_name" label-for="admin_name" v-if="ashow">
  92. <Input v-model="formValidate.admin_name" @on-clear="clearSpreadAdmin" clearable
  93. placeholder="请选择后台账号" icon="ios-arrow-down" @on-focus="editSpreadAdmin" v-width="'400'"
  94. @on-blur="showAdmin"></Input>
  95. </FormItem>
  96. </Col>
  97. <Col span="24">
  98. <FormItem label="账号归属:" prop="wid">
  99. <RadioGroup v-model="formValidate.type">
  100. <!-- :disabled="formValidate.id != 0" -->
  101. <Radio :label="0" >
  102. <Icon type="social-apple"></Icon>
  103. <span>系统</span>
  104. </Radio>
  105. <Radio :label="1" >
  106. <Icon type="social-apple"></Icon>
  107. <span>仓库</span>
  108. </Radio>
  109. <Radio :label="2" >
  110. <Icon type="social-android"></Icon>
  111. <span>门店</span>
  112. </Radio>
  113. </RadioGroup>
  114. </FormItem>
  115. </Col>
  116. <Col span="24">
  117. <FormItem label="所属仓库:" prop="wid" v-if="this.formValidate.type == 1">
  118. <el-cascader placeholder="请选择所属仓库" class="input-add" size="mini" v-model="formValidate.wid"
  119. :options="data1" :props="props" @change="userSearchs" filterable clearable v-width="'400'">
  120. </el-cascader>
  121. </FormItem>
  122. </Col>
  123. <Col span="24">
  124. <FormItem label="所属门店:" prop="store_id" v-if="this.formValidate.type == 2">
  125. <el-cascader placeholder="请选择所属门店" class="input-add" size="mini" v-model="formValidate.store_id"
  126. :options="staffData" :props="propss" @change="userSearchs" filterable clearable
  127. v-width="'400'">
  128. </el-cascader>
  129. </FormItem>
  130. </Col>
  131. <!-- tableList -->
  132. <Col span="24">
  133. <FormItem label="角色身份:" prop="roles" >
  134. <el-cascader placeholder="请选择角色身份" class="input-add" size="mini" v-model="formValidate.roles"
  135. :options="tableList" :props="propsss" @change="userSearchs" filterable clearable
  136. v-width="'400'">
  137. </el-cascader>
  138. </FormItem>
  139. </Col>
  140. <Col span="24">
  141. <FormItem label="手机号码:" prop="phone">
  142. <Input v-model="formValidate.phone" placeholder="请输入手机号码" v-width="'400'" />
  143. </FormItem>
  144. </Col>
  145. </Row>
  146. </Form>
  147. </Card>
  148. <Card :bordered="false" dis-hover class="fixed-card"
  149. :style="{ left: `${!menuCollapse ? '200px' : isMobile ? '0' : '80px'}` }">
  150. <Form>
  151. <FormItem>
  152. <Button type="primary" class="submission" @click="handleSubmit('formValidate')">保存</Button>
  153. </FormItem>
  154. </Form>
  155. </Card>
  156. <Modal v-model="customerShow" scrollable title="请选择商城用户" :closable="false" width="900">
  157. <customerInfo v-if="customerShow" @imageObject="imageObject"></customerInfo>
  158. </Modal>
  159. <Modal v-model="adminShow" scrollable title="请选择商城用户" :closable="false" width="900">
  160. <adminList v-if="adminShow" @imageObject="imageObjectAdmin"></adminList>
  161. </Modal>
  162. <Modal v-model="kefuShow" scrollable title="请选择绑定客服" :closable="false" width="900">
  163. <kefuList v-if="kefuShow" @imageObject="imageObjectKefu"></kefuList>
  164. </Modal>
  165. <Modal v-model="modalPic" width="960px" scrollable footer-hide closable title="上传用户头像" :mask-closable="false"
  166. :z-index="500">
  167. <uploadPictures isChoice="单选" @getPic="getPic" :gridBtn="gridBtn" :gridPic="gridPic" v-if="modalPic">
  168. </uploadPictures>
  169. </Modal>
  170. </div>
  171. </template>
  172. <script>
  173. import customerInfo from "@/components/customerInfo";
  174. import kefuList from "@/components/kfList";
  175. import adminList from "@/components/adminList";
  176. import uploadPictures from "@/components/uploadPictures";
  177. import {
  178. mapState,
  179. mapMutations
  180. } from "vuex";
  181. import {
  182. getGodownList,
  183. createUser,
  184. getUserInfo
  185. } from "@/api/erp";
  186. import {
  187. keyApi,
  188. storeGetInfoApi,
  189. cityApi,
  190. storeUpdateApi,
  191. cascaderList,
  192. staffListInfo
  193. } from '@/api/store';
  194. import {
  195. productSpecs,
  196. productSpecsInfo
  197. } from "@/api/product";
  198. import Setting from "@/setting";
  199. import {
  200. roleListApi,
  201. } from '@/api/setting'
  202. export default {
  203. name: "userAdd",
  204. components: {
  205. uploadPictures,
  206. customerInfo,
  207. kefuList,
  208. adminList
  209. },
  210. data() {
  211. return {
  212. tableList: [],
  213. avshow: true,
  214. ushow: true,
  215. customerShow: false,
  216. kshow: true,
  217. kefuShow: false,
  218. ashow: true,
  219. adminShow: false,
  220. modalPic: false,
  221. propss: {
  222. emitPath: false,
  223. multiple: false,
  224. checkStrictly: true,
  225. value: "id",
  226. label: "name"
  227. },
  228. propsss: {
  229. emitPath: false,
  230. multiple: false,
  231. checkStrictly: true,
  232. value: "id",
  233. label: "role_name"
  234. },
  235. addresData: [],
  236. props: {
  237. emitPath: false,
  238. multiple: false,
  239. checkStrictly: true,
  240. value: "id",
  241. label: "title"
  242. },
  243. roterPre: Setting.roterPre,
  244. data1: [],
  245. grid: {
  246. xl: 7,
  247. lg: 7,
  248. md: 12,
  249. sm: 24,
  250. xs: 24,
  251. },
  252. formValidate: {
  253. type: 0,
  254. avatar: "",
  255. uid: 0,
  256. nickname: "",
  257. id: 0,
  258. account: "",
  259. wid: 0,
  260. staff_name: "",
  261. store_id: 0,
  262. is_manager: 0,
  263. pwd: "",
  264. phone: "",
  265. kefu: "",
  266. staff_id: 0,
  267. admin_name: "",
  268. is_system: 0,
  269. admin_id: 0,
  270. roles: 0
  271. },
  272. gridBtn: {
  273. xl: 4,
  274. lg: 8,
  275. md: 8,
  276. sm: 8,
  277. xs: 8,
  278. },
  279. gridPic: {
  280. xl: 6,
  281. lg: 8,
  282. md: 12,
  283. sm: 12,
  284. xs: 12,
  285. },
  286. staffData: [],
  287. ruleValidate: {
  288. nickname: [{
  289. required: true,
  290. message: "请选择绑定用户",
  291. trigger: "blur"
  292. }],
  293. kefu: [{
  294. required: true,
  295. message: "请选择绑定客服",
  296. trigger: "blur"
  297. }],
  298. admin_name: [{
  299. required: true,
  300. message: "请选择绑定后台账号",
  301. trigger: "blur"
  302. }],
  303. avatar: [{
  304. required: true,
  305. message: "请上传用户头像",
  306. trigger: "blur"
  307. }],
  308. staff_name: [{
  309. required: true,
  310. message: "请输入用户名称",
  311. trigger: "blur"
  312. }],
  313. account: [{
  314. required: true,
  315. message: "请输入登录账号",
  316. trigger: "blur"
  317. }, ],
  318. pwd: [{
  319. required: true,
  320. message: '请输入登录密码',
  321. trigger: 'blur'
  322. }],
  323. phone: [{
  324. required: true,
  325. message: '请输入手机号码',
  326. trigger: 'blur',
  327. }, ],
  328. roles: [{
  329. required: true,
  330. type: 'number',
  331. message: '请选择角色身份',
  332. }, ],
  333. },
  334. };
  335. },
  336. computed: {
  337. ...mapState("admin/layout", ["isMobile", "menuCollapse"]),
  338. labelWidth() {
  339. return this.isMobile ? undefined : 120;
  340. },
  341. labelPosition() {
  342. return this.isMobile ? "top" : "right";
  343. },
  344. },
  345. created() {
  346. // let data = {
  347. // pid: 0
  348. // }
  349. // this.cityInfo(data);
  350. },
  351. mounted() {
  352. this.getList()
  353. // this.setCopyrightShow({
  354. // value: false
  355. // });
  356. this.getGodownList()
  357. this.staffList()
  358. console.log('this.$route.query.id != 0', this.$route.query.id != 0);
  359. if (this.$route.query.id != 0) {
  360. this.getUserInfo(this.$route.query.id)
  361. }
  362. },
  363. destroyed() {
  364. // this.setCopyrightShow({
  365. // value: true
  366. // });
  367. },
  368. methods: {
  369. ...mapMutations("admin/layout", ["setCopyrightShow"]),
  370. getUserInfo(id) {
  371. console.log('hhh');
  372. getUserInfo(id).then(res => {
  373. console.log('zje', res);
  374. let data = res.data
  375. this.formValidate = {
  376. uid: data.user.uid,
  377. nickname: data.user ? data.user.nickname :'',
  378. id: id,
  379. account: data.account || '',
  380. wid: data.wid || 0,
  381. staff_name: data.staff_name || '',
  382. store_id: data.store_id,
  383. is_manager: data.is_manager,
  384. phone: data.phone,
  385. kefu: data.staff ? data.staff.nickname:'',
  386. staff_id: data.staff ?data.staff.id:0,
  387. admin_name: data.admin? data.admin.real_name: '',
  388. is_system: data.is_system + '',
  389. admin_id: data.admin?data.admin.id: 0,
  390. avatar: data.avatar,
  391. type: data.wid?1:(data.store_id?2:0),
  392. roles: data.roles*1 || 0
  393. }
  394. })
  395. },
  396. imageObject(e) {
  397. this.customerShow = false;
  398. this.formValidate.uid = e.uid;
  399. this.formValidate.nickname = e.name
  400. },
  401. imageObjectKefu(e) {
  402. this.kefuShow = false;
  403. this.formValidate.staff_id = e.id;
  404. this.formValidate.kefu = e.name
  405. },
  406. imageObjectAdmin(e) {
  407. this.adminShow = false;
  408. console.log(e);
  409. this.formValidate.admin_id = e.id;
  410. this.formValidate.level = e.level;
  411. this.formValidate.admin_name = e.name
  412. },
  413. showUser() {
  414. this.ushow = true
  415. },
  416. showKefu() {
  417. this.kshow = true
  418. },
  419. showAdmin() {
  420. this.ashow = true
  421. },
  422. clearSpread() {
  423. this.formValidate.uid = 0;
  424. this.formValidate.nickname = '';
  425. this.ushow = true
  426. },
  427. clearSpreadKefu() {
  428. this.formValidate.staff_id = 0;
  429. this.formValidate.kefu = '';
  430. this.kshow = true
  431. },
  432. clearSpreadAdmin() {
  433. this.formValidate.admin_id = 0;
  434. this.formValidate.admin_name = '';
  435. this.formValidate.level = 0
  436. this.ashow = true
  437. },
  438. editSpread() {
  439. this.customerShow = true;
  440. this.ushow = false
  441. },
  442. editSpreadKefu() {
  443. this.kefuShow = true;
  444. this.kshow = false
  445. },
  446. editSpreadAdmin() {
  447. this.adminShow = true;
  448. this.ashow = false
  449. },
  450. getPic(pic) {
  451. this.modalPic = false;
  452. this.formValidate.avatar = pic.att_dir;
  453. this.avshow = true
  454. this.$refs.formValidate.validateField('image');
  455. },
  456. delImage() {
  457. this.formValidate.avatar = "";
  458. this.$refs.formValidate.validateField('image');
  459. this.avshow = true
  460. },
  461. modalPicTap() {
  462. this.modalPic = true;
  463. this.avshow = false
  464. },
  465. staffList() {
  466. staffListInfo()
  467. .then((res) => {
  468. this.staffData = res.data
  469. })
  470. .catch((err) => {
  471. this.$Message.error(err.msg);
  472. });
  473. },
  474. addchack(e, selectedData) {
  475. console.log(selectedData, 'selectedData');
  476. e.forEach((i, index) => {
  477. if (index == 0) {
  478. this.formValidate.province = i
  479. } else if (index == 1) {
  480. this.formValidate.city = i
  481. } else if (index == 2) {
  482. this.formValidate.area = i
  483. } else {
  484. this.formValidate.street = i
  485. }
  486. })
  487. this.formValidate.address = (selectedData.map(o => o.label)).join('/')
  488. // console.log('this.formValidate.addressSelect',this.formValidate.addressSelect);
  489. },
  490. cityInfo(data) {
  491. cityApi(data).then(res => {
  492. this.addresData = res.data
  493. })
  494. },
  495. loadData(item, callback) {
  496. item.loading = true;
  497. cityApi({
  498. pid: item.value
  499. }).then(res => {
  500. item.children = res.data;
  501. item.loading = false;
  502. callback();
  503. });
  504. },
  505. getGodownList() {
  506. getGodownList().then(res => {
  507. console.log(res);
  508. this.data1 = res.data.data
  509. })
  510. },
  511. del(index) {
  512. this.data.splice(index, 1);
  513. },
  514. userSearchs(e) {
  515. },
  516. handleSubmit(name) {
  517. this.$refs[name].validate((valid) => {
  518. if (valid) {
  519. this.formValidate.id = this.$route.query.id;
  520. if(this.formValidate.type == 1) {
  521. this.formValidate.store_id = ''
  522. }else {
  523. this.formValidate.wid = ''
  524. }
  525. createUser(this.formValidate.id, this.formValidate).then(res => {
  526. this.$Message.success(res.msg);
  527. this.$router.push({
  528. path: this.roterPre + "/erp/user"
  529. });
  530. }).catch(err => {
  531. this.$Message.error(err.msg);
  532. })
  533. console.log('this.formValidate:', this.formValidate);
  534. } else {
  535. // this.$Message.error("请输入参数模板名称");
  536. }
  537. });
  538. },
  539. getList() {
  540. this.loading = true
  541. roleListApi({
  542. page: 1,
  543. limit:100,
  544. type: 3
  545. })
  546. .then(async (res) => {
  547. let data = res.data
  548. this.tableList = data.list
  549. // this.total = res.data.count
  550. // this.loading = false
  551. })
  552. .catch((res) => {
  553. this.loading = false
  554. this.$Message.error(res.msg)
  555. })
  556. },
  557. },
  558. };
  559. </script>
  560. <style scoped lang="stylus">
  561. .table {
  562. /deep/.ivu-table-header table {
  563. border: 0 !important;
  564. }
  565. /deep/.ivu-table-header thead tr th:nth-of-type(1) {
  566. padding-left: 16px;
  567. }
  568. /deep/.ivu-table td:nth-of-type(1) {
  569. padding-left: 16px;
  570. }
  571. /deep/.ivu-table-cell {
  572. padding: 0 !important;
  573. }
  574. /deep/.ivu-table-border th,
  575. /deep/.ivu-table-border td {
  576. border-right: unset;
  577. }
  578. /deep/.ivu-table td {
  579. height: 59px;
  580. }
  581. }
  582. .form-submit {
  583. /deep/.ivu-card {
  584. border-radius: 0;
  585. }
  586. margin-bottom: 79px;
  587. .fixed-card {
  588. position: fixed;
  589. right: 0;
  590. bottom: 0;
  591. left: 200px;
  592. z-index: 99;
  593. box-shadow: 0 -1px 2px rgb(240, 240, 240);
  594. /deep/ .ivu-card-body {
  595. padding: 15px 16px 14px;
  596. }
  597. .ivu-form-item {
  598. margin-bottom: 0;
  599. }
  600. /deep/ .ivu-form-item-content {
  601. margin-right: 124px;
  602. text-align: center;
  603. }
  604. .ivu-btn {
  605. height: 36px;
  606. padding: 0 20px;
  607. }
  608. }
  609. }
  610. .after-line {
  611. display: inline-block;
  612. position: relative;
  613. margin-right: 16px;
  614. }
  615. .ml16 {
  616. margin-left: 16px;
  617. }
  618. .upload-list {
  619. display: inline-block;
  620. margin: 0 0 -10px 0;
  621. .upload-item {
  622. position: relative;
  623. display: inline-block;
  624. width: 64px;
  625. height: 64px;
  626. border: 1px dashed #DDDDDD;
  627. border-radius: 4px;
  628. margin: 0 15px 10px 0;
  629. }
  630. img {
  631. width: 64px;
  632. height: 64px;
  633. border-radius: 4px;
  634. vertical-align: middle;
  635. }
  636. .ivu-btn {
  637. position: absolute;
  638. top: 0;
  639. right: 0;
  640. width: 20px;
  641. height: 20px;
  642. margin: -10px -10px 0 0;
  643. }
  644. }
  645. .upload-select {
  646. width: 64px;
  647. height: 64px;
  648. font-size: 35px !important;
  649. background #f5f5f5;
  650. color #ccc;
  651. }
  652. </style>