with_house.vue 13 KB

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