add.vue 11 KB

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