authAdd.vue 13 KB

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