add.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <view class="appWrapper">
  3. <form action="" v-if="type==1" @submit="formSubmit">
  4. <view class="form-item margin-top">
  5. <view class="title">
  6. <text class="necessary">*</text>
  7. 用户名称:
  8. </view>
  9. <input name="userName" v-model="formMess.userName"></input>
  10. </view>
  11. <view class="form-item">
  12. <view class="title">地址:</view>
  13. <input name="input" v-model="formMess.place"></input>
  14. </view>
  15. <view class="form-item">
  16. <view class="title">经度:</view>
  17. <input name="input" v-model="formMess.longitude"></input>
  18. </view>
  19. <view class="form-item">
  20. <view class="title">维度:</view>
  21. <input name="input" v-model="formMess.dimension"></input>
  22. </view>
  23. <view class="form-item">
  24. <view class="title">联系人:</view>
  25. <input name="input" v-model="formMess.contactor"></input>
  26. </view>
  27. <view class="form-item">
  28. <view class="title">手机号码:</view>
  29. <input name="input" v-model="formMess.mobile"></input>
  30. </view>
  31. <view class="btn-area submitBottomBtn padding-lr-sm">
  32. <button class="bg-blue round margin-top" form-type="submit">提 交 </button>
  33. </view>
  34. </form>
  35. <form action="" v-else-if="type==2">
  36. <view class="form-item margin-top">
  37. <view class="title">
  38. <text class="necessary">*</text>
  39. 设备编号:
  40. </view>
  41. <input name="input" v-model="formMess.deviceNo"></input>
  42. </view>
  43. <view class="form-item">
  44. <view class="title">设备名称:</view>
  45. <input name="input" v-model="formMess.deviceName"></input>
  46. </view>
  47. <view class="form-item">
  48. <view class="title">安装位置:</view>
  49. <input name="input" v-model="formMess.place"></input>
  50. </view>
  51. <view class="form-item">
  52. <view class="title">所属楼层:</view>
  53. <select name="" id="">
  54. <option value="">楼层一</option>
  55. <option value="">楼层一</option>
  56. <option value="">楼层一</option>
  57. </select>
  58. </view>
  59. <view class="form-item">
  60. <view class="title">站点:</view>
  61. <select name="" id="">
  62. <option value="">站点一</option>
  63. <option value="">站点一</option>
  64. <option value="">站点一</option>
  65. </select>
  66. </view>
  67. <view class="form-item">
  68. <view class="title">设备类型:</view>
  69. <select name="" id="">
  70. <option value="">智慧用电</option>
  71. <option value="">视频监控</option>
  72. </select>
  73. </view>
  74. <view class="btn-area submitBottomBtn padding-lr-sm">
  75. <button class="bg-blue round margin-top">提 交 </button>
  76. </view>
  77. </form>
  78. <!-- 权限管理 start -->
  79. <form action="" v-else>
  80. <view class="form-item margin-top">
  81. <view class="title">
  82. <text class="necessary">*</text>
  83. 角色名称
  84. </view>
  85. <input name="userName" v-model="formMess.userName"></input>
  86. </view>
  87. <view class="form-item">
  88. <view class="title " style="vertical-align:top">
  89. <text class="necessary">*</text>
  90. 站点:
  91. </view>
  92. <view style="position:relative" class="innerZd">
  93. <input name="siteName" v-model="formMess.siteName" @click="test" @focus="focusfns" @input="handleInput()" placeholder="请选择"></input>
  94. <view class="siteItems" v-if="isShow">
  95. <view class=" site-item" v-if="!siteItemData.length">暂无结果</view>
  96. <view class="site-item" v-for="(item,index) in siteItemData" @click="add(item,index)" :key="index">{{item}}</view>
  97. </view>
  98. <view style="width:500rpx" class="selectedBox">
  99. <button class="cu-btn sm margin-xs" v-for="(item,index) in selectedData" @click="deleteItem(item,index)">
  100. {{item}}
  101. <text class="lg text-gray cuIcon-close"></text>
  102. </button>
  103. </view>
  104. </view>
  105. </view>
  106. <view class="form-item margin-top">
  107. <view class="title">
  108. <text class="necessary">*</text>
  109. 告警类型
  110. </view>
  111. <radio-group name="gender">
  112. <label class="margin-right">
  113. <radio value="全部告警" checked /><text>全部告警</text>
  114. </label>
  115. <label>
  116. <radio value="维保告警" /><text>维保告警</text>
  117. </label>
  118. </radio-group>
  119. </view>
  120. <view class="btn-area submitBottomBtn padding-lr-sm">
  121. <button class="bg-blue round margin-top" form-type="submit">提 交 </button>
  122. </view>
  123. </form>
  124. <!-- 权限管理 end -->
  125. </view>
  126. </template>
  127. <script>
  128. // var graceChecker = require("../../common/graceChecker.js");
  129. // import add from '../../common/select.js';
  130. export default {
  131. data() {
  132. return {
  133. index: -1,
  134. picker: ['楼层一', '楼层二', '楼层三'],
  135. type: '0',
  136. isShow: false,
  137. formMess: {
  138. "userName": "sss",
  139. "siteName": "",
  140. "place": "",
  141. "longitude": "",
  142. "dimension": "",
  143. "contactor": "",
  144. "mobile": "",
  145. },
  146. // 站点多选下拉
  147. siteItemDataOrigin: ["站点一", "站点二", "站点三", "站点四", "站点五", "站点六"],
  148. // newDataList: [],
  149. selectedData: [],
  150. siteItemData: ["站点一", "站点二", "站点三", "站点四", "站点五", "站点六"],
  151. }
  152. },
  153. onLoad: function(option) {
  154. console.log(option.type); //打印出上个页面传递的参数。
  155. this.type = option.type;
  156. if (option.type == 1) {
  157. uni.setNavigationBarTitle({
  158. title: '站点新增'
  159. });
  160. } else if (option.type == 2) {
  161. uni.setNavigationBarTitle({
  162. title: '设备新增'
  163. });
  164. } else {
  165. uni.setNavigationBarTitle({
  166. title: '权限新增'
  167. });
  168. }
  169. },
  170. mounted() {
  171. document.addEventListener('click', (e) => {
  172. if (e.target.className != 'uni-input-input') {
  173. this.isShow = false;
  174. }
  175. });
  176. },
  177. methods: {
  178. add: function(item, index) {
  179. this.selectedData.push(item);
  180. this.isShow = false;
  181. this.formMess.siteName=''
  182. this.siteItemData.splice(index, 1);
  183. },
  184. deleteItem: function(item, index) {
  185. // this.selectedData.remove(item);
  186. this.selectedData.splice(index, 1);
  187. this.siteItemDataOrigin.push(item);
  188. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  189. this.siteItemData = this.getNotSelectItem();
  190. this.siteItemData = this.siteItemData.filter(item => item.indexOf(this.formMess.siteName) > -1);
  191. // console.log('这是过滤来的');
  192. // console.log(this.siteItemData);
  193. // this.selectedData = newlist;
  194. // console.log(this.selectedData)
  195. },
  196. // 站点多选下拉
  197. test: function() {
  198. this.isShow = !this.isShow;
  199. },
  200. test2: function() {
  201. this.isShow = false;
  202. },
  203. handleInput() {
  204. // this.getNotSelectItem();
  205. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  206. this.siteItemData = this.getNotSelectItem();
  207. this.siteItemData = this.siteItemData.filter(item => item.indexOf(this.formMess.siteName) > -1);
  208. // this.selectedData = newlist;
  209. // console.log(this.selectedData)
  210. },
  211. // 站点多选下拉 end
  212. getNotSelectItem(){
  213. let ok1 = this.siteItemDataOrigin;
  214. let ok2 = this.selectedData;
  215. // console.log('选中值',ok2);
  216. // console.log('全部值',ok1);
  217. if(ok2.length){
  218. for(let i = 0; i < ok2.length; i++){
  219. for(let j = 0; j < ok1.length; j++){
  220. if(ok1[j] === ok2[i]){//值已经被选中
  221. ok1.splice(j, 1);
  222. }
  223. }
  224. }
  225. }
  226. return ok1;
  227. },
  228. formSubmit: function(e) {
  229. console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value))
  230. //定义表单规则
  231. var rule = [{
  232. name: "userName",
  233. checkType: "string",
  234. checkRule: "1,3",
  235. errorMsg: "姓名应为1-3个字符..."
  236. },
  237. // {name:"gender", checkType : "in", checkRule:"男,女", errorMsg:"请选择性别"},
  238. // {name:"loves", checkType : "notnull", checkRule:"", errorMsg:"请选择爱好"}
  239. ];
  240. //进行表单检查
  241. var formData = e.detail.value;
  242. var checkRes = graceChecker.check(formData, rule);
  243. if (checkRes) {
  244. uni.showToast({
  245. title: "验证通过!",
  246. icon: "none"
  247. });
  248. } else {
  249. uni.showToast({
  250. title: graceChecker.error,
  251. icon: "none"
  252. });
  253. }
  254. },
  255. formReset: function(e) {
  256. console.log('清空数据')
  257. },
  258. focusfns:function(e){
  259. // this.getNotSelectItem();
  260. //将元素根据搜索内容过滤出来 这里改变了siteItemData
  261. this.siteItemData = this.getNotSelectItem();
  262. this.siteItemData = this.siteItemData.filter(item => item.indexOf(this.formMess.siteName) > -1);
  263. },
  264. }
  265. }
  266. </script>
  267. <style lang="scss">
  268. .cu-form-group {
  269. border-top: 0;
  270. }
  271. input,
  272. select,
  273. option {
  274. line-height: 70rpx;
  275. padding: 0 20rpx;
  276. height: 70rpx;
  277. border: 1px solid #EDEDED;
  278. // width:500rpx!important;
  279. background-color: #fff;
  280. box-sizing: border-box;
  281. appearance: none;
  282. -moz-appearance: none;
  283. -webkit-appearance: none;
  284. color: #999;
  285. }
  286. select:focus,
  287. select:active,
  288. select:hover {
  289. outline: none;
  290. }
  291. select {
  292. background: url(../../static/arrow.png) no-repeat scroll 98% center;
  293. background-size: 6%;
  294. }
  295. .form-item label text {
  296. position: relative;
  297. top: 2rpx
  298. }
  299. .form-item {
  300. padding: 0 40rpx;
  301. display: flex;
  302. align-items: top;
  303. margin-bottom: 20rpx;
  304. .title {
  305. width: 170rpx;
  306. position: relative;
  307. .necessary {
  308. color: red;
  309. display: inline-block;
  310. position: absolute;
  311. top: -2rpx;
  312. left: -20rpx;
  313. font-size: 40rpx;
  314. }
  315. }
  316. input,
  317. select {
  318. width: 500rpx;
  319. font-size: 28rpx;
  320. }
  321. }
  322. /* 站点多选下拉样式 start */
  323. .layui-btn {
  324. background-color: #5fb878;
  325. }
  326. a {
  327. text-decoration: none;
  328. }
  329. .label {
  330. padding: 2px 0px;
  331. background: #aaa;
  332. border-radius: 2px;
  333. color: #fff;
  334. display: block;
  335. line-height: 20px;
  336. height: 20px;
  337. margin: 2px 5px 2px 0;
  338. float: left;
  339. }
  340. .label span {
  341. padding: 0 5px;
  342. color: #fff;
  343. }
  344. .close {
  345. padding: 1px 5px !important;
  346. }
  347. .close:hover {
  348. /* background-color: #009E94;
  349. border-radius: 2px;
  350. color: tomato; */
  351. }
  352. .selectId input {
  353. width: 100% !important;
  354. }
  355. .selectId input {
  356. height: 25px;
  357. padding: 1px 5px;
  358. border-radius: 3px;
  359. width: calc(100% - 12px);
  360. outline-color: #5fb878;
  361. border: 1px solid #5fb878;
  362. }
  363. .selectId {
  364. position: relative;
  365. }
  366. .selectId dl {
  367. border: 1px solid #eee;
  368. border-radius: 3px;
  369. margin: 2px 0px;
  370. max-height: 300px;
  371. overflow-x: hidden;
  372. white-space: nowrap;
  373. position: absolute;
  374. width: 100%;
  375. top: 40px;
  376. background: #fff;
  377. z-index: 1000
  378. }
  379. .selectId dl dd {
  380. margin: 0;
  381. padding: 5px 10px;
  382. }
  383. .selectId dl dd:hover {
  384. background-color: #5FB878;
  385. color: white;
  386. }
  387. .AD {
  388. /* width: 210px;
  389. margin-left: 40px; */
  390. overflow-y: auto;
  391. max-height: 200px;
  392. /* border: 2px solid #5fb878;
  393. border-radius: 6px;
  394. padding: 1px 2px; */
  395. }
  396. form .AD span {
  397. width: auto;
  398. }
  399. .siteSelect {
  400. width: 71%;
  401. display: inline-block;
  402. }
  403. /* 站点多选下拉样式end */
  404. </style>