with_house.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="tel flex">
  5. <label>小区名称:</label>
  6. <view class="picker">
  7. <!-- <picker
  8. @change="hoodChange"
  9. :value="hoodIndex"
  10. :range="hoodList"
  11. range-key="name"
  12. class="pick"
  13. >
  14. <view class="picker_title">
  15. <view class="pickername">
  16. <view>
  17. {{ hoodList[hoodIndex].name || '请选择小区'}}
  18. </view>
  19. </view>
  20. <view class="triangle-down"></view>
  21. </view>
  22. </picker> -->
  23. <jPicker class="cont" position="top" @sure="hoodChange" showKey="name" valKey="name"
  24. :val="hoodList.name" :options="hoodList" />
  25. </view>
  26. </view>
  27. <view class="tel flex" style="margin-top:30rpx;">
  28. <label style="text-align: center;">楼栋:</label>
  29. <view class="picker">
  30. <picker
  31. @change="buildingChange"
  32. :value="buildIndex"
  33. :range="buildList"
  34. range-key="name"
  35. class="pick"
  36. >
  37. <view class="picker_title">
  38. <view class="pickername">
  39. <view>
  40. {{ buildList[buildIndex].name || '请选择楼栋'}}
  41. </view>
  42. </view>
  43. <view class="triangle-down"></view>
  44. </view>
  45. </picker>
  46. </view>
  47. </view>
  48. <view class="tel flex">
  49. <label style="text-align: center;">单元:</label>
  50. <view class="picker">
  51. <picker
  52. @change="unitChange"
  53. :value="unitIndex"
  54. :range="unitList"
  55. range-key="name"
  56. class="pick"
  57. >
  58. <view class="picker_title">
  59. <view class="pickername">
  60. <view>
  61. {{ unitList[unitIndex].name || '请选择单元'}}
  62. </view>
  63. </view>
  64. <view class="triangle-down"></view>
  65. </view>
  66. </picker>
  67. </view>
  68. </view>
  69. <view class="tel flex">
  70. <label style="text-align: center;">房号:</label>
  71. <view class="picker">
  72. <picker
  73. @change="numChange"
  74. :value="numIndex"
  75. :range="numList"
  76. range-key="name"
  77. class="pick"
  78. >
  79. <view class="picker_title">
  80. <view class="pickername">
  81. <view>
  82. {{ numList[numIndex].name || '请选择房号'}}
  83. </view>
  84. </view>
  85. <view class="triangle-down"></view>
  86. </view>
  87. </picker>
  88. </view>
  89. </view>
  90. <view class="tel flex" style="margin-top: 100rpx;">
  91. <label>户主姓名:</label>
  92. <input type="text" class="card input" v-model="house.master" disabled/>
  93. </view>
  94. <view class="tel flex">
  95. <label>住宅面积:</label>
  96. <input type="text" class="card input" v-model="house.area" disabled/>
  97. </view>
  98. </view>
  99. <button class="submit" @tap="houseSubmit">提交</button>
  100. <uni-popup ref="popup" :mask-click="false">
  101. <view class="popup-box" style="height: 400rpx;">
  102. <view>
  103. <view class="popup-title">确认</view>
  104. <view class="popup-content-box">
  105. <view class="popup-content">
  106. <view class="popup-type">
  107. 确定关联此住房信息吗?
  108. </view>
  109. </view>
  110. </view>
  111. </view>
  112. <view class="popup-footer">
  113. <button class="popup-cancel" @click="closePop">取消</button>
  114. <button class="popup-submit" @click="submitPop">确定</button>
  115. </view>
  116. </view>
  117. </uni-popup>
  118. </view>
  119. </template>
  120. <script>
  121. import md5 from "@/common/md5.js";
  122. import jPicker from '../../components/J-Picker/jPicker.vue';
  123. export default {
  124. components: {
  125. jPicker
  126. },
  127. data() {
  128. return {
  129. house: {
  130. name: "",
  131. num: "",
  132. master:'',
  133. area:'',
  134. },
  135. hoodList: [],
  136. buildList: [],
  137. unitList: [],
  138. numList: [],
  139. hoodIndex: 0,
  140. hoodName:'',
  141. buildIndex:0,
  142. unitIndex:0,
  143. numIndex:0,
  144. };
  145. },
  146. onLoad() {
  147. },
  148. onShow() {
  149. this.searchHood()
  150. },
  151. methods: {
  152. searchHood(){
  153. let that = this;
  154. this.hoodList = [];
  155. this.hoodIndex = 0;
  156. // let result = e.detail.value;
  157. let md5Sign = md5(
  158. "method=" +
  159. "user" +
  160. "&timestamp=" +
  161. getApp().globalData.globalTimestamp +
  162. "&secret=" +
  163. getApp().globalData.secret
  164. );
  165. let url =
  166. getApp().globalData.shareUrl +
  167. "api/api.php" +
  168. "?method=user&source=user&action=search_estate&timestamp=" +
  169. getApp().globalData.globalTimestamp +
  170. "&sign=" +
  171. md5Sign;
  172. let postData = {
  173. keyword:'',
  174. openId: getApp().globalData.open_id,
  175. };
  176. uni.request({
  177. url: url,
  178. method: "POST",
  179. header: {
  180. "content-type": "application/x-www-form-urlencoded",
  181. },
  182. data: postData,
  183. success: (res) => {
  184. if (res.data.code === 200) {
  185. let obj = res.data.data;
  186. let c = {
  187. name:"请选择小区",
  188. }
  189. this.hoodList.push(c);
  190. for (let key in obj) {
  191. let child = {
  192. name:obj[key]
  193. }
  194. this.hoodList.push(child)
  195. }
  196. }
  197. },
  198. fail: () => {
  199. console.log("连接失败");
  200. },
  201. });
  202. },
  203. searchDetail(hood,build,unit,room){
  204. let that = this, addressResult,searchType;
  205. // let result = e.detail.value;
  206. that.house.master = '';
  207. that.house.area = '';
  208. if (room)
  209. {
  210. if (hood === "请选择小区")
  211. {
  212. return;
  213. }
  214. searchType = 'houseRoom'
  215. addressResult = hood + '/' + build + '/' + unit + '/' + room
  216. }
  217. if(build && unit && !room){
  218. if (build === "请选择房号")
  219. {
  220. return;
  221. }
  222. searchType = 'houseNumber'
  223. addressResult = hood + '/' + build + '/' + unit
  224. }
  225. if(build && !unit){
  226. if (build === "请选择单元")
  227. {
  228. return;
  229. }
  230. searchType = 'houseUnit'
  231. addressResult = hood + '/' + build
  232. }
  233. if(!build && !unit){
  234. if (build === "请选择楼栋")
  235. {
  236. return;
  237. }
  238. searchType = 'houseBuilding'
  239. addressResult = hood
  240. }
  241. let md5Sign = md5(
  242. "method=" +
  243. "user" +
  244. "&timestamp=" +
  245. getApp().globalData.globalTimestamp +
  246. "&secret=" +
  247. getApp().globalData.secret
  248. );
  249. let url =
  250. getApp().globalData.shareUrl +
  251. "api/api.php" +
  252. "?method=user&source=user&action=get_address&timestamp=" +
  253. getApp().globalData.globalTimestamp +
  254. "&sign=" +
  255. md5Sign;
  256. let postData = {
  257. address:addressResult,
  258. openId: getApp().globalData.open_id,
  259. };
  260. uni.request({
  261. url: url,
  262. method: "POST",
  263. header: {
  264. "content-type": "application/x-www-form-urlencoded",
  265. },
  266. data: postData,
  267. success: (res) => {
  268. if (res.data.code === 200) {
  269. if(res.data.data.length === 0){
  270. uni.showToast({
  271. title: "暂无数据",
  272. icon: "error",
  273. });
  274. }else{
  275. that.makeHouseData(searchType,res.data.data)
  276. }
  277. }
  278. },
  279. fail: () => {
  280. console.log("连接失败");
  281. },
  282. });
  283. },
  284. resetLevels(level){
  285. //重置下一层
  286. let that = this;
  287. switch (level){
  288. case 1:
  289. that.buildList = [];
  290. let a = {
  291. name : '请选择楼栋'
  292. };
  293. that.buildList.push(a);
  294. that.buildIndex = 0;
  295. case 2:
  296. that.unitList = [];
  297. let b = {
  298. name : '请选择单元'
  299. };
  300. that.unitList.push(b);
  301. that.unitIndex = 0;
  302. case 3:
  303. that.numList = [];
  304. let c = {
  305. name : '请选择房号'
  306. };
  307. that.numList.push(c);
  308. that.numIndex = 0;
  309. case 4:
  310. that.house.master = '';
  311. that.house.area = '';
  312. }
  313. },
  314. makeHouseData(type,dataList){
  315. let that = this , obj = dataList;
  316. switch (type){
  317. case 'houseBuilding':
  318. this.resetLevels(1);
  319. for (let key in obj) {
  320. let child = {
  321. name:obj[key]
  322. }
  323. that.buildList.push(child)
  324. }
  325. //that.searchDetail(that.hoodName,that.buildList[0].name)
  326. break;
  327. case 'houseUnit':
  328. this.resetLevels(2);
  329. for (let key in obj) {
  330. let child = {
  331. name:obj[key]
  332. }
  333. that.unitList.push(child)
  334. }
  335. //that.searchDetail(that.hoodName,that.buildList[that.buildIndex].name,that.unitList[0].name)
  336. break;
  337. case 'houseNumber':
  338. this.resetLevels(3);
  339. for (let key in obj) {
  340. let child = {
  341. name:obj[key]
  342. }
  343. that.numList.push(child)
  344. }
  345. //that.searchDetail(that.hoodName,that.buildList[that.buildIndex].name,that.unitList[that.unitIndex].name,that.numList[0].name);
  346. break;
  347. case 'houseRoom':
  348. that.house.master = obj.name;
  349. that.house.area = obj.area;
  350. default:
  351. break;
  352. }
  353. },
  354. houseSubmit(){
  355. //uni.navigateBack({});
  356. this.open()
  357. },
  358. hoodChange(e){
  359. console.log("e.pickerVal="+e.pickerVal);
  360. this.hoodName = e.pickerVal;
  361. this.searchDetail(this.hoodName)
  362. },
  363. buildingChange(e) {
  364. if(!this.hoodName){
  365. uni.showToast({
  366. title: "请先选择小区",
  367. icon: "error",
  368. });
  369. return
  370. }
  371. this.buildIndex = e.detail.value;
  372. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name)
  373. },
  374. unitChange(e) {
  375. if(!this.buildList.length){
  376. uni.showToast({
  377. title: "请先选择楼栋",
  378. icon: "error",
  379. });
  380. return
  381. }
  382. this.unitIndex = e.detail.value;
  383. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name,this.unitList[this.unitIndex].name)
  384. },
  385. numChange(e) {
  386. if(!this.unitList.length){
  387. uni.showToast({
  388. title: "请先选择单元",
  389. icon: "error",
  390. });
  391. return
  392. }
  393. this.numIndex = e.detail.value;
  394. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name,this.unitList[this.unitIndex].name,this.numList[this.numIndex].name);
  395. },
  396. submitPop(){
  397. this.closePopup()
  398. this.submit()
  399. },
  400. closePop(){
  401. this.closePopup()
  402. },
  403. open() {
  404. this.$refs.popup.open('center')
  405. },
  406. closePopup() {
  407. this.$refs.popup.close()
  408. },
  409. submit() {
  410. if (
  411. !this.buildList.length ||
  412. !this.unitList.length ||
  413. !this.numList.length
  414. ) {
  415. uni.showToast({
  416. title: "小区信息不完善",
  417. icon: "error",
  418. });
  419. return;
  420. }
  421. let addressResult = this.hoodName + '/' + this.buildList[this.buildIndex].name + '/' + this.unitList[this.unitIndex].name + '/' + this.numList[this.numIndex].name
  422. let md5Sign = md5(
  423. "method=" +
  424. "user" +
  425. "&timestamp=" +
  426. getApp().globalData.globalTimestamp +
  427. "&secret=" +
  428. getApp().globalData.secret
  429. );
  430. let url =
  431. getApp().globalData.shareUrl +
  432. "api/api.php" +
  433. "?method=user&source=user&action=band_owner&timestamp=" +
  434. getApp().globalData.globalTimestamp +
  435. "&sign=" +
  436. md5Sign;
  437. let postData = {
  438. address:addressResult,
  439. openId: getApp().globalData.open_id,
  440. };
  441. uni.request({
  442. url: url,
  443. method: "POST",
  444. header: {
  445. "content-type": "application/x-www-form-urlencoded",
  446. },
  447. data: postData,
  448. success: (res) => {
  449. if (res.data.code === 200) {
  450. uni.showToast({
  451. title: "绑定成功",
  452. icon: "success",
  453. });
  454. setTimeout(function() {
  455. uni.navigateBack({
  456. });
  457. }, 500)
  458. }
  459. },
  460. fail: () => {
  461. console.log("连接失败");
  462. },
  463. });
  464. },
  465. },
  466. };
  467. </script>
  468. <style lang="scss" scoped>
  469. .content {
  470. font-size: 28rpx;
  471. font-weight: 200;
  472. padding: 1% 2%;
  473. .title {
  474. font-size: 30rpx;
  475. margin: 4% 0;
  476. }
  477. label {
  478. display: inline-block;
  479. width: 25%;
  480. vertical-align: middle;
  481. }
  482. .card {
  483. background-color: rgb(248, 247, 247);
  484. border-radius: 10rpx;
  485. }
  486. .flex {
  487. display: flex;
  488. align-items: center;
  489. margin-bottom: 2%;
  490. }
  491. .input {
  492. padding: 0 2%;
  493. margin: 2% 0;
  494. display: inline-block;
  495. width: 80%;
  496. height: 70rpx;
  497. }
  498. .supplyInfo {
  499. border-radius: 40rpx;
  500. padding: 4%;
  501. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  502. margin: 30rpx 0 30rpx 0;
  503. }
  504. .info {
  505. margin-top: 2%;
  506. border-radius: 40rpx;
  507. padding: 2% 4%;
  508. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  509. }
  510. .submit {
  511. color: white;
  512. font-weight: normal;
  513. width: 55%;
  514. border-radius: 20rpx;
  515. background-color: #02a7f0;
  516. margin: 120rpx auto;
  517. }
  518. }
  519. .popup-box {
  520. height: 100%;
  521. display: flex;
  522. flex-direction: column;
  523. justify-content: space-between;
  524. }
  525. .popup-title {
  526. text-align: center;
  527. font-weight: bold;
  528. height: 30px;
  529. border-bottom: 1px solid #d8d8d8;
  530. }
  531. .popup-content {
  532. font-size: 28rpx;
  533. padding: 10rpx 0 10rpx 0;
  534. }
  535. .popup-type {
  536. height: 80rpx;
  537. text-align: center;
  538. margin-top: 150rpx;
  539. }
  540. .popup-footer {
  541. display: flex;
  542. button{
  543. font-size: 26rpx;
  544. height: 60rpx;
  545. width: 150rpx;
  546. line-height: 60rpx;
  547. color: #FFFFFF;
  548. }
  549. }
  550. .popup-cancel {
  551. background-color: #AAAAAA;
  552. }
  553. .popup-submit {
  554. background-color: #249CD3;
  555. }
  556. </style>