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