room.vue 5.0 KB

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