LocalGuide.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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/LocalGuideOperation">
  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="unitArea" label="单位地区" width="180">
  24. </el-table-column>
  25. <el-table-column prop="unitName" label="单位名称">
  26. </el-table-column>
  27. <el-table-column prop="contact" label="联系人" width="220">
  28. </el-table-column>
  29. <el-table-column prop="contactTel" label="联系电话" width="180">
  30. </el-table-column>
  31. <el-table-column prop="score" label="评分" width="55">
  32. </el-table-column>
  33. <el-table-column prop="createTime" label="更新时间" width="180">
  34. </el-table-column>
  35. <el-table-column label="操作">
  36. <template slot-scope="scope">
  37. <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
  38. <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </template>
  43. <div class="block">
  44. <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
  45. :current-page="currentPage" :page-sizes="[10, 12, 15, 20]" :page-size="pageSize"
  46. layout="total, sizes, prev, pager, next" :total="tableDatas.length">
  47. </el-pagination>
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. loading: false,
  57. tableDatas: [],
  58. tableData: [],
  59. currentPage: 1, // 当前页码
  60. pageSize: 12,// 每页的数据条数
  61. input: '',
  62. token: '',
  63. userId: 0,
  64. unitAreas: [],
  65. restaurants: [],
  66. }
  67. },
  68. methods: {
  69. //每页条数改变时触发 选择一页显示多少行
  70. handleSizeChange(val) {
  71. this.currentPage = 1;
  72. this.pageSize = val;
  73. },
  74. //当前页改变时触发 跳转其他页
  75. handleCurrentChange(val) {
  76. this.currentPage = val;
  77. },
  78. LocalGuide() {
  79. this.loading = true
  80. var url = "/api/Resource/QueryLocalGuide"
  81. var that = this
  82. this.$axios({
  83. method: 'post',
  84. url: url,
  85. headers: {
  86. Authorization: 'Bearer ' + this.token
  87. },
  88. data: {
  89. portType: 1,
  90. pageIndex: 0,
  91. pageSize: 0,
  92. unitName: "",
  93. unitArea: "",
  94. contact: "",
  95. contactTel: ""
  96. }
  97. }).then(function (res) {
  98. console.log(res)
  99. if (res.data.code == 200) {
  100. that.tableData = res.data.data;
  101. that.tableDatas = that.tableData;
  102. that.tableData.forEach(function (item, index) {
  103. that.unitAreas.push({
  104. value: item.unitArea,
  105. });
  106. });
  107. if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
  108. if (that.currentPage > 1) {
  109. that.currentPage = that.currentPage - 1;
  110. }
  111. }
  112. }
  113. that.loading = false
  114. }).catch(function (error) {
  115. that.loading = false
  116. that.$message.error("网络错误,请稍后重试");
  117. });
  118. },
  119. //搜索框处理
  120. Inquireclick() {
  121. var newarr = [];
  122. if (this.input == "") {
  123. newarr = this.tableData;
  124. } else {
  125. for (var i = 0; i < this.tableData.length; i++) {
  126. if (this.tableData[i].unitArea.indexOf(this.input) != -1) {
  127. newarr.push(this.tableData[i]);
  128. } else if (this.tableData[i].unitName.indexOf(this.input) != -1) {
  129. newarr.push(this.tableData[i]);
  130. } else if (this.tableData[i].contact.indexOf(this.input) != -1) {
  131. newarr.push(this.tableData[i]);
  132. } else if (this.tableData[i].contactTel.indexOf(this.input) != -1) {
  133. newarr.push(this.tableData[i]);
  134. }
  135. }
  136. }
  137. this.tableDatas = newarr;
  138. this.currentPage = 1;
  139. },
  140. querySearch(queryString, cb) {
  141. var arr = this.unitAreas;
  142. for (var i = 0; i < arr.length - 1; i++) {
  143. for (var j = i + 1; j < arr.length; j++) {
  144. if (arr[i].value == arr[j].value) {
  145. arr.splice(j, 1);
  146. //因为数组长度减小1,所以直接 j++ 会漏掉一个元素,所以要 j--
  147. j--;
  148. }
  149. }
  150. }
  151. var restaurants = arr;
  152. var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
  153. // 调用 callback 返回建议列表的数据
  154. cb(results);
  155. },
  156. createFilter(queryString) {
  157. return (restaurant) => {
  158. return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
  159. };
  160. },
  161. upDate(index, row) {
  162. this.$router.push({
  163. path: "/home/LocalGuideOperation",
  164. query: { id: row.id }
  165. })
  166. },
  167. handleSelect(item) {
  168. console.log(item);
  169. },
  170. del(index, row) {
  171. this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
  172. confirmButtonText: '确定',
  173. cancelButtonText: '取消',
  174. type: 'warning'
  175. }).then(() => {
  176. var url = "/api/Resource/DelLocalGuide"
  177. var that = this
  178. this.$axios({
  179. method: 'post',
  180. url: url,
  181. headers: {
  182. Authorization: 'Bearer ' + this.token
  183. },
  184. data: {
  185. Id: row.id,
  186. DeleteUserId: this.userId
  187. }
  188. }).then(function (res) {
  189. console.log(res)
  190. if (res.data.code == 200) {
  191. that.$message({
  192. message: '删除成功',
  193. type: 'success'
  194. });
  195. that.LocalGuide();
  196. } else {
  197. that.$message.error('删除失败!');
  198. }
  199. that.loading = false
  200. }).catch(function (error) {
  201. that.loading = false
  202. that.$message.error("网络错误,请稍后重试");
  203. });
  204. }).catch(() => {
  205. this.$message({
  206. type: 'info',
  207. message: '操作已取消!'
  208. });
  209. });
  210. }
  211. },
  212. mounted() {
  213. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  214. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  215. this.LocalGuide();
  216. }
  217. }
  218. </script>
  219. <style>
  220. .communal-list {
  221. background-color: #fff;
  222. padding: 10px;
  223. box-shadow: 0 0 5px #0005;
  224. border-radius: 10px;
  225. }
  226. .communal-title {
  227. display: flex;
  228. font-size: 17px;
  229. font-weight: 600;
  230. color: #555;
  231. margin-top: 8px;
  232. margin-bottom: 10px;
  233. justify-content: space-between;
  234. align-items: center;
  235. }
  236. .communal-box {
  237. display: flex;
  238. }
  239. .communal-box>button {
  240. margin-left: 10px;
  241. padding: 8px 20px;
  242. }
  243. </style>