authAdd.vue 14 KB

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