preHouse.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="">
  3. <!-- #ifndef MP-WEIXIN -->
  4. <u-image :src="src" height="350rpx" width="100%"></u-image>
  5. <!-- #endif -->
  6. <view class="wrap">
  7. <u-form ref="uForm" :errorType="errorType" :model="model" :rules="rules">
  8. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" label="小区名称" label-width="180"
  9. left-icon="map" prop="villageName">
  10. <u-input v-model="model.villageName" :border="border" :select-open="selectShow" placeholder="请选择小区(必选)"
  11. type="select" @click="selectShow = true"></u-input>
  12. </u-form-item>
  13. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" :rightIconStyle="{color:'#d5d5d5'}" label="详细地址"
  14. label-width="180" left-icon="file-text" prop="address"
  15. right-icon="map">
  16. <u-input v-model="model.address" :border="border" disabled placeholder="请在地图选择详细地址" type="text"
  17. @click="chooseAddress"></u-input>
  18. </u-form-item>
  19. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" label="房牌号" label-width="180"
  20. left-icon="home" prop="houseNo">
  21. <u-input v-model="model.houseNo" :border="border" placeholder="请输入门牌号(必填)" type="text"></u-input>
  22. </u-form-item>
  23. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" label="装修" label-width="180" left-icon="eye"
  24. prop="decoration">
  25. <u-input v-model="model.decoration" :border="border" :select-open="decorationShow" placeholder="请选择装修(必选)"
  26. type="select" @click="decorationShow = true"></u-input>
  27. </u-form-item>
  28. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" label="房东姓名" label-width="180"
  29. left-icon="account" prop="ownerName">
  30. <u-input v-model="model.ownerName" :border="border" placeholder="请输入房东姓名(必填)" type="text"></u-input>
  31. </u-form-item>
  32. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" label="房东电话" label-width="180"
  33. left-icon="phone" prop="owerPhone">
  34. <u-input v-model="model.owerPhone" :border="border" maxlength="11" placeholder="请输入房东电话(必填)"
  35. type="number"></u-input>
  36. </u-form-item>
  37. <u-form-item :label-position="labelPosition" :leftIconStyle="{color:'#d5d5d5'}" label="付款方式" label-width="180"
  38. left-icon="rmb-circle" prop="payType">
  39. <u-input v-model="model.payType" :border="border" :select-open="actionSheetShow" placeholder="请选择付款方式(必选)"
  40. type="select" @click="actionSheetShow = true"></u-input>
  41. </u-form-item>
  42. </u-form>
  43. <!-- 流量主-腾讯视频广告 -->
  44. <ad ad-theme="white" ad-type="video" unit-id="adunit-c6cdd74f48eed506"></ad>
  45. <u-select v-model="selectShow" :list="selectList" mode="single-column" @confirm="selectConfirm"></u-select>
  46. <u-select v-model="decorationShow" :list="decorationList" mode="single-column"
  47. @confirm="decorationConfirm"></u-select>
  48. <u-action-sheet v-model="actionSheetShow" :list="actionSheetList" @click="actionSheetCallback"></u-action-sheet>
  49. </view>
  50. <view class="bottom-btn">
  51. <u-button type="primary" @click="submit">下一步</u-button>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. data() {
  58. let that = this;
  59. return {
  60. src: 'http://img.sccnn.com/bimg/340/02027.jpg',
  61. actionSheetShow: false,
  62. model: {
  63. type: 0,
  64. houseType: '',
  65. roomLabel: '',
  66. villageName: '',
  67. villageId: '',
  68. address: '',
  69. houseNo: '',
  70. //装修
  71. decoration: '',
  72. //房东
  73. ownerName: '',
  74. //房东电话
  75. owerPhone: '',
  76. payType: '',
  77. createName: uni.getStorageSync('lifeData').vuex_user.userName,
  78. publishId: uni.getStorageSync('lifeData').vuex_user.userId,
  79. state: 0,
  80. longitude: 0,
  81. latitude: 0,
  82. },
  83. selectList: [],
  84. decorationList: [
  85. {
  86. label: '简装',
  87. value: '简装'
  88. },
  89. {
  90. label: '中装',
  91. value: '中装'
  92. },
  93. {
  94. label: '精装修',
  95. value: '精装修'
  96. },
  97. {
  98. label: '豪装',
  99. value: '豪装'
  100. }
  101. ],
  102. actionSheetList: [
  103. {
  104. text: '月付'
  105. },
  106. {
  107. text: '季付'
  108. },
  109. {
  110. text: '半年付'
  111. },
  112. {
  113. text: '年付'
  114. }
  115. ],
  116. rules: {
  117. villageName: [
  118. {
  119. required: true,
  120. message: '请选择小区',
  121. trigger: ['change', 'blur'],
  122. }
  123. ],
  124. address: [
  125. {
  126. required: true,
  127. message: '请输入详细地址',
  128. trigger: ['change', 'blur'],
  129. }
  130. ],
  131. houseNo: [
  132. {
  133. required: true,
  134. message: '请输入门牌号',
  135. trigger: ['change', 'blur'],
  136. }
  137. ],
  138. decoration: [
  139. {
  140. required: true,
  141. message: '请选择装修',
  142. trigger: ['change', 'blur'],
  143. }
  144. ],
  145. ownerName: [
  146. {
  147. required: true,
  148. message: '请输入房东姓名',
  149. trigger: ['change', 'blur'],
  150. }
  151. ],
  152. owerPhone: [
  153. {
  154. required: true,
  155. message: '请输入房东电话',
  156. trigger: ['change', 'blur'],
  157. }
  158. ],
  159. payType: [
  160. {
  161. required: true,
  162. message: '请选择付款方式',
  163. trigger: ['change', 'blur'],
  164. }
  165. ],
  166. },
  167. border: false,
  168. check: false,
  169. selectShow: false,
  170. decorationShow: false,
  171. labelPosition: 'left',
  172. errorType: ['toast'],
  173. };
  174. },
  175. onLoad(option) {
  176. let houseId = option.houseId //上个页面传递的参数。
  177. if (houseId) {
  178. // 渲染当前房源信息
  179. this.findHouseById(houseId);
  180. }
  181. this.findVillageList()
  182. // 定位经纬度
  183. uni.getLocation({
  184. type: 'gcj02',
  185. // 当指定 high 时,期望精度值为100m,当指定 best 时期望精度值为20m
  186. accuracy: 'best',
  187. // 开启高精度定位
  188. isHighAccuracy: true,
  189. success: (res) => {
  190. this.longitude = res.longitude
  191. this.latitude = res.latitude
  192. }
  193. });
  194. uni.$on('changeAddressConfig', (address, lon, lat) => {
  195. // 获取数据
  196. this.changeAddressConfig(address, lon, lat);
  197. })
  198. },
  199. onUnload() {
  200. // 移除监听事件
  201. uni.$off('changeAddressConfig');
  202. },
  203. onReady() {
  204. this.$refs.uForm.setRules(this.rules);
  205. },
  206. methods: {
  207. changeAddressConfig(address, lon, lat) {
  208. this.model.address = address
  209. this.model.longitude = lon
  210. this.model.latitude = lat
  211. },
  212. submit() {
  213. this.$refs.uForm.validate(valid => {
  214. if (valid) {
  215. if (!this.$u.test.mobile(this.model.owerPhone)) {
  216. return this.$mytip.toast('房东电话请输入手机号码')
  217. }
  218. return this.$u.route({
  219. url: '/pages/detail/addHouse',
  220. params: {
  221. room: JSON.stringify(this.model)
  222. }
  223. })
  224. } else {
  225. console.log('验证失败');
  226. }
  227. });
  228. },
  229. selectConfirm(e) {
  230. e.map((val, index) => {
  231. this.model.villageName = val.label;
  232. this.model.villageId = val.value
  233. })
  234. },
  235. decorationConfirm(e) {
  236. e.map((val, index) => {
  237. this.model.decoration = val.label;
  238. })
  239. },
  240. labelPositionChange(index) {
  241. this.labelPosition = index == 0 ? 'left' : 'top';
  242. },
  243. // 点击actionSheet回调
  244. actionSheetCallback(index) {
  245. uni.hideKeyboard();
  246. this.model.payType = this.actionSheetList[index].text;
  247. },
  248. findVillageList() {
  249. let url = "/api/houseApi/findVillageList";
  250. this.$u.get(url, {
  251. city: uni.getStorageSync('lifeData').vuex_city,
  252. orderByColumn: 'name',
  253. isAsc: 'desc'
  254. }).then(result => {
  255. const data = result.rows
  256. for (let i = 0; i < data.length; i++) {
  257. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  258. let item = data[i]
  259. this.selectList.push({
  260. label: item.name,
  261. value: item.id
  262. })
  263. }
  264. return data
  265. });
  266. },
  267. findHouseById(houseId) {
  268. let url = "api/houseApi/findHouseById";
  269. this.$u.get(url, {
  270. id: houseId
  271. }).then(result => {
  272. let room = result.data
  273. this.model = room
  274. let houseType = this.model.houseNum + this.model.houseHall + this.model.toiletNum
  275. if (houseType == 0) {
  276. houseType = ''
  277. }
  278. this.model.houseType = houseType
  279. if (this.model.roomType == 1) {
  280. this.model.roomLabel = '主卧'
  281. } else if (this.model.roomType == 2) {
  282. this.model.roomLabel = '次卧'
  283. }
  284. });
  285. },
  286. chooseAddress() {
  287. this.$u.route({
  288. url: '/pages/chooseAddress/index'
  289. })
  290. },
  291. }
  292. };
  293. </script>
  294. <style>
  295. page {
  296. background-color: #FFFFFF;
  297. }
  298. </style>
  299. <style lang="scss" scoped>
  300. .wrap {
  301. padding: 30 rpx;
  302. }
  303. /* #ifdef MP-WEIXIN */
  304. .bottom-btn {
  305. position: fixed;
  306. bottom: 8 rpx;
  307. width: 100%;
  308. padding: 30 rpx;
  309. border-top: 1 rpx solid #eee;
  310. background-color: #FFFFFF;
  311. }
  312. /* #endif */
  313. /* #ifndef MP-WEIXIN */
  314. .bottom-btn {
  315. padding: 0 30 rpx 30 rpx 30 rpx;
  316. background-color: #FFFFFF;
  317. }
  318. /* #endif */
  319. </style>