authAdd.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <view class="appWrapper">
  3. <!-- 权限新增 start -->
  4. <form action="" v-if="!phone">
  5. <view class="form-item margin-top">
  6. <view class="title">
  7. <text class="necessary">*</text>
  8. 用户名称
  9. </view>
  10. <select name="" id="" v-model="formMess.mobile" filterable clearable>
  11. <option value="0">请选择</option>
  12. <option :value=item.phone v-for="item in phoneData">{{ item.phone}}</option>
  13. </select>
  14. </view>
  15. <view class="form-item">
  16. <view class="title " style="vertical-align:top">
  17. <text class="necessary">*</text>
  18. 站点:
  19. </view>
  20. <view style="position:relative" class="innerZd">
  21. <input name="siteName" v-model="formMess.siteName" @click="test" @focus="focusfns" @input="handleInput()"
  22. placeholder="请输入或选择"></input>
  23. <view class="siteItems" v-if="isShow" style="max-height:60vh;overflow:auto">
  24. <view class=" site-item" v-if="!siteItemData.length">暂无结果</view>
  25. <view class="site-item" v-for="(item,index) in siteItemData" @click="add(item,index)" :key="index">{{item.siteName}}</view>
  26. </view>
  27. <view style="width:500rpx;max-height:30vh;overflow:scroll" class="selectedBox">
  28. <button class="cu-btn sm margin-xs" v-for="(item,index) in selectedData" @click="deleteItem(item,index)">
  29. {{item.siteName}}
  30. <text class="lg text-gray cuIcon-close"></text>
  31. </button>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="form-item margin-top">
  36. <view class="title">
  37. <text class="necessary">*</text>
  38. 角色权限
  39. </view>
  40. <radio-group name="gender" @change="radioChange">
  41. <label class="margin-right">
  42. <radio value="2" checked /><text>维护人员</text>
  43. </label>
  44. <label>
  45. <radio value="3" /><text>供电人员</text>
  46. </label>
  47. </radio-group>
  48. </view>
  49. <view class="btn-area submitBottomBtn padding-lr-sm">
  50. <button class="bg-blue round margin-top" @click="$noMultipleClicks(addSubmit)">提 交 </button>
  51. </view>
  52. </form>
  53. <!-- 权限新增 end -->
  54. <!-- 权限修改 start -->
  55. <form action="" v-else>
  56. <view class="form-item margin-top">
  57. <view class="title">
  58. <text class="necessary">*</text>
  59. 用户名称
  60. </view>
  61. <select name="" id="" v-model="authorityData.phone" filterable clearable disabled="disabled">
  62. <option :value=item.phone v-for="item in phoneData">{{ item.phone}}</option>
  63. </select>
  64. </view>
  65. <view class="form-item">
  66. <view class="title " style="vertical-align:top">
  67. <text class="necessary">*</text>
  68. 站点:
  69. </view>
  70. <view style="position:relative" class="innerZd">
  71. <input name="siteName" v-model="authorityData.siteName" @click="test" @focus="focusfns" @input="handleInputEdit()"
  72. placeholder="请输入或选择"></input>
  73. <view class="siteItems" v-if="isShow" style="max-height:60vh;overflow:auto">
  74. <view class=" site-item" v-if="!siteItemData.length">暂无结果</view>
  75. <view class="site-item" v-for="(item,index) in siteItemData" @click="add(item,index)" :key="index">{{item.siteName}}</view>
  76. </view>
  77. <view style="width:500rpx;max-height:30vh;overflow:scroll" class="selectedBox">
  78. <button class="cu-btn margin-xs" v-for="(item,index) in selectedData" @click="deleteItem(item,index)">
  79. {{item.siteName}}
  80. <text class="lg text-gray cuIcon-close"></text>
  81. </button>
  82. </view>
  83. </view>
  84. </view>
  85. <view class="form-item margin-top">
  86. <view class="title">
  87. <text class="necessary">*</text>
  88. 角色权限
  89. </view>
  90. <radio-group name="gender" @change="radioChange">
  91. <label class="margin-right">
  92. <radio value="2" :checked='authorityData.permissionLabel == 2' /><text>维护人员</text>
  93. </label>
  94. <label>
  95. <radio value="3" :checked='authorityData.permissionLabel == 3' /><text>供电人员</text>
  96. </label>
  97. </radio-group>
  98. </view>
  99. <view class="btn-area submitBottomBtn padding-lr-sm">
  100. <button class="bg-blue round margin-top" @click="$noMultipleClicks(editSbuimt)">提 交 </button>
  101. </view>
  102. </form>
  103. <!-- 权限修改 end -->
  104. </view>
  105. </template>
  106. <script>
  107. export default {
  108. data() {
  109. return {
  110. noClick:true,
  111. index: -1,
  112. type: '0',
  113. phone:'',
  114. authorityData:{},
  115. isShow: false,
  116. formMess: {
  117. "userName": "",
  118. "siteName": "",
  119. "place": "",
  120. "longitude": "",
  121. "dimension": "",
  122. "contactor": "",
  123. "mobile": 0,
  124. },
  125. // 站点多选下拉
  126. siteItemDataOrigin: [],
  127. selectedData: [],
  128. phoneData:[],
  129. siteItemData: [],
  130. selectedArr: [],
  131. selectedString: '',
  132. radioOne: 2,
  133. }
  134. },
  135. mounted() {
  136. document.addEventListener('click', (e) => {
  137. if (e.target.className != 'uni-input-input') {
  138. this.isShow = false;
  139. }
  140. });
  141. },
  142. onLoad: function(option) {
  143. this.phone = option.phone;
  144. if (option.phone) {
  145. uni.setNavigationBarTitle({
  146. title: '权限修改'
  147. });
  148. this.getAuthority({"phone":this.phone})
  149. } else {
  150. uni.setNavigationBarTitle({
  151. title: '权限新增'
  152. });
  153. }
  154. this.getSiteList();
  155. this.getphoneList();
  156. this.siteItemData = this.getNotSelectItem();
  157. },
  158. methods: {
  159. unique(arr){
  160. // alert(1)
  161. for(var i=0; i<arr.length; i++){
  162. for(var j=i+1; j<arr.length; j++){
  163. if(arr[i]==arr[j]){ //第一个等同于第二个,splice方法删除第二个
  164. arr.splice(j,1);
  165. j--;
  166. }
  167. }
  168. }
  169. return arr;
  170. },
  171. //修改提交
  172. editSbuimt(){
  173. this.selectedArr = [];
  174. this.selectedData.forEach(item => {
  175. this.selectedArr.push(item.id)
  176. })
  177. //修改验证
  178. if (!this.selectedData.length) {
  179. uni.showToast({
  180. title: "请选择站点",
  181. icon: "none"
  182. });
  183. return
  184. }
  185. this.selectedString = this.selectedArr.toString();
  186. this.setEditAuthority({
  187. "phone": this.authorityData.phone,
  188. "siteId": this.selectedString,
  189. "permissionLabel": this.radioOne
  190. })
  191. },
  192. // 修改请求
  193. async setEditAuthority(params={}) {
  194. const res = await this.$myRequest({
  195. url: 'AuthorityManagement/setEditAuthority',
  196. data:params
  197. })
  198. if (!res.data.flag) {
  199. uni.showToast({
  200. title: "添加失败",
  201. icon: "none"
  202. });
  203. } else {
  204. uni.showToast({
  205. title: "添加成功",
  206. });
  207. }
  208. setTimeout(() => {
  209. uni.navigateTo({
  210. url: '/pages/authManage/authManage',
  211. });
  212. }, 1000);
  213. },
  214. // 回显信息请求
  215. async getAuthority(params={}) {
  216. const res = await this.$myRequest({
  217. url: 'AuthorityManagement/getAuthority',
  218. data:params
  219. })
  220. this.authorityData=res.data.data[0]
  221. this.selectedData=res.data.data[0].siteIdData;
  222. },
  223. radioChange(e) {
  224. console.log('type:' + e.detail.value);
  225. this.radioOne = e.detail.value;
  226. },
  227. //新增提交
  228. async addSubmit() {
  229. this.selectedArr = [];
  230. this.selectedData.forEach(item => {
  231. this.selectedArr.push(item.id)
  232. })
  233. this.selectedString = this.selectedArr.toString();
  234. //提交验证
  235. if (!this.formMess.mobile) {
  236. uni.showToast({
  237. title: "请选择用户",
  238. icon: "none"
  239. });
  240. return
  241. }
  242. if (!this.selectedData.length) {
  243. uni.showToast({
  244. title: "请选择站点",
  245. icon: "none"
  246. });
  247. return
  248. }
  249. let res = await this.addAuthority({
  250. "phone": this.formMess.mobile,
  251. "siteId": this.selectedString,
  252. "permissionLabel": this.radioOne
  253. })
  254. if (!res.data.flag) {
  255. uni.showToast({
  256. title: "添加失败",
  257. icon: "none"
  258. });
  259. } else {
  260. uni.showToast({
  261. title: "添加成功",
  262. });
  263. }
  264. setTimeout(() => {
  265. uni.navigateTo({
  266. url: '/pages/authManage/authManage',
  267. });
  268. }, 1000);
  269. },
  270. //电话号码下拉请求数据
  271. async getphoneList() {
  272. const res = await this.$myRequest({
  273. url: 'AuthorityManagement/getPhoneList',
  274. })
  275. this.phoneData = res.data.data;
  276. console.log(this.phoneData)
  277. },
  278. //站点下拉请求数据
  279. async getSiteList() {
  280. const res = await this.$myRequest({
  281. url: 'SiteManagement/getSiteList',
  282. })
  283. this.siteItemData = res.data.data;
  284. this.siteItemDataOrigin = res.data.data;
  285. this.siteItemData = this.getNotSelectItem();
  286. },
  287. addAuthority(params = {}) {
  288. return this.$myRequest({
  289. url: 'AuthorityManagement/setaddAuthority',
  290. data: params
  291. })
  292. },
  293. add: function(item, index) {
  294. this.selectedData.push(item);
  295. this.isShow = false;
  296. this.formMess.siteName = '';
  297. this.authorityData.siteName = '';
  298. this.siteItemData.splice(index, 1);
  299. this.unique(this.siteItemData)
  300. },
  301. deleteItem: function(item, index) {
  302. this.selectedData.splice(index, 1);
  303. this.siteItemDataOrigin.push(item);
  304. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  305. this.siteItemData = this.getNotSelectItem();
  306. this.siteItemData = this.siteItemData.filter(item => item.siteName.indexOf(this.formMess.siteName) > -1);
  307. this.unique(this.siteItemData)
  308. },
  309. // 站点多选下拉
  310. test: function() {
  311. this.isShow = !this.isShow;
  312. },
  313. test2: function() {
  314. this.isShow = false;
  315. },
  316. //权限新增下拉筛选
  317. handleInput() {
  318. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  319. this.siteItemData = this.getNotSelectItem();
  320. this.siteItemData = this.siteItemData.filter(item => item.siteName.indexOf(this.formMess.siteName) > -1);
  321. this.unique(this.siteItemData)
  322. },
  323. //权限修改下拉筛选
  324. handleInputEdit() {
  325. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  326. this.siteItemData = this.getNotSelectItem();
  327. this.siteItemData = this.siteItemData.filter(item => item.siteName.indexOf(this.authorityData.siteName) > -1);
  328. this.unique(this.siteItemData)
  329. },
  330. // 站点多选下拉 end
  331. getNotSelectItem() {
  332. let ok1 = this.siteItemDataOrigin;
  333. let ok2 = this.selectedData;
  334. if (ok2.length) {
  335. for (let i = 0; i < ok2.length; i++) {
  336. for (let j = 0; j < ok1.length; j++) {
  337. if (ok1[j].id == ok2[i].id) { //值已经被选中
  338. ok1.splice(j, 1);
  339. }
  340. }
  341. }
  342. }
  343. return ok1;
  344. },
  345. formSubmit: function(e) {
  346. console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value))
  347. //定义表单规则
  348. var rule = [{
  349. name: "userName",
  350. checkType: "string",
  351. checkRule: "1,3",
  352. errorMsg: "姓名应为1-3个字符..."
  353. },
  354. // {name:"gender", checkType : "in", checkRule:"男,女", errorMsg:"请选择性别"},
  355. // {name:"loves", checkType : "notnull", checkRule:"", errorMsg:"请选择爱好"}
  356. ];
  357. //进行表单检查
  358. var formData = e.detail.value;
  359. var checkRes = graceChecker.check(formData, rule);
  360. if (checkRes) {
  361. uni.showToast({
  362. title: "验证通过!",
  363. icon: "none"
  364. });
  365. } else {
  366. uni.showToast({
  367. title: graceChecker.error,
  368. icon: "none"
  369. });
  370. }
  371. },
  372. formReset: function(e) {
  373. console.log('清空数据')
  374. },
  375. focusfns: function(e) {
  376. // this.getNotSelectItem();
  377. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  378. this.siteItemData = this.getNotSelectItem();
  379. this.siteItemData = this.siteItemData.filter(item => item.siteName.indexOf(this.formMess.siteName) > -1);
  380. this.unique(this.siteItemData)
  381. },
  382. }
  383. }
  384. </script>
  385. <style lang="scss">
  386. page {
  387. height: 100% !important
  388. }
  389. .cu-form-group {
  390. border-top: 0;
  391. }
  392. input,
  393. select,
  394. option {
  395. line-height: 70rpx;
  396. padding: 0 20rpx;
  397. height: 70rpx;
  398. border: 1px solid #EDEDED;
  399. // width:500rpx!important;
  400. background-color: #fff;
  401. box-sizing: border-box;
  402. appearance: none;
  403. -moz-appearance: none;
  404. -webkit-appearance: none;
  405. color: #999;
  406. }
  407. select:focus,
  408. select:active,
  409. select:hover {
  410. outline: none;
  411. }
  412. select {
  413. background: url(../../static/arrow.png) no-repeat scroll 98% center;
  414. background-size: 6%;
  415. }
  416. .form-item label text {
  417. position: relative;
  418. top: 2rpx
  419. }
  420. .form-item {
  421. padding: 0 40rpx;
  422. display: flex;
  423. align-items: top;
  424. margin-bottom: 20rpx;
  425. .title {
  426. width: 170rpx;
  427. position: relative;
  428. .necessary {
  429. color: red;
  430. display: inline-block;
  431. position: absolute;
  432. top: -2rpx;
  433. left: -20rpx;
  434. font-size: 40rpx;
  435. }
  436. }
  437. input,
  438. select {
  439. width: 500rpx;
  440. font-size: 28rpx;
  441. }
  442. }
  443. /* 站点多选下拉样式 start */
  444. .layui-btn {
  445. background-color: #5fb878;
  446. }
  447. a {
  448. text-decoration: none;
  449. }
  450. .label {
  451. padding: 2px 0px;
  452. background: #aaa;
  453. border-radius: 2px;
  454. color: #fff;
  455. display: block;
  456. line-height: 20px;
  457. height: 20px;
  458. margin: 2px 5px 2px 0;
  459. float: left;
  460. }
  461. .label span {
  462. padding: 0 5px;
  463. color: #fff;
  464. }
  465. .close {
  466. padding: 1px 5px !important;
  467. }
  468. .close:hover {
  469. /* background-color: #009E94;
  470. border-radius: 2px;
  471. color: tomato; */
  472. }
  473. .selectId input {
  474. width: 100% !important;
  475. }
  476. .selectId input {
  477. height: 25px;
  478. padding: 1px 5px;
  479. border-radius: 3px;
  480. width: calc(100% - 12px);
  481. outline-color: #5fb878;
  482. border: 1px solid #5fb878;
  483. }
  484. .selectId {
  485. position: relative;
  486. }
  487. .selectId dl {
  488. border: 1px solid #eee;
  489. border-radius: 3px;
  490. margin: 2px 0px;
  491. max-height: 300px;
  492. overflow-x: hidden;
  493. white-space: nowrap;
  494. position: absolute;
  495. width: 100%;
  496. top: 40px;
  497. background: #fff;
  498. z-index: 1000
  499. }
  500. .selectId dl dd {
  501. margin: 0;
  502. padding: 5px 10px;
  503. }
  504. .selectId dl dd:hover {
  505. background-color: #5FB878;
  506. color: white;
  507. }
  508. .AD {
  509. /* width: 210px;
  510. margin-left: 40px; */
  511. overflow-y: auto;
  512. max-height: 200px;
  513. /* border: 2px solid #5fb878;
  514. border-radius: 6px;
  515. padding: 1px 2px; */
  516. }
  517. form .AD span {
  518. width: auto;
  519. }
  520. .siteSelect {
  521. width: 71%;
  522. display: inline-block;
  523. }
  524. .selectedBox .cu-btn{
  525. padding: 6rpx 20rpx;
  526. font-size: 22rpx;
  527. height: auto;
  528. line-height: 36rpx;
  529. text-align: left;
  530. }
  531. /* 站点多选下拉样式end */
  532. </style>