with_house.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="tel flex">
  5. <label>小区名称:</label>
  6. <view class="picker card input">
  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 card input">
  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 card input">
  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 card input">
  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. let that = this;
  358. uni.showModal({
  359. title: "确定关联此住房信息吗?",
  360. success(res) {
  361. if (res.confirm) {
  362. //确定继续后续操作。
  363. that.submit();
  364. }else if (res.cancel) {
  365. return;
  366. }
  367. },
  368. });
  369. },
  370. hoodChange(e){
  371. console.log("e.pickerVal="+e.pickerVal);
  372. this.hoodName = e.pickerVal;
  373. this.searchDetail(this.hoodName)
  374. },
  375. buildingChange(e) {
  376. if(!this.hoodName){
  377. uni.showToast({
  378. title: "请先选择小区",
  379. icon: "error",
  380. });
  381. return
  382. }
  383. this.buildIndex = e.detail.value;
  384. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name)
  385. },
  386. unitChange(e) {
  387. if(!this.buildList.length){
  388. uni.showToast({
  389. title: "请先选择楼栋",
  390. icon: "error",
  391. });
  392. return
  393. }
  394. this.unitIndex = e.detail.value;
  395. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name,this.unitList[this.unitIndex].name)
  396. },
  397. numChange(e) {
  398. if(!this.unitList.length){
  399. uni.showToast({
  400. title: "请先选择单元",
  401. icon: "error",
  402. });
  403. return
  404. }
  405. this.numIndex = e.detail.value;
  406. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name,this.unitList[this.unitIndex].name,this.numList[this.numIndex].name);
  407. },
  408. submitPop(){
  409. //this.closePopup()
  410. this.submit()
  411. },
  412. closePop(){
  413. this.closePopup()
  414. },
  415. open() {
  416. this.$refs.popup.open('center')
  417. },
  418. closePopup() {
  419. this.$refs.popup.close()
  420. },
  421. submit() {
  422. if (
  423. !this.buildList.length ||
  424. !this.unitList.length ||
  425. !this.numList.length
  426. ) {
  427. uni.showToast({
  428. title: "小区信息不完善",
  429. icon: "error",
  430. });
  431. return;
  432. }
  433. let addressResult = this.hoodName + '/' + this.buildList[this.buildIndex].name + '/' + this.unitList[this.unitIndex].name + '/' + this.numList[this.numIndex].name
  434. let md5Sign = md5(
  435. "method=" +
  436. "user" +
  437. "&timestamp=" +
  438. getApp().globalData.globalTimestamp +
  439. "&secret=" +
  440. getApp().globalData.secret
  441. );
  442. let url =
  443. getApp().globalData.shareUrl +
  444. "api/api.php" +
  445. "?method=user&source=user&action=band_owner&timestamp=" +
  446. getApp().globalData.globalTimestamp +
  447. "&sign=" +
  448. md5Sign;
  449. let postData = {
  450. address:addressResult,
  451. openId: getApp().globalData.open_id,
  452. };
  453. uni.request({
  454. url: url,
  455. method: "POST",
  456. header: {
  457. "content-type": "application/x-www-form-urlencoded",
  458. },
  459. data: postData,
  460. success: (res) => {
  461. if (res.data.code === 200) {
  462. uni.showToast({
  463. title: "绑定成功",
  464. icon: "success",
  465. });
  466. setTimeout(function() {
  467. uni.navigateBack({
  468. });
  469. }, 500)
  470. }
  471. },
  472. fail: () => {
  473. console.log("连接失败");
  474. },
  475. });
  476. },
  477. },
  478. };
  479. </script>
  480. <style lang="scss" scoped>
  481. .content {
  482. font-size: 28rpx;
  483. font-weight: 200;
  484. padding: 1% 2%;
  485. .title {
  486. font-size: 30rpx;
  487. margin: 4% 0;
  488. }
  489. label {
  490. display: inline-block;
  491. width: 25%;
  492. vertical-align: middle;
  493. }
  494. .card {
  495. background-color: rgb(248, 247, 247);
  496. border-radius: 10rpx;
  497. }
  498. .flex {
  499. display: flex;
  500. align-items: center;
  501. margin-bottom: 2%;
  502. }
  503. .input {
  504. padding: 0 2%;
  505. margin: 2% 0;
  506. display: inline-block;
  507. width: 80%;
  508. height: 70rpx;
  509. line-height: 70rpx;
  510. }
  511. .supplyInfo {
  512. border-radius: 40rpx;
  513. padding: 4%;
  514. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  515. margin: 30rpx 0 30rpx 0;
  516. }
  517. .info {
  518. margin-top: 2%;
  519. border-radius: 40rpx;
  520. padding: 2% 4%;
  521. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  522. }
  523. .submit {
  524. color: white;
  525. font-weight: normal;
  526. width: 55%;
  527. border-radius: 20rpx;
  528. background-color: #02a7f0;
  529. margin: 120rpx auto;
  530. }
  531. }
  532. .popup-box {
  533. height: 100%;
  534. display: flex;
  535. flex-direction: column;
  536. justify-content: space-between;
  537. }
  538. .popup-title {
  539. text-align: center;
  540. font-weight: bold;
  541. height: 30px;
  542. border-bottom: 1px solid #d8d8d8;
  543. }
  544. .popup-content {
  545. font-size: 28rpx;
  546. padding: 10rpx 0 10rpx 0;
  547. }
  548. .popup-type {
  549. height: 80rpx;
  550. text-align: center;
  551. margin-top: 100rpx;
  552. }
  553. .popup-footer {
  554. display: flex;
  555. button{
  556. font-size: 26rpx;
  557. height: 60rpx;
  558. width: 150rpx;
  559. line-height: 60rpx;
  560. color: #FFFFFF;
  561. }
  562. }
  563. .popup-cancel {
  564. background-color: #AAAAAA;
  565. }
  566. .popup-submit {
  567. background-color: #249CD3;
  568. }
  569. </style>