酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

424 rivejä
17 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <!-- import CSS -->
  6. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  7. </head>
  8. <body>
  9. <div id="app" class="table">
  10. <div>
  11. <div class="header-search">
  12. <span>ID:</span>
  13. <el-input v-model="search.id" style="width: 120px;" placeholder="请输入内容"></el-input>
  14. <span>名称:</span>
  15. <el-input v-model="search.hotel_name" style="width: 120px;" placeholder="请输入内容"></el-input>
  16. <span>省份</span>
  17. <el-select v-model="search.province" placeholder="请选择" style="width: 120px;" clearable>
  18. <el-option
  19. v-for="item in province"
  20. :key="item.value"
  21. :label="item.name"
  22. :value="item.value">
  23. </el-option>
  24. </el-select>
  25. <span>市</span>
  26. <el-select v-model="search.city" placeholder="请选择" style="width: 120px;" clearable>
  27. <el-option
  28. v-for="item in city"
  29. :key="item.value"
  30. :label="item.name"
  31. :value="item.value">
  32. </el-option>
  33. </el-select>
  34. <span>区</span>
  35. <el-select v-model="search.area" placeholder="请选择" style="width: 120px;" clearable>
  36. <el-option
  37. v-for="item in area"
  38. :key="item.value"
  39. :label="item.name"
  40. :value="item.value">
  41. </el-option>
  42. </el-select>
  43. <el-button type="primary" icon="el-icon-search" @click="getData(1)">搜索</el-button>
  44. <el-button type="primary" icon="el-icon-plus" @click="edit(null)">新增</el-button>
  45. </div>
  46. <el-table ref="multipleTable" :data="tableData" border tooltip-effect="dark"
  47. style="font-size:12px;width: 100%;margin-top: 12px">
  48. <el-table-column prop="id" label="酒店ID" min-width="50"></el-table-column>
  49. <el-table-column prop="hotel_name" label="名称" min-width="180"></el-table-column>
  50. <el-table-column prop="province_name" label="省" min-width="90"></el-table-column>
  51. <el-table-column prop="city_name" label="市" min-width="90"></el-table-column>
  52. <el-table-column prop="area_name" label="区" min-width="90"></el-table-column>
  53. <el-table-column prop="detail_address" label="详细地址" min-width="250"></el-table-column>
  54. <el-table-column prop="create_time" label="创建时间" min-width="80"></el-table-column>
  55. <el-table-column prop="update_time" label="更新时间" min-width="80"></el-table-column>
  56. <el-table-column label="操作" min-width="180">
  57. <template slot-scope="scope">
  58. <el-button-group>
  59. <el-button type="primary" size="mini" @click="edit(scope.row)" icon="el-icon-edit">编辑</el-button>
  60. <el-button type="danger" size="mini" icon="el-icon-delete" @click="delAll(scope.row.id)">删除</el-button>
  61. </el-button-group>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <el-pagination
  66. :page-size="search.pageSize"
  67. :pager-count="11"
  68. layout="total, sizes, prev, pager, next, jumper"
  69. :total="total"
  70. :current-page="search.pageNum"
  71. :page-sizes="[10, 20, 30, 40, 50]"
  72. @size-change="sizeChange"
  73. @current-change="getData"
  74. @prev-click="getData"
  75. @next-click="getData"
  76. ></el-pagination>
  77. </div>
  78. <transition name="bounce" v-if="editShow">
  79. <el-dialog title="详情" :visible.sync="editShow" width="90%" top="15px">
  80. <el-form ref="form" label-width="100px" style="width: 100%;padding-bottom: 20px">
  81. <div style="display: flex;width: 100%">
  82. <el-form-item v-if="editType" label="ID:" style="width: 80%">
  83. <div v-html="editData.id"></div>
  84. </el-form-item>
  85. </div>
  86. <div>
  87. <el-form-item label="名称:" style="width: 80%">
  88. <el-input v-model="editData.hotel_name" style="width: 280px;" placeholder="请输入内容"></el-input>
  89. </el-form-item>
  90. </div>
  91. <div style="display: flex">
  92. <el-form-item label="省:" >
  93. <el-select v-model="editData.province" placeholder="请选择" style="width: 120px;" clearable>
  94. <el-option v-for="item in province" :key="item.value" :label="item.name" :value="item.value"></el-option>
  95. </el-select>
  96. </el-form-item>
  97. <el-form-item label="市:" >
  98. <el-select v-model="editData.city" placeholder="请选择" style="width: 120px;" clearable>
  99. <el-option v-for="item in edit_city" :key="item.value" :label="item.name" :value="item.value"></el-option>
  100. </el-select>
  101. </el-form-item>
  102. <el-form-item label="区:" >
  103. <el-select v-model="editData.area" placeholder="请选择" style="width: 120px;" clearable>
  104. <el-option v-for="item in edit_area" :key="item.value" :label="item.name" :value="item.value"></el-option>
  105. </el-select>
  106. </el-form-item>
  107. </div>
  108. <div>
  109. <el-form-item label="详细地址:" style="width: 80%">
  110. <el-input v-model="editData.detail_address" style="width: 580px;" placeholder="请输入内容"></el-input>
  111. </el-form-item>
  112. </div>
  113. <div>
  114. <el-button type="primary" @click="editDoing()" >保存</el-button>
  115. </div>
  116. </el-form>
  117. </el-dialog>
  118. </transition>
  119. </div>
  120. </body>
  121. <!-- import Vue before Element -->
  122. <script src="/assets/js/vue/vue.js"></script>
  123. <!-- import JavaScript -->
  124. <script src="/assets/js/vue/index.js"></script>
  125. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  126. <script>
  127. new Vue({
  128. el: '#app',
  129. data: function () {
  130. return {
  131. search: {
  132. id:"",
  133. hotel_name: "",
  134. hotel_phone: "",
  135. province:"",
  136. city:"",
  137. area: "",
  138. pageSize:10,
  139. pageNum: 1
  140. },
  141. total: 0,
  142. tableData: [],
  143. editShow: false,
  144. editType: false,
  145. editData: {
  146. },
  147. province: [],
  148. city: [],
  149. area:[],
  150. edit_city_set:3,
  151. edit_city: [],
  152. edit_area:[],
  153. }
  154. },
  155. created() {
  156. this.getProvince();
  157. this.getData(1)
  158. },
  159. watch: {
  160. "search.province" : function (newVal,oldVal){
  161. this.city = []
  162. this.area = []
  163. this.search.city=""
  164. this.search.area=""
  165. if (newVal==''){
  166. return false;
  167. }
  168. let row = {
  169. "province":newVal
  170. }
  171. axios.post("/hotel.php/ajax/areaList", row).then((response) => {
  172. let data = response.data;
  173. if (data.flag) {
  174. this.city = data.data;
  175. } else {
  176. this.$message.error(data.msg);
  177. }
  178. }).catch(function (error) {
  179. console.log(error);
  180. });
  181. },
  182. "search.city" : function (newVal,oldVal){
  183. this.area = []
  184. this.search.area=""
  185. if (newVal == "") {
  186. return false;
  187. }
  188. let row = {
  189. province:this.search.province,
  190. city:newVal
  191. }
  192. axios.post("/hotel.php/ajax/areaList", row).then((response) => {
  193. let data = response.data;
  194. if (data.flag) {
  195. this.area = data.data;
  196. } else {
  197. this.$message.error(data.msg);
  198. }
  199. }).catch(function (error) {
  200. console.log(error);
  201. });
  202. },
  203. "editData.province" : function (newVal,oldVal){
  204. if (this.edit_city_set==3) {
  205. this.edit_city = []
  206. this.edit_area = []
  207. this.editData.city=""
  208. this.editData.area=""
  209. }
  210. if (newVal==''){
  211. return false;
  212. }
  213. let row = {
  214. "province":newVal
  215. }
  216. axios.post("/hotel.php/ajax/areaList", row).then((response) => {
  217. let data = response.data;
  218. if (data.flag) {
  219. this.edit_city = data.data;
  220. this.edit_city_set++;
  221. } else {
  222. this.$message.error(data.msg);
  223. }
  224. }).catch(function (error) {
  225. console.log(error);
  226. });
  227. },
  228. "editData.city" : function (newVal,oldVal){
  229. if (this.edit_city_set==3) {
  230. this.edit_area = []
  231. this.editData.area=""
  232. }
  233. if (newVal == "") {
  234. return false;
  235. }
  236. let row = {
  237. province:this.editData.province,
  238. city:newVal
  239. }
  240. axios.post("/hotel.php/ajax/areaList", row).then((response) => {
  241. let data = response.data;
  242. if (data.flag) {
  243. this.edit_area = data.data;
  244. this.edit_city_set++;
  245. } else {
  246. this.$message.error(data.msg);
  247. }
  248. }).catch(function (error) {
  249. console.log(error);
  250. });
  251. }
  252. },
  253. methods: {
  254. getProvince(){
  255. axios.post("/hotel.php/ajax/areaList", {}).then((response) => {
  256. let data = response.data;
  257. if (data.flag) {
  258. this.province = data.data;
  259. } else {
  260. this.$message.error(data.msg);
  261. }
  262. }).catch(function (error) {
  263. console.log(error);
  264. });
  265. },
  266. sizeChange(pageSize) {
  267. this.search.pageSize = pageSize;
  268. this.getData(this.search.pageNum)
  269. },
  270. //獲取列表
  271. getData(page) {
  272. this.search.pageNum = page;
  273. axios.post("/hotel.php/cf_hotel_info/getList", this.search).then((response) => {
  274. let data = response.data;
  275. if (data.flag) {
  276. this.tableData = data.data.list;
  277. this.total = data.data.total;
  278. } else {
  279. this.$message.error(response.msg);
  280. }
  281. }).catch(function (error) {
  282. console.log(error);
  283. });
  284. },
  285. edit(info) {
  286. if (info == null) {
  287. this.editType = false;
  288. this.editData = {
  289. hotel_name: "",
  290. hotel_phone: "",
  291. province:"",
  292. city:"",
  293. area: "",
  294. detail_address:""
  295. }
  296. } else {
  297. this.edit_city_set = 1;
  298. this.editType = true;
  299. this.editData = {
  300. id:info.id,
  301. hotel_name: info.hotel_name,
  302. hotel_phone: info.hotel_phone,
  303. province:info.province,
  304. province_name:info.province_name,
  305. city:info.city,
  306. city_name:info.city_name,
  307. area: info.area,
  308. area_name:info.area_name,
  309. detail_address:info.detail_address
  310. }
  311. }
  312. this.editShow = true;
  313. },
  314. setAreaName(){
  315. for (let i = 0; i < this.province.length; i++) {
  316. if (this.province[i].value == this.editData.province) {
  317. this.editData.province_name = this.province[i].name;
  318. break
  319. }
  320. }
  321. for (let i = 0; i < this.edit_city.length; i++) {
  322. if (this.edit_city[i].value == this.editData.city) {
  323. this.editData.city_name = this.edit_city[i].name;
  324. break
  325. }
  326. }
  327. for (let i = 0; i < this.edit_area.length; i++) {
  328. if (this.edit_area[i].value == this.editData.area) {
  329. this.editData.area_name = this.edit_area[i].name;
  330. break;
  331. }
  332. }
  333. },
  334. editDoing(){
  335. if (this.editData.hotel_name==''){
  336. this.$message.error("名称不能为空");return false;
  337. }
  338. if (this.editData.province==''){
  339. this.$message.error("省不能为空");return false;
  340. }
  341. if (this.editData.city==''){
  342. this.$message.error("市不能为空");return false;
  343. }
  344. if (this.editData.area==''){
  345. this.$message.error("区不能为空");return false;
  346. }
  347. this.setAreaName();
  348. axios.post("/hotel.php/cf_hotel_info/save", this.editData).then( (response)=> {
  349. let data = response.data;
  350. console.log(this.tableData);
  351. if (data.flag) {
  352. this.$message.success("保存成功");
  353. this.editShow = false;
  354. this.getData(1);
  355. } else {
  356. this.$message.error(data.msg);
  357. }
  358. }).catch(function (error) {
  359. this.$message.error("保存失败");
  360. console.log(error);
  361. });
  362. },
  363. delAll(id){
  364. this.$confirm('确定删除酒店?', '提示', {
  365. confirmButtonText: '确定',
  366. cancelButtonText: '取消',
  367. type: 'warning'
  368. }).then(() => {
  369. let param = {
  370. id: id
  371. }
  372. axios.post("/hotel.php/cf_hotel_info/delAll", param).then((response) => {
  373. let data = response.data;
  374. if (data.flag) {
  375. this.getData(this.search.pageNum)
  376. this.$message.success("保存成功");
  377. } else {
  378. this.$message.error(response.msg);
  379. }
  380. }).catch(function (error) {
  381. console.log(error);
  382. });
  383. }).catch(() => {
  384. this.$message.info("已取消");
  385. this.getData(this.search.pageNum)
  386. })
  387. }
  388. }
  389. })
  390. </script>
  391. <style lang="scss" scoped>
  392. .el-table thead {
  393. background-color: #5a5e66 !important;
  394. }
  395. .header-search {
  396. font-size: 14px;
  397. font-weight: 900;
  398. }
  399. body {
  400. background-color: white;
  401. }
  402. .table {
  403. width: 100%;
  404. font-size: 12px;
  405. margin-top: 12px;
  406. background-color: white;
  407. }
  408. .el-form-item{
  409. margin-bottom: 5px !important;
  410. }
  411. </style>
  412. </html>