add.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <template>
  2. <view class='content'>
  3. <view class='wrap'>
  4. <u--form labelPosition="left" :model="form" ref="uForm">
  5. <u-form-item labelWidth='240' labelPosition='top' label="上传民宿图片">
  6. <u-upload :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic" name="1" multiple
  7. :maxCount="20">
  8. </u-upload>
  9. </u-form-item>
  10. <u-form-item labelWidth='120' labelPosition='left' label="标题">
  11. <u--input minlength='6' maxlength='30' inputAlign='right' v-model="form.title" placeholder="输入标题,6-30个字" border="none"></u--input>
  12. </u-form-item>
  13. <u-form-item labelWidth='150' labelPosition='top' label="详细介绍(选填)">
  14. <u--textarea maxlength='1000' v-model="form.detailedIntroduction" autoHeight placeholder="输入房源介绍,0-1000个字" ></u--textarea>
  15. </u-form-item>
  16. <u-form-item labelWidth='120' labelPosition='left' label="单价(元/晚)">
  17. <u--input inputAlign='right' type='digit' v-model="form.price" placeholder="输入单价" border="none"></u--input>
  18. </u-form-item>
  19. <u-form-item labelWidth='120' labelPosition='left' label="户型">
  20. <view class='flex'>
  21. <view class='flex'>
  22. <u--input inputAlign='right' type='digit' v-model="room" placeholder="输入" border="none"></u--input>
  23. <view>室</view>
  24. </view>
  25. <view class='flex'>
  26. <u--input inputAlign='right' type='digit' v-model="hall" placeholder="输入" border="none"></u--input>
  27. <view>厅</view>
  28. </view>
  29. <view class='flex'>
  30. <u--input inputAlign='right' type='digit' v-model="toilet" placeholder="输入" border="none"></u--input>
  31. <view>卫</view>
  32. </view>
  33. </view>
  34. </u-form-item>
  35. <u-form-item labelWidth='120' labelPosition='left' label="床铺数量">
  36. <u--input inputAlign='right' type='digit' v-model="form.bedNum" placeholder="输入床铺数量" border="none"></u--input>
  37. </u-form-item>
  38. <u-form-item labelWidth='120' labelPosition='left' label="最多可住人数">
  39. <u--input inputAlign='right' type='digit' v-model="form.mostPeople" placeholder="输入最多可住人数" border="none"></u--input>
  40. </u-form-item>
  41. <u-form-item labelWidth='120' labelPosition='left' label="面积(平米)">
  42. <u--input inputAlign='right' type='digit' v-model="form.decorationArea" placeholder="输入房屋面积" border="none"></u--input>
  43. </u-form-item>
  44. <u-form-item labelWidth='120' labelPosition='left' @click='placeSelect(),hideKeyboard()' label="房源位置">
  45. <view style='text-align:right;' v-if="form.province">{{ form.province }}{{ form.city }}{{ form.area }}</view>
  46. <view style='text-align:right;' v-else>
  47. <text style='text-align:right;'>选择房源位置 </text>
  48. <image src="@/static/image/yjt.png" mode=""
  49. style="margin-left:10rpx;width:12rpx;height: 21rpx;"></image>
  50. </view>
  51. </u-form-item>
  52. <u-form-item labelWidth='80' labelPosition='left' label="详细地址">
  53. <u-input inputAlign='right' maxlength="15" border='none' placeholder='输入详细地址,不超过15个字' v-model="form.detailedAddress" />
  54. </u-form-item>
  55. <u-form-item labelWidth='120' labelPosition='top' label="房源特色">
  56. <view class="flex">
  57. <u--input v-for='item in labelList' inputAlign='right' v-model="item.value" placeholder="输入房源特色" border="none"></u--input>
  58. </view>
  59. </u-form-item>
  60. </u--form>
  61. <view>
  62. <view class='flex justify-space-between'>
  63. <view style='width:25%;'>服务</view>
  64. <view style='width:25%;'></view>
  65. <view style='width:25%;'></view>
  66. <view class='checkall'>
  67. <u-checkbox-group
  68. v-model="checkboxValue1"
  69. placement="column"
  70. @change="checkboxChange1"
  71. >
  72. <u-checkbox
  73. :customStyle="{marginBottom: '8px'}"
  74. :checked='checked1'
  75. label='全选'
  76. name="全选"
  77. >
  78. </u-checkbox>
  79. </u-checkbox-group>
  80. </view>
  81. </view>
  82. <view class='more'>
  83. <u-checkbox-group
  84. v-model="checkList1"
  85. placement="row"
  86. @change="checkboxChange1"
  87. >
  88. <u-checkbox
  89. :customStyle="{marginBottom: '8px'}"
  90. v-for="(item, index) in checkboxList1"
  91. :key="index"
  92. :checked='item.checked'
  93. :label="item.name"
  94. :name="item.name"
  95. >
  96. </u-checkbox>
  97. </u-checkbox-group>
  98. </view>
  99. </view>
  100. <view>
  101. <view class='flex justify-space-between'>
  102. <view style='width:25%;'>家居</view>
  103. <view style='width:25%;'></view>
  104. <view style='width:25%;'></view>
  105. <view class='checkall'>
  106. <u-checkbox-group
  107. v-model="checkboxValue2"
  108. placement="column"
  109. @change="checkboxChange2"
  110. >
  111. <u-checkbox
  112. :customStyle="{marginBottom: '8px'}"
  113. :checked='checked2'
  114. label='全选'
  115. name="全选"
  116. >
  117. </u-checkbox>
  118. </u-checkbox-group>
  119. </view>
  120. </view>
  121. <view class='more'>
  122. <u-checkbox-group
  123. v-model="checkList2"
  124. placement="row"
  125. @change="checkboxChange2"
  126. >
  127. <u-checkbox
  128. :customStyle="{marginBottom: '8px'}"
  129. v-for="(item, index) in checkboxList2"
  130. :key="index"
  131. :checked='item.checked'
  132. :label="item.name"
  133. :name="item.name"
  134. >
  135. </u-checkbox>
  136. </u-checkbox-group>
  137. </view>
  138. </view>
  139. <view>
  140. <view class='flex justify-space-between'>
  141. <view style='width:25%;'>卫浴</view>
  142. <view style='width:25%;'></view>
  143. <view style='width:25%;'></view>
  144. <view class='checkall'>
  145. <u-checkbox-group
  146. v-model="checkboxValue3"
  147. placement="column"
  148. @change="checkboxChange3"
  149. >
  150. <u-checkbox
  151. :customStyle="{marginBottom: '8px'}"
  152. :checked='checked3'
  153. label='全选'
  154. name="全选"
  155. >
  156. </u-checkbox>
  157. </u-checkbox-group>
  158. </view>
  159. </view>
  160. <view class='more'>
  161. <u-checkbox-group
  162. v-model="checkList3"
  163. placement="row"
  164. @change="checkboxChange3"
  165. >
  166. <u-checkbox
  167. :customStyle="{marginBottom: '8px'}"
  168. v-for="(item, index) in checkboxList3"
  169. :key="index"
  170. :checked='item.checked'
  171. :label="item.name"
  172. :name="item.name"
  173. >
  174. </u-checkbox>
  175. </u-checkbox-group>
  176. </view>
  177. </view>
  178. <view>
  179. <view class='flex justify-space-between'>
  180. <view style='width:25%;'>餐厨</view>
  181. <view style='width:25%;'></view>
  182. <view style='width:25%;'></view>
  183. <view class='checkall'>
  184. <u-checkbox-group
  185. v-model="checkboxValue4"
  186. placement="column"
  187. @change="checkboxChange4"
  188. >
  189. <u-checkbox
  190. :customStyle="{marginBottom: '8px'}"
  191. :checked='checked4'
  192. label='全选'
  193. name="全选"
  194. >
  195. </u-checkbox>
  196. </u-checkbox-group>
  197. </view>
  198. </view>
  199. <view class='more'>
  200. <u-checkbox-group
  201. v-model="checkList4"
  202. placement="row"
  203. @change="checkboxChange4"
  204. >
  205. <u-checkbox
  206. :customStyle="{marginBottom: '8px'}"
  207. v-for="(item, index) in checkboxList4"
  208. :key="index"
  209. :checked='item.checked'
  210. :label="item.name"
  211. :name="item.name"
  212. >
  213. </u-checkbox>
  214. </u-checkbox-group>
  215. </view>
  216. </view>
  217. <view>
  218. <view class='flex justify-space-between'>
  219. <view style='width:25%;'>建筑</view>
  220. <view style='width:25%;'></view>
  221. <view style='width:25%;'></view>
  222. <view class='checkall'>
  223. <u-checkbox-group
  224. v-model="checkboxValue5"
  225. placement="column"
  226. @change="checkboxChange5"
  227. >
  228. <u-checkbox
  229. :customStyle="{marginBottom: '8px'}"
  230. :checked='checked5'
  231. label='全选'
  232. name="全选"
  233. >
  234. </u-checkbox>
  235. </u-checkbox-group>
  236. </view>
  237. </view>
  238. <view class='more'>
  239. <u-checkbox-group
  240. v-model="checkList5"
  241. placement="row"
  242. @change="checkboxChange5"
  243. >
  244. <u-checkbox
  245. :customStyle="{marginBottom: '8px'}"
  246. v-for="(item, index) in checkboxList5"
  247. :key="index"
  248. :checked='item.checked'
  249. :label="item.name"
  250. :name="item.name"
  251. >
  252. </u-checkbox>
  253. </u-checkbox-group>
  254. </view>
  255. </view>
  256. </view>
  257. <view class="mercharts_footer">
  258. <button @click='submit' class="submit">提交</button>
  259. </view>
  260. <u-modal :show="isSubmit" content='确定添加民宿信息?' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
  261. @cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
  262. </view>
  263. </template>
  264. <script>
  265. var that
  266. import uploadImage from '@/components/ossutil/uploadFile.js';
  267. export default {
  268. data() {
  269. return {
  270. form:{},
  271. homestayImageArray:[],
  272. fileList1:[],
  273. checked1:false,
  274. checked2:false,
  275. checked3:false,
  276. checked4:false,
  277. checked5:false,
  278. room:'',
  279. hall:'',
  280. toilet:'',
  281. isSubmit:false,
  282. currectData:{},
  283. labelList:[{value:''},{value:''},{value:''},{value:''}],
  284. checkList1:[],
  285. checkList2:[],
  286. checkList3:[],
  287. checkList4:[],
  288. checkList5:[],
  289. checkboxValue1:'',
  290. checkboxValue2:'',
  291. checkboxValue3:'',
  292. checkboxValue4:'',
  293. checkboxValue5:'',
  294. checkboxList1:[{name:'行李寄存',checked:false},{name:'可长租',checked:false},{name:'自助入住',checked:false},{name:'免费停车',checked:false}],
  295. checkboxList2:[{name:'电视',checked:false},{name:'洗衣机',checked:false},{name:'冰箱',checked:false},{name:'空调',checked:false}
  296. ,{name:'热水壶',checked:false},{name:'免费wifi',checked:false}],
  297. checkboxList3:[{name:'吹风机',checked:false},{name:'洗发水',checked:false},{name:'沐浴露',checked:false},{name:'独立卫浴',checked:false}
  298. ,{name:'拖鞋',checked:false},{name:'牙具',checked:false},{name:'毛巾',checked:false},{name:'浴巾',checked:false},{name:'纸巾',checked:false},
  299. {name:'热水淋浴',checked:false},{name:'香皂',checked:false}],
  300. checkboxList4:[{name:'餐具',checked:false},{name:'锅具',checked:false},{name:'调料',checked:false},{name:'电磁炉',checked:false}
  301. ,{name:'天然气',checked:false},{name:'刀具',checked:false},{name:'菜板',checked:false},{name:'汤勺',checked:false}],
  302. checkboxList5:[{name:'电梯',checked:false},{name:'窗户',checked:false},{name:'落地窗',checked:false},{name:'海景',checked:false}],
  303. }
  304. },
  305. onLoad() {
  306. that = this
  307. },
  308. async onShow() {
  309. this.currectData=await this.getHomestayId()
  310. console.log(this.currectData)
  311. this.form.homestayId = this.currectData.id
  312. },
  313. methods: {
  314. // 删除图片
  315. deletePic(event,status) {
  316. this[`fileList${event.name}`].splice(event.index, 1)
  317. },
  318. // 新增图片
  319. async afterRead(event,status) {
  320. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  321. let lists = [].concat(event.file)
  322. let fileListLen = this[`fileList${event.name}`].length
  323. lists.map((item) => {
  324. this[`fileList${event.name}`].push({
  325. ...item,
  326. status: 'uploading',
  327. message: '上传中'
  328. })
  329. })
  330. for (let i = 0; i < lists.length; i++) {
  331. const result = await this.uploadFilePromise(lists[i].url,status)
  332. let item = this[`fileList${event.name}`][fileListLen]
  333. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  334. status: 'success',
  335. message: '',
  336. url: result
  337. }))
  338. fileListLen++
  339. console.log(that.form, this[`fileList${event.name}`])
  340. }
  341. },
  342. uploadFilePromise(res,status) {
  343. return new Promise((resolve, reject) => {
  344. uploadImage(res, 'cardImages/',
  345. result => {
  346. that.homestayImageArray.push(result)
  347. that.form.homestayImage = that.homestayImageArray.toString()
  348. resolve(res)
  349. }
  350. )
  351. })
  352. },
  353. confirmSubmit(){
  354. uni.showLoading({
  355. title: '加载中',
  356. mask: true
  357. })
  358. that.$request.baseRequest('admin.tourism.homestayDetailInfo', 'add',{
  359. homestayDetailInfo:JSON.stringify(this.form)
  360. }, failres => {
  361. uni.showToast({
  362. icon: "none",
  363. title: failres.errmsg,
  364. duration: 3000
  365. });
  366. uni.hideLoading()
  367. }).then(res => {
  368. this.isSubmit = false
  369. uni.showToast({
  370. icon: "success",
  371. title: '添加民宿成功',
  372. duration: 2000
  373. });
  374. })
  375. },
  376. getHomestayId(){
  377. return new Promise((resolve, reject) => {
  378. that.$request.baseRequest('admin.tourism.homestayInfo', 'list', {
  379. page:1,
  380. limit: 10,
  381. commonId:uni.getStorageSync("userInfo").id
  382. }, failres => {
  383. uni.showToast({
  384. icon: "none",
  385. title: failres.errmsg,
  386. duration: 3000
  387. });
  388. uni.hideLoading()
  389. }).then(res => {
  390. resolve(res.data.items[0])
  391. })
  392. })
  393. },
  394. submit(){
  395. var labeldata=this.labelList.filter((item)=>{return item.value!=''})
  396. var label=[]
  397. for(var i=0;i<labeldata.length;i++){
  398. label.push(labeldata[i].value)
  399. }
  400. this.form.label = label.toString()
  401. this.form.houseType=this.room+','+this.hall+','+this.toilet
  402. var list1=[],list2=[],list3=[],list4=[],list5=[]
  403. var data1=this.checkboxList1.filter((item)=>{return item.checked})
  404. var data2=this.checkboxList2.filter((item)=>{return item.checked})
  405. var data3=this.checkboxList3.filter((item)=>{return item.checked})
  406. var data4=this.checkboxList4.filter((item)=>{return item.checked})
  407. var data5=this.checkboxList5.filter((item)=>{return item.checked})
  408. if(data1.length>0){
  409. for(var i=0;i<data1.length;i++){
  410. list1.push(data1[i].name)
  411. }
  412. this.form.service=list1.toString()
  413. }
  414. if(data2.length>0){
  415. for(var i=0;i<data2.length;i++){
  416. list2.push(data2[i].name)
  417. }
  418. this.form.homeFurnishing=list2.toString()
  419. }
  420. if(data3.length>0){
  421. for(var i=0;i<data3.length;i++){
  422. list3.push(data3[i].name)
  423. }
  424. this.form.bathroom=list3.toString()
  425. }
  426. if(data4.length>0){
  427. for(var i=0;i<data4.length;i++){
  428. list4.push(data4[i].name)
  429. }
  430. this.form.kitchen=list4.toString()
  431. }
  432. if(data5.length>0){
  433. for(var i=0;i<data5.length;i++){
  434. list5.push(data5[i].name)
  435. }
  436. this.form.build=list5.toString()
  437. }
  438. this.isSubmit = true
  439. },
  440. checkboxChange1(e){
  441. var data=JSON.parse(JSON.stringify(e))
  442. this.$forceUpdate()
  443. if(e[0]){
  444. if(e[0]=='全选'){
  445. this.checkboxList1=this.checkboxList1.map((item)=>{
  446. item.checked = true
  447. return item})
  448. }else{
  449. this.checkboxList1=this.checkboxList1.map((item)=>{
  450. item.checked = false
  451. return item})
  452. for(var i=0;i<data.length;i++){
  453. var index=this.checkboxList1.findIndex((item)=>{return item.name==data[i]})
  454. if(index!=-1) this.checkboxList1[index].checked=true
  455. else this.checkboxList1[index].checked=false
  456. }
  457. if(this.checkboxList1.every((item)=>{return item.checked==true})==true){
  458. this.checked1=true
  459. }else{
  460. this.checked1=false
  461. }
  462. }
  463. }else{
  464. if(this.checkboxValue1){
  465. this.checkboxList1=this.checkboxList1.map((item)=>{
  466. item.checked = false
  467. return item})
  468. }
  469. }
  470. console.log(this.checkboxList1,this.checkList1)
  471. },
  472. checkboxChange2(e){
  473. var data=JSON.parse(JSON.stringify(e))
  474. this.$forceUpdate()
  475. if(e[0]){
  476. if(e[0]=='全选'){
  477. this.checkboxList2=this.checkboxList2.map((item)=>{
  478. item.checked = true
  479. return item})
  480. }else{
  481. this.checkboxList2=this.checkboxList2.map((item)=>{
  482. item.checked = false
  483. return item})
  484. for(var i=0;i<data.length;i++){
  485. var index=this.checkboxList2.findIndex((item)=>{return item.name==data[i]})
  486. if(index!=-1) this.checkboxList2[index].checked=true
  487. else this.checkboxList2[index].checked=false
  488. }
  489. if(this.checkboxList2.every((item)=>{return item.checked==true})==true){
  490. this.checked2=true
  491. }else{
  492. this.checked2=false
  493. }
  494. }
  495. }else{
  496. if(this.checkboxValue2){
  497. this.checkboxList2=this.checkboxList2.map((item)=>{
  498. item.checked = false
  499. return item})
  500. }
  501. }
  502. console.log(this.checkboxList2,this.checkList2)
  503. },
  504. checkboxChange3(e){
  505. var data=JSON.parse(JSON.stringify(e))
  506. this.$forceUpdate()
  507. if(e[0]){
  508. if(e[0]=='全选'){
  509. this.checkboxList3=this.checkboxList3.map((item)=>{
  510. item.checked = true
  511. return item})
  512. }else{
  513. this.checkboxList3=this.checkboxList3.map((item)=>{
  514. item.checked = false
  515. return item})
  516. for(var i=0;i<data.length;i++){
  517. var index=this.checkboxList3.findIndex((item)=>{return item.name==data[i]})
  518. if(index!=-1) this.checkboxList3[index].checked=true
  519. else this.checkboxList3[index].checked=false
  520. }
  521. if(this.checkboxList3.every((item)=>{return item.checked==true})==true){
  522. this.checked3=true
  523. }else{
  524. this.checked3=false
  525. }
  526. }
  527. }else{
  528. if(this.checkboxValue3){
  529. this.checkboxList3=this.checkboxList3.map((item)=>{
  530. item.checked = false
  531. return item})
  532. }
  533. }
  534. console.log(this.checkboxList3,this.checkList3)
  535. },
  536. checkboxChange4(e){
  537. var data=JSON.parse(JSON.stringify(e))
  538. this.$forceUpdate()
  539. if(e[0]){
  540. if(e[0]=='全选'){
  541. this.checkboxList4=this.checkboxList4.map((item)=>{
  542. item.checked = true
  543. return item})
  544. }else{
  545. this.checkboxList4=this.checkboxList4.map((item)=>{
  546. item.checked = false
  547. return item})
  548. for(var i=0;i<data.length;i++){
  549. var index=this.checkboxList4.findIndex((item)=>{return item.name==data[i]})
  550. if(index!=-1) this.checkboxList4[index].checked=true
  551. else this.checkboxList4[index].checked=false
  552. }
  553. if(this.checkboxList4.every((item)=>{return item.checked==true})==true){
  554. this.checked4=true
  555. }else{
  556. this.checked4=false
  557. }
  558. }
  559. }else{
  560. if(this.checkboxValue4){
  561. this.checkboxList4=this.checkboxList4.map((item)=>{
  562. item.checked = false
  563. return item})
  564. }
  565. }
  566. console.log(this.checkboxList4,this.checkList4)
  567. },
  568. checkboxChange5(e){
  569. var data=JSON.parse(JSON.stringify(e))
  570. this.$forceUpdate()
  571. if(e[0]){
  572. if(e[0]=='全选'){
  573. this.checkboxList5=this.checkboxList5.map((item)=>{
  574. item.checked = true
  575. return item})
  576. }else{
  577. this.checkboxList5=this.checkboxList5.map((item)=>{
  578. item.checked = false
  579. return item})
  580. for(var i=0;i<data.length;i++){
  581. var index=this.checkboxList5.findIndex((item)=>{return item.name==data[i]})
  582. if(index!=-1) this.checkboxList5[index].checked=true
  583. else this.checkboxList5[index].checked=false
  584. }
  585. if(this.checkboxList5.every((item)=>{return item.checked==true})==true){
  586. this.checked5=true
  587. }else{
  588. this.checked5=false
  589. }
  590. }
  591. }else{
  592. if(this.checkboxValue1){
  593. this.checkboxList1=this.checkboxList1.map((item)=>{
  594. item.checked = false
  595. return item})
  596. }
  597. }
  598. console.log(this.checkboxList5,this.checkList5)
  599. },
  600. placeSelect() {
  601. uni.chooseLocation({
  602. success: function(res) {
  603. console.log(res);
  604. that.form.location = res.latitude + ',' + res.longitude
  605. let _address = that.$helper.formatLocation(res.address)
  606. console.log(_address)
  607. that.form.province = _address.Province
  608. that.form.city = _address.City
  609. that.form.area = _address.Country
  610. that.form.detailedAddress = _address.Village
  611. that.$forceUpdate()
  612. }
  613. });
  614. },
  615. hideKeyboard() {
  616. uni.hideKeyboard()
  617. },
  618. }
  619. }
  620. </script>
  621. <style lang='scss' scoped>
  622. /deep/.u-checkbox-group{
  623. flex-wrap: wrap;
  624. }
  625. .checkall{
  626. width:25%;
  627. }
  628. /* .checkall /deep/.u-checkbox-group{
  629. padding-right: 9vw;
  630. } */
  631. .more /deep/.u-checkbox-group .u-checkbox{
  632. width:25%;
  633. }
  634. </style>