with_house.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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">
  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. // let result = e.detail.value;
  156. let md5Sign = md5(
  157. "method=" +
  158. "user" +
  159. "&timestamp=" +
  160. getApp().globalData.globalTimestamp +
  161. "&secret=" +
  162. getApp().globalData.secret
  163. );
  164. let url =
  165. getApp().globalData.shareUrl +
  166. "api/api.php" +
  167. "?method=user&source=user&action=search_estate&timestamp=" +
  168. getApp().globalData.globalTimestamp +
  169. "&sign=" +
  170. md5Sign;
  171. let postData = {
  172. keyword:'',
  173. openId: getApp().globalData.open_id,
  174. };
  175. uni.request({
  176. url: url,
  177. method: "POST",
  178. header: {
  179. "content-type": "application/x-www-form-urlencoded",
  180. },
  181. data: postData,
  182. success: (res) => {
  183. if (res.data.code === 200) {
  184. let obj = res.data.data;
  185. for (let key in obj) {
  186. let child = {
  187. name:obj[key]
  188. }
  189. this.hoodList.push(child)
  190. }
  191. }
  192. },
  193. fail: () => {
  194. console.log("连接失败");
  195. },
  196. });
  197. },
  198. searchDetail(hood,build,unit,room){
  199. let that = this, addressResult,searchType;
  200. // let result = e.detail.value;
  201. that.house.master = '';
  202. that.house.area = '';
  203. if (room)
  204. {
  205. searchType = 'houseRoom'
  206. addressResult = hood + '/' + build + '/' + unit + '/' + room
  207. }
  208. if(build && unit && !room){
  209. if (build === "请选择房号")
  210. {
  211. return;
  212. }
  213. searchType = 'houseNumber'
  214. addressResult = hood + '/' + build + '/' + unit
  215. }
  216. if(build && !unit){
  217. if (build === "请选择单元")
  218. {
  219. return;
  220. }
  221. searchType = 'houseUnit'
  222. addressResult = hood + '/' + build
  223. }
  224. if(!build && !unit){
  225. if (build === "请选择楼栋")
  226. {
  227. return;
  228. }
  229. searchType = 'houseBuilding'
  230. addressResult = hood
  231. }
  232. let md5Sign = md5(
  233. "method=" +
  234. "user" +
  235. "&timestamp=" +
  236. getApp().globalData.globalTimestamp +
  237. "&secret=" +
  238. getApp().globalData.secret
  239. );
  240. let url =
  241. getApp().globalData.shareUrl +
  242. "api/api.php" +
  243. "?method=user&source=user&action=get_address&timestamp=" +
  244. getApp().globalData.globalTimestamp +
  245. "&sign=" +
  246. md5Sign;
  247. let postData = {
  248. address:addressResult,
  249. openId: getApp().globalData.open_id,
  250. };
  251. uni.request({
  252. url: url,
  253. method: "POST",
  254. header: {
  255. "content-type": "application/x-www-form-urlencoded",
  256. },
  257. data: postData,
  258. success: (res) => {
  259. if (res.data.code === 200) {
  260. if(res.data.data.length === 0){
  261. uni.showToast({
  262. title: "暂无数据",
  263. icon: "error",
  264. });
  265. }else{
  266. that.makeHouseData(searchType,res.data.data)
  267. }
  268. }
  269. },
  270. fail: () => {
  271. console.log("连接失败");
  272. },
  273. });
  274. },
  275. resetLevels(level){
  276. //重置下一层
  277. let that = this;
  278. switch (level){
  279. case 1:
  280. that.buildList = [];
  281. let a = {
  282. name : '请选择楼栋'
  283. };
  284. that.buildList.push(a);
  285. that.buildIndex = 0;
  286. case 2:
  287. that.unitList = [];
  288. let b = {
  289. name : '请选择单元'
  290. };
  291. that.unitList.push(b);
  292. that.unitIndex = 0;
  293. case 3:
  294. that.numList = [];
  295. let c = {
  296. name : '请选择房号'
  297. };
  298. that.numList.push(c);
  299. that.numIndex = 0;
  300. case 4:
  301. that.house.master = '';
  302. that.house.area = '';
  303. }
  304. },
  305. makeHouseData(type,dataList){
  306. let that = this , obj = dataList;
  307. switch (type){
  308. case 'houseBuilding':
  309. this.resetLevels(1);
  310. for (let key in obj) {
  311. let child = {
  312. name:obj[key]
  313. }
  314. that.buildList.push(child)
  315. }
  316. //that.searchDetail(that.hoodName,that.buildList[0].name)
  317. break;
  318. case 'houseUnit':
  319. this.resetLevels(2);
  320. for (let key in obj) {
  321. let child = {
  322. name:obj[key]
  323. }
  324. that.unitList.push(child)
  325. }
  326. //that.searchDetail(that.hoodName,that.buildList[that.buildIndex].name,that.unitList[0].name)
  327. break;
  328. case 'houseNumber':
  329. this.resetLevels(3);
  330. for (let key in obj) {
  331. let child = {
  332. name:obj[key]
  333. }
  334. that.numList.push(child)
  335. }
  336. //that.searchDetail(that.hoodName,that.buildList[that.buildIndex].name,that.unitList[that.unitIndex].name,that.numList[0].name);
  337. break;
  338. case 'houseRoom':
  339. that.house.master = obj.name;
  340. that.house.area = obj.area;
  341. default:
  342. break;
  343. }
  344. },
  345. houseSubmit(){
  346. //uni.navigateBack({});
  347. this.open()
  348. },
  349. hoodChange(e){
  350. console.log("e.pickerVal="+e.pickerVal);
  351. this.hoodName = e.pickerVal;
  352. this.searchDetail(this.hoodName)
  353. },
  354. buildingChange(e) {
  355. if(!this.hoodName){
  356. uni.showToast({
  357. title: "请先选择小区",
  358. icon: "error",
  359. });
  360. return
  361. }
  362. this.buildIndex = e.detail.value;
  363. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name)
  364. },
  365. unitChange(e) {
  366. if(!this.buildList.length){
  367. uni.showToast({
  368. title: "请先选择楼栋",
  369. icon: "error",
  370. });
  371. return
  372. }
  373. this.unitIndex = e.detail.value;
  374. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name,this.unitList[this.unitIndex].name)
  375. },
  376. numChange(e) {
  377. if(!this.unitList.length){
  378. uni.showToast({
  379. title: "请先选择单元",
  380. icon: "error",
  381. });
  382. return
  383. }
  384. this.numIndex = e.detail.value;
  385. this.searchDetail(this.hoodName,this.buildList[this.buildIndex].name,this.unitList[this.unitIndex].name,this.numList[this.numIndex].name);
  386. },
  387. submitPop(){
  388. this.closePopup()
  389. this.submit()
  390. },
  391. closePop(){
  392. this.closePopup()
  393. },
  394. open() {
  395. this.$refs.popup.open('center')
  396. },
  397. closePopup() {
  398. this.$refs.popup.close()
  399. },
  400. submit() {
  401. if (
  402. !this.buildList.length ||
  403. !this.unitList.length ||
  404. !this.numList.length
  405. ) {
  406. uni.showToast({
  407. title: "小区信息不完善",
  408. icon: "error",
  409. });
  410. return;
  411. }
  412. let addressResult = this.hoodName + '/' + this.buildList[this.buildIndex].name + '/' + this.unitList[this.unitIndex].name + '/' + this.numList[this.numIndex].name
  413. let md5Sign = md5(
  414. "method=" +
  415. "user" +
  416. "&timestamp=" +
  417. getApp().globalData.globalTimestamp +
  418. "&secret=" +
  419. getApp().globalData.secret
  420. );
  421. let url =
  422. getApp().globalData.shareUrl +
  423. "api/api.php" +
  424. "?method=user&source=user&action=band_owner&timestamp=" +
  425. getApp().globalData.globalTimestamp +
  426. "&sign=" +
  427. md5Sign;
  428. let postData = {
  429. address:addressResult,
  430. openId: getApp().globalData.open_id,
  431. };
  432. uni.request({
  433. url: url,
  434. method: "POST",
  435. header: {
  436. "content-type": "application/x-www-form-urlencoded",
  437. },
  438. data: postData,
  439. success: (res) => {
  440. if (res.data.code === 200) {
  441. uni.showToast({
  442. title: "绑定成功",
  443. icon: "success",
  444. });
  445. setTimeout(function() {
  446. uni.navigateBack({
  447. });
  448. }, 500)
  449. }
  450. },
  451. fail: () => {
  452. console.log("连接失败");
  453. },
  454. });
  455. },
  456. },
  457. };
  458. </script>
  459. <style lang="scss" scoped>
  460. .content {
  461. font-size: 28rpx;
  462. font-weight: 200;
  463. padding: 1% 2%;
  464. .title {
  465. font-size: 30rpx;
  466. margin: 4% 0;
  467. }
  468. label {
  469. display: inline-block;
  470. width: 25%;
  471. vertical-align: middle;
  472. }
  473. .card {
  474. background-color: rgb(248, 247, 247);
  475. border-radius: 10rpx;
  476. }
  477. .flex {
  478. display: flex;
  479. align-items: center;
  480. margin-bottom: 2%;
  481. }
  482. .input {
  483. padding: 0 2%;
  484. margin: 2% 0;
  485. display: inline-block;
  486. width: 80%;
  487. height: 70rpx;
  488. }
  489. .supplyInfo {
  490. border-radius: 40rpx;
  491. padding: 4%;
  492. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  493. margin: 30rpx 0 30rpx 0;
  494. }
  495. .info {
  496. margin-top: 2%;
  497. border-radius: 40rpx;
  498. padding: 2% 4%;
  499. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  500. }
  501. .submit {
  502. color: white;
  503. font-weight: normal;
  504. width: 55%;
  505. border-radius: 20rpx;
  506. background-color: #02a7f0;
  507. margin: 120rpx auto;
  508. }
  509. }
  510. .popup-box {
  511. height: 100%;
  512. display: flex;
  513. flex-direction: column;
  514. justify-content: space-between;
  515. }
  516. .popup-title {
  517. text-align: center;
  518. font-weight: bold;
  519. height: 30px;
  520. border-bottom: 1px solid #d8d8d8;
  521. }
  522. .popup-content {
  523. font-size: 28rpx;
  524. padding: 10rpx 0 10rpx 0;
  525. }
  526. .popup-type {
  527. height: 80rpx;
  528. text-align: center;
  529. margin-top: 150rpx;
  530. }
  531. .popup-footer {
  532. display: flex;
  533. button{
  534. font-size: 26rpx;
  535. height: 60rpx;
  536. width: 150rpx;
  537. line-height: 60rpx;
  538. color: #FFFFFF;
  539. }
  540. }
  541. .popup-cancel {
  542. background-color: #AAAAAA;
  543. }
  544. .popup-submit {
  545. background-color: #249CD3;
  546. }
  547. </style>