CarData.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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/CarDataAdd">
  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. rules: {
  57. UnitArea: [
  58. { required: true, message: '请输入单位地区', trigger: 'blur' },
  59. { required: true, message: '请输入单位地区', trigger: 'change' },
  60. ],
  61. UnitName: [
  62. { required: true, message: '请输入单位名称', trigger: 'blur' },
  63. ],
  64. Contact: [
  65. { required: true, message: '请输入单位联系人', trigger: 'blur' },
  66. ],
  67. ContactTel: [
  68. { required: true, message: '请输入单位联系人电话', trigger: 'blur' },
  69. ],
  70. },
  71. loading: false,
  72. tableDatas: [],
  73. tableData: [],
  74. currentPage: 1, // 当前页码
  75. pageSize: 12,// 每页的数据条数
  76. input: '',
  77. token: '',
  78. userId: 0,
  79. unitAreas: [],
  80. restaurants: [],
  81. upCarVisible: false,
  82. }
  83. },
  84. methods: {
  85. //每页条数改变时触发 选择一页显示多少行
  86. handleSizeChange(val) {
  87. this.currentPage = 1;
  88. this.pageSize = val;
  89. },
  90. //当前页改变时触发 跳转其他页
  91. handleCurrentChange(val) {
  92. this.currentPage = val;
  93. },
  94. carData() {
  95. this.loading = true
  96. var url = "/api/Resource/QuerCarData"
  97. var that = this
  98. this.$axios({
  99. method: 'post',
  100. url: url,
  101. headers: {
  102. Authorization: 'Bearer ' + this.token
  103. },
  104. data: {
  105. portType: 1,
  106. }
  107. }).then(function (res) {
  108. console.log(res)
  109. debugger
  110. if (res.data.code == 200) {
  111. debugger
  112. that.tableData = res.data.data;
  113. that.tableDatas = that.tableData;
  114. that.tableData.forEach(function (item, index) {
  115. that.unitAreas.push({
  116. value: item.unitArea,
  117. });
  118. });
  119. }
  120. that.loading = false
  121. }).catch(function (error) {
  122. that.loading = false
  123. that.$message.error("网络错误,请稍后重试");
  124. });
  125. },
  126. //搜索框处理
  127. Inquireclick() {
  128. var newarr = [];
  129. if (this.input == "") {
  130. newarr = this.tableData;
  131. } else {
  132. for (var i = 0; i < this.tableData.length; i++) {
  133. if (this.tableData[i].unitArea.indexOf(this.input) != -1) {
  134. newarr.push(this.tableData[i]);
  135. } else if (this.tableData[i].unitName.indexOf(this.input) != -1) {
  136. newarr.push(this.tableData[i]);
  137. } else if (this.tableData[i].contact.indexOf(this.input) != -1) {
  138. newarr.push(this.tableData[i]);
  139. } else if (this.tableData[i].contactTel.indexOf(this.input) != -1) {
  140. newarr.push(this.tableData[i]);
  141. }
  142. }
  143. }
  144. this.tableDatas = newarr;
  145. },
  146. querySearch(queryString, cb) {
  147. var arr = this.unitAreas;
  148. for (var i = 0; i < arr.length - 1; i++) {
  149. for (var j = i + 1; j < arr.length; j++) {
  150. if (arr[i].value == arr[j].value) {
  151. arr.splice(j, 1);
  152. //因为数组长度减小1,所以直接 j++ 会漏掉一个元素,所以要 j--
  153. j--;
  154. }
  155. }
  156. }
  157. var restaurants = arr;
  158. var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
  159. // 调用 callback 返回建议列表的数据
  160. cb(results);
  161. },
  162. createFilter(queryString) {
  163. return (restaurant) => {
  164. return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
  165. };
  166. },
  167. upDate(index, row) {
  168. localStorage.setItem('CarDataEdit', JSON.stringify(row));
  169. this.$router.push('/home/carDataEdit')
  170. },
  171. handleSelect(item) {
  172. console.log(item);
  173. },
  174. del(index, row) {
  175. var url = "/api/Resource/DelCarData"
  176. var that = this
  177. this.$axios({
  178. method: 'post',
  179. url: url,
  180. headers: {
  181. Authorization: 'Bearer ' + this.token
  182. },
  183. data: {
  184. Id: row.id,
  185. DeleteUserId: this.userId
  186. }
  187. }).then(function (res) {
  188. console.log(res)
  189. debugger
  190. if (res.data.code == 200) {
  191. debugger
  192. that.$message({
  193. message: '删除成功',
  194. type: 'success'
  195. });
  196. that.carData();
  197. } else {
  198. that.$message.error('删除失败!');
  199. }
  200. that.loading = false
  201. }).catch(function (error) {
  202. that.loading = false
  203. that.$message.error("网络错误,请稍后重试");
  204. });
  205. }
  206. },
  207. mounted() {
  208. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  209. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  210. this.carData();
  211. }
  212. }
  213. </script>
  214. <style>
  215. .communal-list {
  216. background-color: #fff;
  217. padding: 10px;
  218. box-shadow: 0 0 5px #0005;
  219. border-radius: 10px;
  220. }
  221. .communal-title {
  222. display: flex;
  223. font-size: 17px;
  224. font-weight: 600;
  225. color: #555;
  226. margin-top: 8px;
  227. margin-bottom: 10px;
  228. justify-content: space-between;
  229. align-items: center;
  230. }
  231. .communal-box {
  232. display: flex;
  233. }
  234. .communal-box>button {
  235. margin-left: 10px;
  236. padding: 8px 20px;
  237. }
  238. </style>