authAdd.vue 14 KB

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