room.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view>
  3. <view class="list">
  4. <view class="r_item" v-for="(it, index) in list" :key="index" @click="popup(it)">
  5. <view class="lef"><image :src="ip + it.pic[0]" mode="aspectFill" class="pic"></image></view>
  6. <view class="con">
  7. <view class="title omit">{{ it.title }}</view>
  8. <view class="ms">
  9. <text class="rmb">¥{{ it.price }}</text>
  10. <text>起</text>
  11. </view>
  12. <view class="ms">共有{{ it.nums }}间</view>
  13. <view class="btn" @click.stop="del(it)">删除</view>
  14. </view>
  15. <view class="clear"></view>
  16. </view>
  17. </view>
  18. <view class="noLogin">
  19. <image class="u-error-icon" src="../../../static/sj.png" mode="widthFix" v-if="list.length == 0"></image>
  20. <view class="dll" @click="popup()">添加房间</view>
  21. </view>
  22. <!--添加房间信息-->
  23. <u-popup v-model="popup_show" :mask-close-able="false" mode="center" border-radius="14" width="90%" height="auto" :closeable="true">
  24. <view class="u-popup">
  25. <view class="tttt" style="font-weight: bolder;">{{ popup_title }}</view>
  26. <view class="form_group hr">
  27. <view class="lable">房间名称</view>
  28. <input placeholder="例如单人房" v-model="item.title" />
  29. </view>
  30. <view class="form_group hr">
  31. <view class="lable">房价价格</view>
  32. <input type="number" placeholder="每晚价格" v-model="item.price" />
  33. </view>
  34. <view class="form_group hr">
  35. <view class="lable">房间数量</view>
  36. <input type="number" placeholder="请输入房间数量" v-model="item.nums" />
  37. </view>
  38. <view class="form_group"><view class="lable">房间图片</view></view>
  39. <view class="pl5" v-if="popup_show">
  40. <u-upload
  41. :ip="ip"
  42. :action="upload.action"
  43. :header="upload.header"
  44. :size-type="upload.size"
  45. :max-count="upload.count"
  46. :name="upload.name"
  47. :file-list="item.pic"
  48. ref="pic"
  49. width="140"
  50. height="140"
  51. ></u-upload>
  52. </view>
  53. <button class="btn" @click="add()">保存</button>
  54. </view>
  55. </u-popup>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. ip: this.$http.urls.ip,
  63. list: [],
  64. item: {},
  65. popup_show: false,
  66. popup_title: '添加房间',
  67. shopId: '',
  68. upload: {
  69. header: { apiToken: this.$getUser().apiToken },
  70. name: 'img',
  71. action: this.$http.urls.uploadImg,
  72. size_type: 'compressed ',
  73. count: 1
  74. }
  75. };
  76. },
  77. onLoad(e) {
  78. this.shopId = e.shopId;
  79. this.getData();
  80. },
  81. methods: {
  82. //获取数据
  83. getData() {
  84. this.$http.request({
  85. url: this.$http.urls.roomList,
  86. data: { shopId: this.shopId },
  87. success: res => {
  88. console.log("zx:"+JSON.stringify(res));
  89. this.list = res.data.data;
  90. this.list.forEach(item => {
  91. item.pic = item.pic.split(',');
  92. });
  93. this.$forceUpdate();
  94. }
  95. });
  96. },
  97. popup(item) {
  98. if (item) {
  99. item = JSON.stringify(item);
  100. this.item = JSON.parse(item);
  101. this.popup_title = '编辑房间';
  102. } else {
  103. this.item = {};
  104. }
  105. this.popup_show = true;
  106. },
  107. add() {
  108. let pic = this.$refs.pic.lists.filter(val => {
  109. return val.progress == 100;
  110. });
  111. pic.forEach(item => {
  112. if (item.response) {
  113. this.item.pic = item.response.fileName; //获取上传成功的网络地址
  114. } else {
  115. this.item.pic = item.url; //原来的地址
  116. }
  117. });
  118. let rule = [
  119. { name: 'title', checkType: 'notnull', errorMsg: '请输入房间名称' },
  120. { name: 'price', checkType: 'notnull', errorMsg: '请输入房间价格' },
  121. { name: 'nums', checkType: 'notnull', errorMsg: '请输入房间数量' },
  122. { name: 'pic', checkType: 'notnull', errorMsg: '请上传一张房间图片' }
  123. ];
  124. if (!this.$verify.check(this.item, rule)) {
  125. uni.showModal({ content: this.$verify.error, showCancel: false });
  126. return;
  127. }
  128. this.item.shopId = this.shopId;
  129. this.$http.request({
  130. method: 'POST',
  131. url: this.$http.urls.roomAdd,
  132. data: this.item,
  133. success: res => {
  134. uni.showToast({ title: '添加成功' });
  135. this.popup_show = false;
  136. this.getData();
  137. }
  138. });
  139. },
  140. del(item) {
  141. uni.showModal({
  142. title: '提示',
  143. content: '是否删除该房间?',
  144. success: res => {
  145. if (res.confirm) {
  146. this.$http.request({
  147. url: this.$http.urls.roomDel,
  148. data: { id: item.id },
  149. success: res => {
  150. uni.showToast({ title: '删除成功' });
  151. this.list.splice(this.list.indexOf(item), 1);
  152. }
  153. });
  154. }
  155. }
  156. });
  157. }
  158. }
  159. };
  160. </script>
  161. <style lang="scss">
  162. .list {
  163. padding: 0px 10px 70px 10px;
  164. .r_item {
  165. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0);
  166. border-radius: 0px;
  167. .btn {
  168. float: right;
  169. margin-top: -54px;
  170. padding: 5px 25px;
  171. border-radius: 20px;
  172. background-color: orange;
  173. margin-right: -34px;
  174. }
  175. }
  176. }
  177. .noLogin {
  178. margin-top: -40px;
  179. }
  180. </style>