HotelData.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div>
  3. <div class="communal-list">
  4. <div class="communal-title">
  5. <div>酒店资料</div>
  6. <div class="communal-box">
  7. <el-input @input="Inquireclick()" placeholder="城市/名称/联系人" v-model="input" clearable
  8. style="width: 350px;">
  9. </el-input>
  10. <router-link to="/home/HotelDataOperation">
  11. <el-button type="primary" style="margin-left: 10px;">新增</el-button>
  12. </router-link>
  13. </div>
  14. </div>
  15. <template>
  16. <el-table :data="tableDatas.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
  17. style="width: 100%" v-loading="loading" element-loading-text="拼命加载中...">
  18. <el-table-column prop="num" label="序 号" width="55">
  19. <template slot-scope="scope">
  20. {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="city" label="所在城市" width="150">
  24. <template slot-scope="scope">
  25. {{scope.row.city|filter_emptyAcquiesce}}
  26. </template>
  27. </el-table-column>
  28. <el-table-column prop="name" label="酒店名称" width="300">
  29. <template slot-scope="scope">
  30. {{scope.row.name|filter_emptyAcquiesce}}
  31. </template>
  32. </el-table-column>
  33. <el-table-column prop="tel" label="酒店电话" width="200">
  34. <template slot-scope="scope">
  35. {{scope.row.tel|filter_emptyAcquiesce}}
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="fax" label="酒店传真" width="180">
  39. <template slot-scope="scope">
  40. {{scope.row.fax|filter_emptyAcquiesce}}
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="contact" label="联系人" width="180">
  44. <template slot-scope="scope">
  45. {{scope.row.contact|filter_emptyAcquiesce}}
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="contactPhone" label="联系电话" width="200">
  49. <template slot-scope="scope">
  50. {{scope.row.contactPhone|filter_emptyAcquiesce}}
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="操作">
  54. <template slot-scope="scope">
  55. <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
  56. <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. </template>
  61. <div class="block">
  62. <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
  63. :current-page="currentPage" :page-sizes="[10, 12, 15, 20]" :page-size="pageSize"
  64. layout="total, sizes, prev, pager, next" :total="tableDatas.length">
  65. </el-pagination>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. export default {
  72. beforeRouteLeave(to, from, next) {
  73. if(to.name!='HotelDataOperation'){
  74. localStorage.removeItem('jdzlval');
  75. }
  76. next()
  77. },
  78. data() {
  79. return {
  80. loading: false,
  81. tableDatas: [],
  82. tableData: [],
  83. currentPage: 1, // 当前页码
  84. pageSize: 12,// 每页的数据条数
  85. input: '',
  86. token: '',
  87. userId: 0
  88. }
  89. },
  90. methods: {
  91. //每页条数改变时触发 选择一页显示多少行
  92. handleSizeChange(val) {
  93. this.currentPage = 1;
  94. this.pageSize = val;
  95. },
  96. //当前页改变时触发 跳转其他页
  97. handleCurrentChange(val) {
  98. this.currentPage = val;
  99. },
  100. HotelData() {
  101. this.loading = true
  102. var url = "/api/Resource/QueryHotelData"
  103. var that = this
  104. this.$axios({
  105. method: 'post',
  106. url: url,
  107. headers: {
  108. Authorization: 'Bearer ' + this.token
  109. },
  110. data: {
  111. portType: 1,
  112. PageIndex: 0,
  113. PageSize: 0,
  114. City: '',
  115. Name: '',
  116. Contact: '',
  117. ContactPhone: '',
  118. }
  119. }).then(function (res) {
  120. console.log(res)
  121. if (res.data.code == 200) {
  122. that.tableData = res.data.data;
  123. that.tableDatas = that.tableData;
  124. if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
  125. if (that.currentPage > 1) {
  126. that.currentPage = that.currentPage - 1;
  127. }
  128. }
  129. if(JSON.parse(localStorage.getItem('jdzlval'))){
  130. that.currentPage=JSON.parse(localStorage.getItem('jdzlval')).currentPage;
  131. that.input=JSON.parse(localStorage.getItem('jdzlval')).input;
  132. var newarr = [];
  133. if (that.input == "") {
  134. newarr = that.tableData;
  135. } else {
  136. for (var i = 0; i < that.tableData.length; i++) {
  137. if (that.tableData[i].city.indexOf(that.input) != -1) {
  138. newarr.push(that.tableData[i]);
  139. } else if (that.tableData[i].name.indexOf(that.input) != -1) {
  140. newarr.push(that.tableData[i]);
  141. } else if (that.tableData[i].contact.indexOf(that.input) != -1) {
  142. newarr.push(that.tableData[i]);
  143. }
  144. }
  145. }
  146. that.tableDatas = newarr;
  147. }
  148. }
  149. that.loading = false
  150. }).catch(function (error) {
  151. that.loading = false
  152. that.$message.error("上传oa,请稍等");
  153. });
  154. },
  155. //搜索框处理
  156. Inquireclick() {
  157. var newarr = [];
  158. if (this.input == "") {
  159. newarr = this.tableData;
  160. } else {
  161. for (var i = 0; i < this.tableData.length; i++) {
  162. if (this.tableData[i].city.indexOf(this.input) != -1) {
  163. newarr.push(this.tableData[i]);
  164. } else if (this.tableData[i].name.indexOf(this.input) != -1) {
  165. newarr.push(this.tableData[i]);
  166. } else if (this.tableData[i].contact.indexOf(this.input) != -1) {
  167. newarr.push(this.tableData[i]);
  168. }
  169. }
  170. }
  171. this.tableDatas = newarr;
  172. this.currentPage = 1;
  173. },
  174. upDate(index, row) {
  175. var jdzlval={
  176. currentPage:this.currentPage,
  177. input:this.input,
  178. }
  179. localStorage.setItem('jdzlval', JSON.stringify(jdzlval));
  180. this.$router.push({
  181. path: "/home/HotelDataOperation",
  182. query: { id: row.id }
  183. })
  184. },
  185. del(index, row) {
  186. var url = "/api/Resource/DelHotelData"
  187. var that = this
  188. this.$axios({
  189. method: 'post',
  190. url: url,
  191. headers: {
  192. Authorization: 'Bearer ' + this.token
  193. },
  194. data: {
  195. Id: row.id,
  196. DeleteUserId: this.userId
  197. }
  198. }).then(function (res) {
  199. console.log(res)
  200. if (res.data.code == 200) {
  201. that.$message({
  202. message: '删除成功',
  203. type: 'success'
  204. });
  205. that.HotelData();
  206. } else {
  207. that.$message.error('删除失败!');
  208. }
  209. that.loading = false
  210. }).catch(function (error) {
  211. that.loading = false
  212. that.$message.error("网络错误,请稍后重试");
  213. });
  214. }
  215. },
  216. created(){
  217. // if(JSON.parse(localStorage.getItem('jdzlval'))){
  218. // this.currentPage=JSON.parse(localStorage.getItem('jdzlval')).currentPage;
  219. // this.input=JSON.parse(localStorage.getItem('jdzlval')).input;
  220. // var newarr = [];
  221. // console.log(this.input);
  222. // if (this.input == "") {
  223. // console.log(1);
  224. // newarr = this.tableData;
  225. // } else {
  226. // console.log(2);
  227. // for (var i = 0; i < this.tableData.length; i++) {
  228. // if (this.tableData[i].city.indexOf(this.input) != -1) {
  229. // newarr.push(this.tableData[i]);
  230. // } else if (this.tableData[i].name.indexOf(this.input) != -1) {
  231. // newarr.push(this.tableData[i]);
  232. // } else if (this.tableData[i].contact.indexOf(this.input) != -1) {
  233. // newarr.push(this.tableData[i]);
  234. // }
  235. // }
  236. // }
  237. // this.tableDatas = newarr;
  238. // }
  239. },
  240. filters:{
  241. //空默认值
  242. filter_emptyAcquiesce(value) {
  243. let fhz= value==""?"--":value
  244. return fhz
  245. },
  246. },
  247. mounted() {
  248. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  249. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  250. this.HotelData();
  251. }
  252. }
  253. </script>
  254. <style>
  255. .communal-list {
  256. background-color: #fff;
  257. padding: 10px;
  258. box-shadow: 0 0 5px #0005;
  259. border-radius: 10px;
  260. }
  261. .communal-title {
  262. display: flex;
  263. font-size: 17px;
  264. font-weight: 600;
  265. color: #555;
  266. margin-top: 8px;
  267. margin-bottom: 10px;
  268. justify-content: space-between;
  269. align-items: center;
  270. }
  271. .communal-box {
  272. display: flex;
  273. }
  274. .communal-box>button {
  275. margin-left: 10px;
  276. padding: 8px 20px;
  277. }
  278. </style>