addAllHouse.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view>
  3. <scroll-view class="scroll-wrapper" scroll-y="true">
  4. <view>
  5. <view class="wrap">
  6. <u-form ref="uForm">
  7. <u-form-item :label-position="labelPosition" label="户型" label-width="150" required>
  8. <u-input v-model="houseTypeVo" :border="border" :select-open="selectShow" placeholder="请选择户型"
  9. type="select" @click="selectShow = true"></u-input>
  10. </u-form-item>
  11. <u-form-item :label-position="labelPosition" label="面积" label-width="150" required>
  12. <u-input v-model="model.houseArea" :border="border" placeholder="请输入面积" type="number"></u-input>
  13. </u-form-item>
  14. <u-form-item :label-position="labelPosition" label="租金" label-width="150" required>
  15. <u-input v-model="model.price" :border="border" placeholder="请输入租金" type="number"></u-input>
  16. </u-form-item>
  17. <u-form-item :label-position="labelPosition" label="起租日期" label-width="150">
  18. <view class="dateBtn" @click="dateClick">
  19. {{ dateLabel }}
  20. <u-icon name="arrow-right"></u-icon>
  21. </view>
  22. </u-form-item>
  23. <view class="custom-gap"></view>
  24. <u-form-item :label-position="labelPosition" label="房源图片" label-width="150" required>
  25. <u-upload
  26. ref="uUpload" :action="action" :auto-upload="true" :custom-btn="true" :max-size="10 * 1024 * 1024"
  27. :size-type="siteType" height="160" max-count="9" width="160">
  28. <view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
  29. <u-icon :color="$u.color['lightColor']" name="plus" size="60"></u-icon>
  30. </view>
  31. </u-upload>
  32. </u-form-item>
  33. <u-form-item :label-position="labelPosition" label="房源描述" label-width="150">
  34. <u-input v-model="model.introduce" :border="border" placeholder="请填写房屋描述" type="textarea"/>
  35. </u-form-item>
  36. <u-form-item :label-position="labelPosition" label="房源亮点" label-width="150" required>
  37. <u-checkbox-group :width="radioCheckWidth" :wrap="radioCheckWrap" @change="checkboxGroupChange">
  38. <u-checkbox v-for="(item, index) in checkboxList" :key="index" v-model="item.checked" :name="item.name">
  39. {{ item.name }}
  40. </u-checkbox>
  41. </u-checkbox-group>
  42. </u-form-item>
  43. </u-form>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. <u-select v-model="selectShow" :list="selectList" mode="mutil-column" @confirm="selectConfirm"></u-select>
  48. <u-action-sheet v-model="actionSheetShow" :list="actionSheetList" @click="actionSheetCallback"></u-action-sheet>
  49. <u-calendar v-model="show" :mode="mode" max-date="2100-01-01" @change="changeDate"></u-calendar>
  50. <view class="bottom-btn">
  51. <u-button type="primary" @click="submit">提交</u-button>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import config from "@/common/config.js" // 全局配置文件
  57. export default {
  58. props: {
  59. model: Object
  60. },
  61. data() {
  62. return {
  63. houseTypeVo: '',
  64. show: false,
  65. mode: 'date',
  66. selectList: [
  67. [
  68. {
  69. value: '一室',
  70. label: '一室'
  71. },
  72. {
  73. value: '二室',
  74. label: '二室'
  75. },
  76. {
  77. value: '三室',
  78. label: '三室'
  79. },
  80. {
  81. value: '四室',
  82. label: '四室'
  83. }
  84. ],
  85. [
  86. {
  87. value: '',
  88. label: ''
  89. },
  90. {
  91. value: '一厅',
  92. label: '一厅'
  93. },
  94. {
  95. value: '二厅',
  96. label: '二厅'
  97. },
  98. {
  99. value: '三厅',
  100. label: '三厅'
  101. }
  102. ],
  103. [
  104. {
  105. value: '',
  106. label: ''
  107. },
  108. {
  109. value: '一卫',
  110. label: '一卫'
  111. },
  112. {
  113. value: '二卫',
  114. label: '二卫'
  115. }
  116. ],
  117. ],
  118. border: false,
  119. check: false,
  120. selectStatus: 'close',
  121. checkboxList: [
  122. {
  123. name: '看房方便',
  124. checked: false,
  125. disabled: false
  126. },
  127. {
  128. name: '独卫',
  129. checked: false,
  130. disabled: false
  131. },
  132. {
  133. name: '独立阳台',
  134. checked: false,
  135. disabled: false
  136. },
  137. {
  138. name: '智能锁',
  139. checked: false,
  140. disabled: false
  141. },
  142. {
  143. name: '可短租',
  144. checked: false,
  145. disabled: false
  146. },
  147. {
  148. name: '首次出租',
  149. checked: false,
  150. disabled: false
  151. },
  152. {
  153. name: '免物业费',
  154. checked: false,
  155. disabled: false
  156. },
  157. {
  158. name: '民用水电',
  159. checked: false,
  160. disabled: false
  161. }
  162. ],
  163. actionSheetList: [
  164. {
  165. text: '电梯房'
  166. },
  167. {
  168. text: '楼梯房'
  169. }
  170. ],
  171. selectShow: false,
  172. radioCheckWidth: 'auto',
  173. radioCheckWrap: false,
  174. labelPosition: 'left',
  175. errorType: ['toast'],
  176. actionSheetShow: false,
  177. dateLabel: '随时入住',
  178. // 服务器地址
  179. action: config.staticUrl + '/common/upload',
  180. siteType: ['compressed'],
  181. };
  182. },
  183. watch: {
  184. model: {
  185. handler(newName, oldName) {
  186. this.houseTypeVo = newName.houseType
  187. // 回显房源亮点
  188. if (this.model.featureList) {
  189. this.checkboxList.forEach(item => {
  190. this.model.featureList.forEach(feature => {
  191. if (feature.feature == item.name) {
  192. item.checked = true
  193. }
  194. })
  195. })
  196. }
  197. },
  198. immediate: true,
  199. deep: true
  200. }
  201. },
  202. methods: {
  203. submit() {
  204. if (this.$u.test.isEmpty(this.model.houseType)) {
  205. return this.$mytip.toast('请选择户型')
  206. }
  207. if (this.$u.test.isEmpty(this.model.houseArea)) {
  208. return this.$mytip.toast('请输入面积')
  209. }
  210. if (this.$u.test.isEmpty(this.model.price)) {
  211. return this.$mytip.toast('请输入租金')
  212. }
  213. let files = [];
  214. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  215. files = this.$refs.uUpload.lists.filter(val => {
  216. return val.progress == 100;
  217. })
  218. if (this.$u.test.isEmpty(files)) {
  219. return this.$mytip.toast('请至少选择一张房源图片')
  220. }
  221. let imageList = files.map(val => {
  222. return {
  223. imageName: val.response.realName,
  224. imagePath: val.response.fileName,
  225. imgUrl: val.response.url,
  226. imageSize: val.file.size
  227. }
  228. })
  229. this.model.imageList = imageList
  230. if (this.$u.test.isEmpty(this.model.featureList)) {
  231. return this.$mytip.toast('请至少选择一个房源亮点')
  232. }
  233. let url = "api/houseApi/saveHouse";
  234. if (this.model.id) {
  235. url = "api/houseApi/updateHouse";
  236. }
  237. this.model.publishId = uni.getStorageSync('lifeData').vuex_user.user.userId;
  238. this.$u.post(url, this.model).then(data => {
  239. // uni.$emit('findIndexHouseList', {});
  240. // this.$u.route({
  241. // type: 'tab',url: '/pages/index/index'
  242. // })
  243. this.$u.route({
  244. url: 'pages/center/order',
  245. })
  246. });
  247. },
  248. // 选择类型回调
  249. selectConfirm(e) {
  250. this.model.houseType = ''
  251. e.map((val, index) => {
  252. if (index == 0) {
  253. this.model.houseNum = val.label;
  254. } else if (index == 1) {
  255. this.model.houseHall = val.label;
  256. } else if (index == 2) {
  257. this.model.toiletNum = val.label;
  258. }
  259. this.model.houseType += val.label;
  260. this.houseTypeVo = this.model.houseType
  261. })
  262. },
  263. // 点击actionSheet回调
  264. actionSheetCallback(index) {
  265. uni.hideKeyboard();
  266. this.model.stepType = this.actionSheetList[index].text;
  267. },
  268. // checkbox选择发生变化
  269. checkboxGroupChange(e) {
  270. let featureList = e.map(val => {
  271. return {
  272. feature: val
  273. }
  274. })
  275. this.model.featureList = featureList
  276. },
  277. borderChange(index) {
  278. this.border = !index;
  279. },
  280. labelPositionChange(index) {
  281. this.labelPosition = index == 0 ? 'left' : 'top';
  282. },
  283. codeChange(text) {
  284. this.codeTips = text;
  285. },
  286. dateClick() {
  287. this.show = true
  288. },
  289. changeDate(e) {
  290. this.model.startDate = e.result
  291. this.dateLabel = e.result
  292. }
  293. }
  294. };
  295. </script>
  296. <style>
  297. page {
  298. background-color: #FFFFFF;
  299. }
  300. </style>
  301. <style lang="scss" scoped>
  302. .wrap {
  303. padding: 30 rpx;
  304. }
  305. .scroll-wrapper {
  306. position: absolute;
  307. left: 0 rpx;
  308. right: 0 rpx;
  309. top: 0 rpx;
  310. bottom: 120 rpx;
  311. }
  312. .bottom-btn {
  313. position: fixed;
  314. bottom: 8 rpx;
  315. width: 100%;
  316. padding: 30 rpx;
  317. border-top: 1 rpx solid #ccc;
  318. background-color: #FFFFFF;
  319. }
  320. .dateBtn {
  321. position: absolute;
  322. right: 0 rpx;
  323. top: 10 rpx;
  324. color: #606266;
  325. }
  326. .slot-btn {
  327. width: 160 rpx;
  328. height: 160 rpx;
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. background: rgb(244, 245, 246);
  333. border-radius: 10 rpx;
  334. }
  335. .slot-btn__hover {
  336. background-color: rgb(235, 236, 238);
  337. }
  338. .custom-gap {
  339. width: 1000 rpx;
  340. height: 10 rpx;
  341. margin: 0 -200rpx 0 -200rpx;
  342. background-color: rgb(235, 236, 238);
  343. }
  344. </style>