CarData.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. beforeRouteLeave(to, from, next) {
  55. if(to.name!='carDataEdit'){
  56. localStorage.removeItem('carval');
  57. }
  58. next()
  59. },
  60. data() {
  61. return {
  62. rules: {
  63. UnitArea: [
  64. { required: true, message: '请输入单位地区', trigger: 'blur' },
  65. { required: true, message: '请输入单位地区', trigger: 'change' },
  66. ],
  67. UnitName: [
  68. { required: true, message: '请输入单位名称', trigger: 'blur' },
  69. ],
  70. Contact: [
  71. { required: true, message: '请输入单位联系人', trigger: 'blur' },
  72. ],
  73. ContactTel: [
  74. { required: true, message: '请输入单位联系人电话', trigger: 'blur' },
  75. ],
  76. },
  77. loading: false,
  78. tableDatas: [],
  79. tableData: [],
  80. currentPage: 1, // 当前页码
  81. pageSize: 12,// 每页的数据条数
  82. input: '',
  83. token: '',
  84. userId: 0,
  85. unitAreas: [],
  86. restaurants: [],
  87. upCarVisible: false,
  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. carData() {
  101. this.loading = true
  102. var url = "/api/Resource/QueryCarData"
  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. unitName: "",
  115. unitArea: "",
  116. contact: "",
  117. contactTel: ""
  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. that.tableData.forEach(function (item, index) {
  125. that.unitAreas.push({
  126. value: item.unitArea,
  127. });
  128. });
  129. if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
  130. if (that.currentPage > 1) {
  131. that.currentPage = that.currentPage - 1;
  132. }
  133. }
  134. if(JSON.parse(localStorage.getItem('carval'))){
  135. that.currentPage=JSON.parse(localStorage.getItem('carval')).currentPage;
  136. that.input=JSON.parse(localStorage.getItem('carval')).input;
  137. var newarr = [];
  138. if (that.input == "") {
  139. newarr = that.tableData;
  140. } else {
  141. for (var i = 0; i < that.tableData.length; i++) {
  142. if (that.tableData[i].unitArea.indexOf(that.input) != -1) {
  143. newarr.push(that.tableData[i]);
  144. } else if (that.tableData[i].unitName.indexOf(that.input) != -1) {
  145. newarr.push(that.tableData[i]);
  146. } else if (that.tableData[i].contact.indexOf(that.input) != -1) {
  147. newarr.push(that.tableData[i]);
  148. } else if (that.tableData[i].contactTel.indexOf(that.input) != -1) {
  149. newarr.push(that.tableData[i]);
  150. }
  151. }
  152. }
  153. that.tableDatas = newarr;
  154. }
  155. }
  156. that.loading = false
  157. }).catch(function (error) {
  158. that.loading = false
  159. that.$message.error("网络错误,请稍后重试");
  160. });
  161. },
  162. //搜索框处理
  163. Inquireclick() {
  164. var newarr = [];
  165. if (this.input == "") {
  166. newarr = this.tableData;
  167. } else {
  168. for (var i = 0; i < this.tableData.length; i++) {
  169. if (this.tableData[i].unitArea.indexOf(this.input) != -1) {
  170. newarr.push(this.tableData[i]);
  171. } else if (this.tableData[i].unitName.indexOf(this.input) != -1) {
  172. newarr.push(this.tableData[i]);
  173. } else if (this.tableData[i].contact.indexOf(this.input) != -1) {
  174. newarr.push(this.tableData[i]);
  175. } else if (this.tableData[i].contactTel.indexOf(this.input) != -1) {
  176. newarr.push(this.tableData[i]);
  177. }
  178. }
  179. }
  180. this.tableDatas = newarr;
  181. this.currentPage = 1;
  182. },
  183. querySearch(queryString, cb) {
  184. var arr = this.unitAreas;
  185. for (var i = 0; i < arr.length - 1; i++) {
  186. for (var j = i + 1; j < arr.length; j++) {
  187. if (arr[i].value == arr[j].value) {
  188. arr.splice(j, 1);
  189. //因为数组长度减小1,所以直接 j++ 会漏掉一个元素,所以要 j--
  190. j--;
  191. }
  192. }
  193. }
  194. var restaurants = arr;
  195. var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
  196. // 调用 callback 返回建议列表的数据
  197. cb(results);
  198. },
  199. createFilter(queryString) {
  200. return (restaurant) => {
  201. return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
  202. };
  203. },
  204. upDate(index, row) {
  205. var carval={
  206. currentPage:this.currentPage,
  207. input:this.input,
  208. }
  209. localStorage.setItem('carval', JSON.stringify(carval));
  210. localStorage.setItem('CarDataEdit', JSON.stringify(row));
  211. this.$router.push('/home/carDataEdit')
  212. },
  213. handleSelect(item) {
  214. console.log(item);
  215. },
  216. del(index, row) {
  217. this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
  218. confirmButtonText: '确定',
  219. cancelButtonText: '取消',
  220. type: 'warning'
  221. }).then(() => {
  222. var url = "/api/Resource/DelCarData"
  223. var that = this
  224. this.$axios({
  225. method: 'post',
  226. url: url,
  227. headers: {
  228. Authorization: 'Bearer ' + this.token
  229. },
  230. data: {
  231. Id: row.id,
  232. DeleteUserId: this.userId
  233. }
  234. }).then(function (res) {
  235. console.log(res)
  236. if (res.data.code == 200) {
  237. that.$message({
  238. message: '删除成功',
  239. type: 'success'
  240. });
  241. that.carData();
  242. } else {
  243. that.$message.error('删除失败!');
  244. }
  245. that.loading = false
  246. }).catch(function (error) {
  247. that.loading = false
  248. that.$message.error("网络错误,请稍后重试");
  249. });
  250. }).catch(() => {
  251. this.$message({
  252. type: 'info',
  253. message: '操作已取消!'
  254. });
  255. });
  256. }
  257. },
  258. mounted() {
  259. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  260. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  261. this.carData();
  262. }
  263. }
  264. </script>
  265. <style>
  266. .communal-list {
  267. background-color: #fff;
  268. padding: 10px;
  269. box-shadow: 0 0 5px #0005;
  270. border-radius: 10px;
  271. }
  272. .communal-title {
  273. display: flex;
  274. font-size: 17px;
  275. font-weight: 600;
  276. color: #555;
  277. margin-top: 8px;
  278. margin-bottom: 10px;
  279. justify-content: space-between;
  280. align-items: center;
  281. }
  282. .communal-box {
  283. display: flex;
  284. }
  285. .communal-box>button {
  286. margin-left: 10px;
  287. padding: 8px 20px;
  288. }
  289. </style>