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