with_house.vue 12 KB

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