houseList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <view class="page" :style="{ 'height': (h) + 'px', 'padding-top': mt + 'px' }">
  3. <c-nav-bar title="房间列表" :showIcon="true"></c-nav-bar>
  4. <view class="body">
  5. <!-- 房型信息 -->
  6. <view class="typeInfo">
  7. <view class="titleInfo">
  8. <text style="font-size: 32rpx; font-weight: 700;">房型信息</text>
  9. </view>
  10. <view class="cellBox">
  11. <text style="font-size: 30rpx; margin-right: 30rpx;">房型名称</text>
  12. <input v-model="form.name" type="text" placeholder="请输入房型"
  13. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  14. </view>
  15. <view class="bigRoom">
  16. <text style="font-size: 30rpx;color: black; margin-right: 90rpx;">简称</text>
  17. <input v-model="form.shortName" type="text" placeholder="请输入简称"
  18. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  19. </view>
  20. </view>
  21. <!-- <view class="shelves">
  22. <view style="margin-left: 30rpx;">
  23. <text style="font-size: 30rpx; ">是否上架</text>
  24. </view>
  25. <view style="margin-right: 30rpx;">
  26. <u-switch v-model="checked" size="50" active-color="#07C160"> </u-switch>
  27. </view>
  28. </view> -->
  29. <!-- 图片上传
  30. -->
  31. <view class="uploadPic">
  32. <view style=" margin-left: 30rpx;">
  33. <text style="font-size: 32rpx; font-weight: 700; ">封面图片({{ fileList.length }}/1)</text>
  34. </view>
  35. <view style="margin-top: 20rpx; margin-left: 30rpx; color: #777; font-size: 24rpx;">
  36. <text>仅能上传1张,需展示房间内容</text>
  37. </view>
  38. <view class="pic">
  39. <!-- 图片 -->
  40. <u-upload :fileList="fileList" multiple :maxCount="1" :maxSize="10 * 1024 * 1024"
  41. @afterRead="afterRead" @oversize="overSize" width="120" height="120" @delete="deletePic">
  42. </u-upload>
  43. </view>
  44. </view>
  45. <!-- 房间列表 -->
  46. <view class="everyHouseList" style="padding-top: 20rpx;">
  47. <view class="HouseListTitleInfo">
  48. <text style="font-size: 32rpx; font-weight: 700;">房间列表</text>
  49. <text style="font-size: 24rpx; color: #777;">共{{ form.roomFloor.length }}个房间</text>
  50. </view>
  51. <!-- 房间号 -->
  52. <view class="priceBoxWeek" v-for="(room, index) in form.roomFloor" :key="index" @scroll="scroll">
  53. <view class="weekendBox" style="display: flex; justify-content: space-between; align-items: center">
  54. <view style="display: flex; align-items: center;height:54rpx ">
  55. <view style="font-size: 30rpx;"> 楼层:</view>
  56. <input style="width: 150rpx; margin-bottom: 5rpx; font-size: 28rpx; height: 50rpx;"
  57. v-model="room.floor" />
  58. </view>
  59. <view style="display: flex; align-items: center;">
  60. <view style="font-size: 30rpx;"> 房间号:</view>
  61. <input style=" width: 150rpx; margin-bottom: 5rpx; font-size: 28rpx; height: 50rpx;"
  62. v-model="room.roomNumber" />
  63. </view>
  64. <view style="display: flex; margin-top: 10rpx;" @click="delRoom(index)">
  65. <u-icon name="trash"></u-icon>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="submit" @click="addRoom">
  71. <u-icon name="plus-circle" color=" #1372FF"></u-icon>
  72. <text style="color: #1372FF; font-size: 30rpx;">添加房间</text>
  73. </view>
  74. </view>
  75. <!-- 新增按钮 -->
  76. <view class="btn-btn" @click="addNewRoom()">
  77. <view class="btn">
  78. 确定
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. export default {
  85. data() {
  86. return {
  87. checked: false,
  88. weekedChecked: false,
  89. action: '', //图片服务器地址
  90. fileList: [],
  91. form: {
  92. price: '',
  93. homestayId: '',
  94. mondayPrice: '',
  95. tuesdayPrice: '',
  96. wednesdayPrice: '',
  97. thursdayPrice: '',
  98. fridayPrice: '',
  99. saturdayPrice: '',
  100. sundayPrice: '',
  101. name: '',
  102. shortName: '',
  103. isPutaway: '',
  104. roomFloor: [{
  105. floor: '',
  106. roomNumber: ''
  107. }],
  108. cover: ''
  109. },
  110. }
  111. },
  112. onLoad({
  113. id,
  114. houseBaseId
  115. }) {
  116. this.form.homestayId = id
  117. // console.log(houseBaseId)
  118. this.id = houseBaseId
  119. // console.log(this.id)
  120. this.getTypeInfo()
  121. },
  122. methods: {
  123. scroll(e) {
  124. console.log('-----++++', e);
  125. uni.hideKeyboard()
  126. },
  127. // 删除图片
  128. deletePic(event) {
  129. this.fileList.splice(event.index, 1)
  130. },
  131. // 新增图片
  132. async afterRead(event) {
  133. const result = await this.uploadFilePromise(event.file[0].url);
  134. //图片路径
  135. console.log(result)
  136. },
  137. // 图片大小超出最大允许大小
  138. overSize(e) {
  139. uni.$u.toast('上传图片大小不能超过10MB!')
  140. },
  141. //上传图片
  142. uploadFilePromise(url) {
  143. console.log(url)
  144. return new Promise((resolve, reject) => {
  145. let a = uni.uploadFile({
  146. url: 'https://fsy.shengsi.gov.cn/island-cloud-server/oss/file/aliyunUpload',
  147. filePath: url,
  148. name: 'file',
  149. header: {
  150. token: wx.getStorageSync('access_token')
  151. },
  152. success: (res) => {
  153. console.log(res)
  154. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  155. this.fileList.push({
  156. url: data.data.url
  157. })
  158. this.form.cover = data.data.url;
  159. resolve(data.data.url)
  160. }
  161. });
  162. })
  163. },
  164. // 添加&编辑房屋
  165. addNewRoom() {
  166. // console.log(this.form)
  167. if (!this.id) {
  168. if (this.checked === true) {
  169. this.form.isPutaway = 1
  170. } else {
  171. this.form.isPutaway = 0
  172. }
  173. this.$api.post('/merchant/hotel/mine/addHouseBase', this.form).then(res => {
  174. // console.log(res)
  175. if (res.data.code === 0) {
  176. this.$showToast('修改成功');
  177. setTimeout(() => {
  178. uni.reLaunch({
  179. url: '/pages/my/roomType'
  180. })
  181. }, 1500)
  182. }
  183. })
  184. console.log('这是')
  185. } else {
  186. // console.log('这是修改')
  187. // if(this.)
  188. if (this.checked === true) {
  189. this.form.isPutaway = 1
  190. } else {
  191. this.form.isPutaway = 0
  192. }
  193. this.$api.put('/merchant/hotel/mine/updHouseBase', this.form).then(res => {
  194. // console.log('修改成功')
  195. if (res.data.code === 0) {
  196. this.$showToast('修改成功')
  197. setTimeout(() => {
  198. uni.reLaunch({
  199. url: '/pages/my/roomType'
  200. })
  201. }, 1500)
  202. }
  203. })
  204. }
  205. },
  206. // 添加房间
  207. addRoom() {
  208. const newRoom = {
  209. floor: '',
  210. roomNumber: ''
  211. }
  212. this.form.roomFloor.push(newRoom)
  213. },
  214. // 删除房间
  215. delRoom(index) {
  216. this.form.roomFloor.splice(index, 1)
  217. },
  218. // 获取当前房型信息
  219. getTypeInfo() {
  220. if (this.id) {
  221. this.$api.get(`/merchant/hotel/mine/getHouseBaseInfo/${this.id}`).then((res) => {
  222. // console.log(res)
  223. if (res.data.code === 0) {
  224. this.form = res.data.data
  225. this.fileList.push({
  226. url: res.data.data.cover
  227. })
  228. if (this.form.isPutaway == 1) {
  229. this.checked = true
  230. } else {
  231. this.checked = false
  232. }
  233. }
  234. })
  235. } else {
  236. return
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. .btn-btn {
  244. width: 100%;
  245. height: 136rpx;
  246. background-color: #fff;
  247. position: fixed;
  248. bottom: 0;
  249. padding: 30rpx 0 0;
  250. // margin: 0 auto;
  251. z-index: 999999;
  252. // margin-top: 30rpx;
  253. // margin-left: 30rpx;
  254. }
  255. .btn {
  256. margin: 0 auto;
  257. width: 690rpx;
  258. height: 96rpx;
  259. background-color: #1372FF;
  260. color: #fff;
  261. display: flex;
  262. justify-content: center;
  263. align-items: center;
  264. font-size: 34rpx;
  265. border-radius: 48rpx;
  266. }
  267. .uicon-close {
  268. font-size: 30rpx !important;
  269. top: 8rpx !important;
  270. }
  271. .page {
  272. background: #F3F4F4;
  273. padding-bottom: 260rpx;
  274. box-sizing: border-box;
  275. overflow-y: auto;
  276. overflow-x: auto;
  277. }
  278. .body {
  279. padding-top: 20rpx;
  280. padding-left: 30rpx;
  281. padding-right: 30rpx;
  282. }
  283. .typeInfo {
  284. background-color: #fff;
  285. width: 100%;
  286. // height: 145px;
  287. border-radius: 5px;
  288. padding-top: 15px;
  289. padding-left: 7px;
  290. padding-right: 15px;
  291. box-sizing: border-box;
  292. }
  293. .titleInfo {
  294. // margin-top: 30rpx;
  295. margin-left: 20rpx;
  296. margin-bottom: 40rpx;
  297. }
  298. .cellBox {
  299. margin-left: 20rpx;
  300. display: flex;
  301. padding-bottom: 40rpx;
  302. border-bottom: 1rpx solid #E1E1E1;
  303. }
  304. .bigRoom {
  305. margin-left: 20rpx;
  306. width: 100%;
  307. height: 102rpx;
  308. display: flex;
  309. // justify-content: center;
  310. align-items: center;
  311. }
  312. .shelves {
  313. width: 695rpx;
  314. height: 102rpx;
  315. background-color: #fff;
  316. margin-top: 20rpx;
  317. border-radius: 10rpx;
  318. display: flex;
  319. justify-content: space-between;
  320. align-items: center;
  321. // padding-left: 30rpx;
  322. // padding-right: 30rpx;
  323. }
  324. .uploadPic {
  325. padding-top: 28rpx;
  326. width: 690rpx;
  327. // height: 293rpx;
  328. background-color: #fff;
  329. border-radius: 10rpx;
  330. margin-top: 20rpx;
  331. }
  332. .pic {
  333. // margin-left: 30rpx;
  334. // margin-top: 20rpx;
  335. // width: 190rpx;
  336. // height: 120rpx;
  337. margin: 20rpx 30rpx;
  338. padding-bottom: 20rpx;
  339. }
  340. // .custom-upload-button{
  341. // width: 190rpx;
  342. // height: 120rpx;
  343. // }
  344. .priceInfo {
  345. width: 690rpx;
  346. // height: 908rpx;
  347. background-color: #fff;
  348. border-radius: 10rpx;
  349. margin-top: 20rpx;
  350. padding-top: 30rpx;
  351. }
  352. .week {
  353. padding-left: 30rpx;
  354. padding-right: 30rpx;
  355. margin-bottom: 20rpx;
  356. }
  357. .weekend {
  358. display: flex;
  359. justify-content: space-between;
  360. border-bottom: 1rpx solid #E1E1E1;
  361. padding-bottom: 30rpx;
  362. }
  363. .everyDay {
  364. padding-left: 30rpx;
  365. padding-right: 30rpx;
  366. width: 100%;
  367. // background-color: pink;
  368. height: 102rpx;
  369. display: flex;
  370. align-items: center;
  371. }
  372. .days {
  373. display: flex;
  374. align-items: center;
  375. border-bottom: 1rpx solid #E1E1E1;
  376. padding-bottom: 30rpx;
  377. }
  378. .priceBoxWeek {
  379. display: flex;
  380. align-items: center;
  381. padding-left: 30rpx;
  382. padding-right: 30rpx;
  383. }
  384. .weekendBox {
  385. width: 630rpx;
  386. display: flex;
  387. align-items: center;
  388. // margin-right: 90rpx;
  389. // justify-content: space-between;
  390. border-bottom: 1rpx solid #E1E1E1;
  391. height: 102rpx;
  392. overflow: hidden;
  393. box-sizing: border-box;
  394. }
  395. .everyHouseList {
  396. // padding-right: 30rpx;
  397. width: 690rpx;
  398. // height: 908rpx;
  399. background-color: #fff;
  400. border-radius: 10rpx;
  401. margin-top: 20rpx;
  402. // padding-top: 30rpx;
  403. }
  404. .HouseListTitleInfo {
  405. margin-right: 30rpx;
  406. margin-left: 20rpx;
  407. margin-bottom: 40rpx;
  408. display: flex;
  409. justify-content: space-between;
  410. }
  411. .submit {
  412. margin-top: 20rpx;
  413. border-radius: 10rpx;
  414. width: 690rpx;
  415. height: 102rpx;
  416. background-color: #fff;
  417. display: flex;
  418. justify-content: center;
  419. align-items: center;
  420. }
  421. .addSubmit {
  422. width: 100%;
  423. position: fixed;
  424. /* 固定定位 */
  425. bottom: 20rpx;
  426. /* 底部对齐 */
  427. left: 0;
  428. /* 可选:左对齐 */
  429. // width: 690rpx;
  430. /* 可选:宽度为 100% */
  431. height: 96rpx;
  432. margin-left: 30rpx;
  433. // padding-top: 20rpx;
  434. margin-top: 30rpx;
  435. background-color: #1372FF;
  436. border-radius: 48rpx;
  437. }
  438. .uploadPicPic {
  439. position: relative;
  440. top: -96rpx;
  441. }
  442. .u-upload__deletable[data-v-69e2a36e] {
  443. width: 0 !important;
  444. }
  445. </style>