addSubHouse.vue 10 KB

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