openPass.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view style="background-color: #FFFFFF;height: 100vh;">
  3. <!--pages/openPass/openPass.wxml-->
  4. <view class="container edit_wrap" >
  5. <view class="form_group">
  6. <text class="type">选择房间:</text>
  7. <view class="ar_picker " style="background:#fff;border-bottom: 1rpx solid #ddd;" @click="roomSelectShow=true">
  8. <view class="ar_picker_wrap">
  9. <text>{{selectRoomName?selectRoomName:room_list[0].name}}</text>
  10. </view>
  11. </view>
  12. </view>
  13. <view class="form_group" >
  14. <view class="tui-picker-content">
  15. <text class="type">访客类型:</text>
  16. <view class="flex between itemBox">
  17. <view v-for="(item, index) in guestTypeArray" :key="index" :class="guestTypeIndex == index ? 'active':''" @tap="guestTypethis" :data-thisindex="index">
  18. <text>{{item}}</text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="form_group" >
  24. <view class="tui-picker-content">
  25. <text class="type">密码有效时间:</text>
  26. <view class="flex between itemBox">
  27. <view v-for="(item, index) in numArray" :key="index" :class="activeIndex == index ? 'active':''" @tap="activethis" :data-thisindex="index">
  28. <text>{{item}}小时</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="form_group">
  34. <text class="type">有效次数:</text>
  35. <view class="stepper">
  36. <text :class="minusStatus" type="number" @tap="bindMinus">-</text>
  37. <input @input="bindManual" :value="valid_count"></input>
  38. <text @tap="bindPlus">+</text>
  39. </view>
  40. </view>
  41. <!-- <view class="submit_btn">
  42. <button class="ar_btn" @tap="getGuestAuthorize">获取开门密码</button>
  43. </view> -->
  44. <view @tap="getGuestAuthorize" class=" footer-fixed" >
  45. <view class="cu-btn flex text-lg bg-red-btn" style="padding: 46rpx 0;">
  46. 获取开门密码
  47. </view>
  48. </view>
  49. </view>
  50. <!--弹窗-->
  51. <view class="modal-mask" @tap="closeModal" catchtouchmove="preventTouchMove" v-if="showModal"></view>
  52. <!-- -->
  53. <view class="modal-dialog" v-if="showModal">
  54. <view class="modal-title">开门密码</view>
  55. <view class="modal-content">
  56. <view class="modal-input">
  57. <text class="password">{{password}}</text>
  58. </view>
  59. </view>
  60. <view class="modal-footer">
  61. <button class="btn-cancel" open-type="share" data-status="cancel">转发</button>
  62. <button class="btn-confirm" @tap="copy" data-status="confirm">复制</button>
  63. </view>
  64. </view>
  65. <u-select z-index="9999999" mode="single-column" value-name="id" label-name="name" v-model="roomSelectShow" :list="room_list" @confirm="roomChange"></u-select>
  66. </view>
  67. </template>
  68. <script>
  69. // 访客授权
  70. //获取app实例
  71. var app = getApp();
  72. var util = require("../../../utils/util.js");
  73. export default {
  74. data() {
  75. return {
  76. roomSelectShow:false,
  77. selectRoomName:'',
  78. selectRoomId:0,
  79. room_list: null,
  80. //有效次数
  81. valid_count: 1,
  82. minusStatus: 'disable',
  83. //获取开门密码
  84. showModal: false,
  85. //开门密码
  86. password: null,
  87. //访客类型
  88. guestTypeIndex: 0,
  89. //默认选中第一个
  90. guestTypeArray: ['朋友', '外卖', '快递', '其他'],
  91. //密码有效期
  92. activeIndex: 0,
  93. //默认选中第一个
  94. numArray: [1, 2, 5, 8, 24, 48],
  95. begin_date: "",
  96. end_date: ""
  97. };
  98. },
  99. components: {},
  100. props: {},
  101. /**
  102. * 监听页面加载
  103. */
  104. onLoad() {
  105. //禁用头部分享
  106. uni.hideShareMenu({});
  107. let room_list = app.globalData.room_list;
  108. console.log(room_list,"**************");
  109. if (room_list) {
  110. this.selectRoomId=room_list[0].id
  111. this.setData({
  112. room_list: room_list
  113. });
  114. } else {
  115. //获取房屋信息
  116. this.geRoomByMemberId();
  117. }
  118. },
  119. onShareAppMessage: function (ops) {
  120. let title = "访客密码:" + this.password + ",有效次数:" + this.valid_count + "次,有效期" + this.begin_date + " 到 " + this.end_date;
  121. return {
  122. title: title,
  123. path: '/pages/myPassword/myPassword?valid_count=' + this.valid_count + "&password=" + this.password + "&end_date=" + this.end_date,
  124. imageUrl: "http://139.9.103.171:1888/img/image/ps_bg.png"
  125. };
  126. },
  127. methods: {
  128. //选择房间
  129. roomChange: function (e) {
  130. this.selectRoomId=e[0].value
  131. this.selectRoomName=e[0].label
  132. },
  133. //事件处理函数
  134. /*点击减号*/
  135. bindMinus: function () {
  136. var valid_count = this.valid_count;
  137. if (valid_count > 1) {
  138. valid_count--;
  139. }
  140. var minusStatus = valid_count > 1 ? 'normal' : 'disable';
  141. this.setData({
  142. valid_count: valid_count,
  143. minusStatus: minusStatus
  144. });
  145. },
  146. /*点击加号*/
  147. bindPlus: function () {
  148. var valid_count = this.valid_count;
  149. if (valid_count >= 10) {
  150. uni.showToast({
  151. title: '密码最大次数不能超过10次',
  152. icon: 'none',
  153. duration: 2000
  154. });
  155. } else {
  156. valid_count++;
  157. var minusStatus = valid_count > 1 ? 'normal' : 'disable';
  158. this.setData({
  159. valid_count: valid_count,
  160. minusStatus: minusStatus
  161. });
  162. }
  163. },
  164. /*输入框事件*/
  165. bindManual: function (e) {
  166. var valid_count = e.detail.value;
  167. var minusStatus = valid_count > 1 ? 'normal' : 'disable';
  168. this.setData({
  169. valid_count: valid_count,
  170. minusStatus: minusStatus
  171. });
  172. },
  173. //访客类型
  174. guestTypethis: function (event) {
  175. //点击选中事件
  176. var thisindex = event.currentTarget.dataset.thisindex; //当前index
  177. this.setData({
  178. guestTypeIndex: thisindex
  179. });
  180. },
  181. //密码有效时间
  182. activethis: function (event) {
  183. //点击选中事件
  184. var thisindex = event.currentTarget.dataset.thisindex; //当前index
  185. this.setData({
  186. activeIndex: thisindex
  187. });
  188. },
  189. //复制密码
  190. copy: function (e) {
  191. var that = this; //获取app.js里面定义的全局变量
  192. if (uni.setClipboardData) {
  193. //微信版本兼容处理
  194. let title = "访客密码:" + this.password + ",有效次数:" + this.valid_count + "次,有效期" + this.begin_date + " 到 " + this.end_date;
  195. uni.setClipboardData({
  196. data: title,
  197. success(res) {
  198. uni.getClipboardData({
  199. success(res) {
  200. that.closeModal()
  201. }
  202. });
  203. }
  204. });
  205. } else {//用户微信版本过低,不支持使用该功能
  206. }
  207. },
  208. //关闭弹窗
  209. closeModal: function () {
  210. this.setData({
  211. showModal: false
  212. });
  213. },
  214. //获取开门密码
  215. getGuestAuthorize: function () {
  216. let that = this;
  217. let params = {};
  218. params['member_id'] = app.globalData.member.id;
  219. params['room_id'] = that.selectRoomId;
  220. params['guest_type'] = that.guestTypeIndex;
  221. params['valid_count'] = that.valid_count; //选择有效时间数字
  222. let avalid_num = that.numArray[that.activeIndex]; //有效开始时间
  223. let begin_date = new Date(); //提前30分钟
  224. begin_date.setMinutes(begin_date.getMinutes() - 30);
  225. params['begin_date'] = util.getTimestamp(begin_date); //有效结束时间
  226. let end_date = new Date(); //小时累加
  227. end_date.setHours(end_date.getHours() + avalid_num);
  228. params['end_date'] = util.getTimestamp(end_date); //有效次数
  229. params['valid_count'] = that.valid_count;
  230. console.log(that.params);
  231. let operation = 'guestAuthorize/getGuestAuthorize';
  232. app.globalData.postRequest(params, operation, function (res) {
  233. console.info("接口返回结果:" + res.data.result_msg); //获取成功
  234. if (res.data.result_code == 1) {
  235. uni.setStorageSync("isFlush", true);
  236. that.setData({
  237. //显示复制密码弹窗
  238. showModal: true,
  239. password: res.data.guestAuthorize.password,
  240. begin_date: util.formatTime(res.data.guestAuthorize.beginDate),
  241. end_date: util.formatTime(res.data.guestAuthorize.endDate)
  242. });
  243. } else {
  244. app.globalData.oneFailHint(res.data.result_msg);
  245. }
  246. });
  247. },
  248. //根据会员id获取我的房屋列表
  249. geRoomByMemberId: function () {
  250. let that = this;
  251. let params = {};
  252. params['member_id'] = app.globalData.member.id;
  253. ;
  254. let operation = 'estate/getRoomByMemberId';
  255. app.globalData.postRequest(params, operation, function (res) {
  256. console.info("获取成功" + res.data.result_msg); //获取成功
  257. if (res.data.result_code == 1) {
  258. that.setData({
  259. room_list: res.data.list
  260. });
  261. that.selectRoomId=that.room_list[0].id
  262. app.globalData.room_list = res.data.list;
  263. }
  264. });
  265. }
  266. }
  267. };
  268. </script>
  269. <style lang="scss">
  270. /* pages/openPass/openPass.wxss */
  271. .edit_wrap {
  272. font-size: 30rpx;
  273. color: #333;
  274. }
  275. .form_group {
  276. margin:0 20rpx;
  277. line-height: 60rpx;
  278. background: #fff;
  279. border-radius: 10rpx;
  280. padding: 20rpx;
  281. }
  282. .form_group input, .form_group picker {
  283. width: 100%;
  284. border-bottom: 1px solid #ddd;
  285. color: $base-btn-color;
  286. height: 60rpx;
  287. line-height: 60rpx;
  288. padding: 0rpx 20rpx;
  289. }
  290. .ar_picker_wrap picker {
  291. width: 100%;
  292. box-sizing: border-box;
  293. }
  294. .tui-picker-content picker {
  295. width: 260rpx;
  296. display: inline-block;
  297. padding: 0 10rpx;
  298. }
  299. .tui-picker-content .time_text {
  300. margin: 0 20rpx;
  301. }
  302. /*主容器*/
  303. .stepper {
  304. width: 214rpx;
  305. height: 60rpx;
  306. border: 2rpx solid #ddd;
  307. border-radius: 10rpx;
  308. background: #fff;
  309. margin-top: 10rpx;
  310. }
  311. /*加号和减号*/
  312. .stepper text {
  313. float: left;
  314. width: 70rpx;
  315. line-height: 52rpx;
  316. text-align: center;
  317. }
  318. /*数值*/
  319. .stepper input {
  320. width: 70rpx;
  321. height: 60rpx;
  322. float: left;
  323. margin: 0 auto;
  324. text-align: center;
  325. font-size: 12px;
  326. border: none;
  327. border-left: 1px solid #ddd;
  328. border-right: 1px solid #ddd;
  329. padding: 0;
  330. border-radius: 0;
  331. color: $base-btn-color;
  332. }
  333. /*普通样式*/
  334. .stepper .normal {
  335. color: black;
  336. }
  337. /*禁用样式*/
  338. .stepper .disable {
  339. color: #ccc;
  340. }
  341. .get_code {
  342. padding: 0rpx 60rpx;
  343. position: fixed;
  344. bottom: 20rpx;
  345. width: 100%;
  346. box-sizing: border-box;
  347. }
  348. .ar_book {
  349. background: $base-btn-color;
  350. font-size: 28rpx;
  351. color: #fff;
  352. border-radius: 10rpx;
  353. margin: 40rpx 0rpx 10rpx;
  354. padding: 0rpx 60rpx;
  355. }
  356. .show-btn {
  357. margin-top: 100rpx;
  358. color: #2c2;
  359. }
  360. .modal-mask {
  361. width: 100%;
  362. height: 100%;
  363. position: fixed;
  364. top: 0;
  365. left: 0;
  366. background: #000;
  367. opacity: 0.5;
  368. overflow: hidden;
  369. z-index: 9000;
  370. color: #fff;
  371. }
  372. .modal-dialog {
  373. width: 540rpx;
  374. overflow: hidden;
  375. position: fixed;
  376. top: 50%;
  377. left: 0;
  378. z-index: 9999;
  379. background: #f9f9f9;
  380. margin: -180rpx 105rpx;
  381. border-radius: 36rpx;
  382. }
  383. .modal-title {
  384. padding-top: 50rpx;
  385. font-size: 36rpx;
  386. color: #030303;
  387. text-align: center;
  388. }
  389. .modal-content {
  390. padding: 50rpx 32rpx;
  391. }
  392. .modal-input {
  393. display: flex;
  394. font-size: 40rpx;
  395. }
  396. .password {
  397. width: 100%;
  398. height: 80rpx;
  399. font-size: 40rpx;
  400. line-height: 80rpx;
  401. padding: 0 20rpx;
  402. box-sizing: border-box;
  403. color: #ec5300;
  404. text-align: center;
  405. }
  406. input-holder {
  407. color: #666;
  408. font-size: 28rpx;
  409. }
  410. .modal-footer {
  411. display: flex;
  412. flex-direction: row;
  413. height: 86rpx;
  414. border-top: 1px solid #dedede;
  415. font-size: 34rpx;
  416. line-height: 86rpx;
  417. }
  418. .modal-footer button::after{
  419. border: none;
  420. }
  421. .modal-footer .btn-cancel {
  422. width: 50%;
  423. color: #666;
  424. text-align: center;
  425. border-right: 1px solid #dedede;
  426. border-radius: 0;
  427. }
  428. .modal-footer .btn-confirm {
  429. width: 50%;
  430. color: #ec5300;
  431. text-align: center;
  432. }
  433. /* 密码有效期 */
  434. .itemBox {
  435. flex-flow: wrap;
  436. }
  437. .itemBox view {
  438. width: 30%;
  439. box-sizing: border-box;
  440. margin: 10rpx;
  441. }
  442. .itemBox view.active text{
  443. background: $base-btn-color;
  444. color: #fff;
  445. }
  446. .itemBox view text {
  447. text-align: center;
  448. width: 100%;
  449. background: #fff;
  450. color: $base-btn-color;
  451. font-size: 28rpx;
  452. display: inline-block;
  453. border: 2rpx solid $base-btn-color;
  454. border-radius: 40rpx;
  455. }
  456. </style>