SetData.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. <el-button type="primary" style="margin-left: 10px;" @click="AddSetDataType">新增</el-button>
  11. </div>
  12. </div>
  13. <template>
  14. <el-table :data="tableDatas.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
  15. style="width: 100%" v-loading="loading" element-loading-text="拼命加载中...">
  16. <el-table-column prop="num" label="序 号" width="55">
  17. <template slot-scope="scope">
  18. {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
  19. </template>
  20. </el-table-column>
  21. <el-table-column prop="stName" label="类型名称">
  22. </el-table-column>
  23. <el-table-column prop="name" label="板块名称">
  24. </el-table-column>
  25. <el-table-column prop="cnName" label="添加人">
  26. </el-table-column>
  27. <el-table-column prop="createTime" label="添加时间">
  28. </el-table-column>
  29. <el-table-column label="操作">
  30. <template slot-scope="scope">
  31. <el-button size="mini" @click="upDate(scope.$index, scope.row)">编辑</el-button>
  32. <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. </template>
  37. <div class="block">
  38. <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
  39. :current-page="currentPage" :page-sizes="[10, 12, 15, 20]" :page-size="pageSize"
  40. layout="total, sizes, prev, pager, next" :total="tableDatas.length">
  41. </el-pagination>
  42. </div>
  43. </div>
  44. <el-dialog :title="typeName" :visible.sync="AddSetDataTypeVisible" width="30%" :before-close="handleClose">
  45. <div>
  46. <el-form :model="OperationData" :rules="rules" ref="OperationData" label-width="100px"
  47. class="demo-ruleForm">
  48. <el-form-item label="数据类型" prop="sTid">
  49. <el-select v-model="OperationData.sTid" filterable placeholder="请选择">
  50. <el-option v-for="item in setDataType" :key="item.id" :label="item.name" :value="item.id">
  51. </el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item label="板块名称" prop="name">
  55. <el-input placeholder="请输入内容" v-model="OperationData.name">
  56. </el-input>
  57. </el-form-item>
  58. <el-form-item label="备 注" prop="remark">
  59. <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="OperationData.remark"></el-input>
  60. </el-form-item>
  61. </el-form>
  62. </div>
  63. <span slot="footer" class="dialog-footer">
  64. <el-button @click="AddSetDataTypeVisible = false">取 消</el-button>
  65. <el-button type="primary" @click="AddBtn">确 定</el-button>
  66. </span>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script>
  71. export default {
  72. data() {
  73. return {
  74. loading: false,
  75. tableDatas: [],
  76. tableData: [],
  77. currentPage: 1, // 当前页码
  78. pageSize: 12,// 每页的数据条数
  79. input: '',
  80. token: '',
  81. userId: 0,
  82. typeName: "添加数据类型",
  83. OperationData: {
  84. status: 1,
  85. id: 0,
  86. name: "",
  87. sTid: '',
  88. createUserId: 0,
  89. remark: ""
  90. },
  91. AddSetDataTypeVisible: false,
  92. rules: {
  93. name: [
  94. { required: true, message: '板块名称', trigger: 'blur' },
  95. ],
  96. sTid: [
  97. { required: true, message: '请选择数据类型', trigger: 'blur' },
  98. ],
  99. },
  100. setDataType: [
  101. ]
  102. }
  103. },
  104. methods: {
  105. //每页条数改变时触发 选择一页显示多少行
  106. handleSizeChange(val) {
  107. this.currentPage = 1;
  108. this.pageSize = val;
  109. },
  110. //当前页改变时触发 跳转其他页
  111. handleCurrentChange(val) {
  112. this.currentPage = val;
  113. },
  114. //关闭修改框
  115. handleClose(done) {
  116. done();
  117. },
  118. SetData() {
  119. this.loading = true
  120. var url = "/api/System/QuerySetDataInfo"
  121. var that = this
  122. this.$axios({
  123. method: 'post',
  124. url: url,
  125. headers: {
  126. Authorization: 'Bearer ' + this.token
  127. },
  128. data: {
  129. portType: 1,
  130. pageIndex: 0,
  131. pageSize: 0,
  132. STid: 0
  133. }
  134. }).then(function (res) {
  135. console.log(res)
  136. if (res.data.code == 200) {
  137. that.tableData = res.data.data;
  138. that.tableDatas = that.tableData;
  139. if (that.tableDatas.slice((that.currentPage - 1) * that.pageSize, that.currentPage * that.pageSize).length == 0) {
  140. if (that.currentPage > 1) {
  141. that.currentPage = that.currentPage - 1;
  142. }
  143. }
  144. }
  145. that.loading = false
  146. }).catch(function (error) {
  147. that.loading = false
  148. that.$message.error("网络错误,请稍后重试");
  149. });
  150. },
  151. //下拉框数据
  152. SetDataType() {
  153. this.loading = true
  154. var url = "/api/System/QuerySetDataType"
  155. var that = this
  156. this.$axios({
  157. method: 'post',
  158. url: url,
  159. headers: {
  160. Authorization: 'Bearer ' + this.token
  161. },
  162. data: {
  163. portType: 1,
  164. pageIndex: 0,
  165. pageSize: 0,
  166. name: "",
  167. cnName: ""
  168. }
  169. }).then(function (res) {
  170. console.log(res)
  171. if (res.data.code == 200) {
  172. res.data.data.forEach(function (item, index) {
  173. that.setDataType.push({
  174. id: item.id,
  175. name: item.name
  176. });
  177. })
  178. }
  179. }).catch(function (error) {
  180. });
  181. },
  182. //搜索框处理
  183. Inquireclick() {
  184. var newarr = [];
  185. if (this.input == "") {
  186. newarr = this.tableData;
  187. } else {
  188. for (var i = 0; i < this.tableData.length; i++) {
  189. if (this.tableData[i].name.indexOf(this.input) != -1) {
  190. newarr.push(this.tableData[i]);
  191. }
  192. }
  193. }
  194. this.tableDatas = newarr;
  195. this.currentPage = 1;
  196. },
  197. //点击修改
  198. upDate(index, row) {
  199. this.AddSetDataTypeVisible = true;
  200. this.typeName = "修改数据板块"
  201. this.OperationData.status = 2
  202. this.OperationData.id = row.id
  203. this.OperationData.name = row.name
  204. this.OperationData.sTid = row.sTid
  205. this.OperationData.createUserId = row.createUserId
  206. this.OperationData.remark = row.remark
  207. },
  208. //点击添加
  209. AddSetDataType() {
  210. this.OperationData = {
  211. status: 1,
  212. id: 0,
  213. name: "",
  214. sTid: '',
  215. createUserId: 0,
  216. remark: ""
  217. },
  218. this.AddSetDataTypeVisible = true;
  219. this.typeName = "添加数据板块"
  220. },
  221. AddBtn() {
  222. this.$refs.OperationData.validate((valid) => {
  223. if (valid) {
  224. var that = this
  225. that.OperationData.CreateUserId = this.userId
  226. var url = "/api/System/OperationSetData"
  227. that.$axios({
  228. method: 'post',
  229. url: url,
  230. headers: {
  231. Authorization: 'Bearer ' + that.token
  232. },
  233. data: that.OperationData
  234. }).then(function (res) {
  235. if (res.data.code == 200) {
  236. that.$message({
  237. message: res.data.msg,
  238. type: 'success'
  239. });
  240. that.loading = true;
  241. that.AddSetDataTypeVisible = false;
  242. that.SetData()
  243. } else {
  244. that.$message.error(res.data.msg);
  245. }
  246. })
  247. }
  248. })
  249. },
  250. //点击删除
  251. del(index, row) {
  252. this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
  253. confirmButtonText: '确定',
  254. cancelButtonText: '取消',
  255. type: 'warning'
  256. }).then(() => {
  257. var url = "/api/System/DelSetData"
  258. var that = this
  259. this.$axios({
  260. method: 'post',
  261. url: url,
  262. headers: {
  263. Authorization: 'Bearer ' + this.token
  264. },
  265. data: {
  266. Id: row.id,
  267. DeleteUserId: this.userId
  268. }
  269. }).then(function (res) {
  270. console.log(res)
  271. if (res.data.code == 200) {
  272. that.$message({
  273. message: '删除成功',
  274. type: 'success'
  275. });
  276. that.SetData();
  277. } else {
  278. that.$message.error('删除失败!');
  279. }
  280. that.loading = false
  281. }).catch(function (error) {
  282. that.loading = false
  283. that.$message.error("网络错误,请稍后重试");
  284. });
  285. }).catch(() => {
  286. this.$message({
  287. type: 'info',
  288. message: '操作已取消!'
  289. });
  290. });
  291. }
  292. },
  293. mounted() {
  294. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  295. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  296. this.SetData();
  297. this.SetDataType();
  298. }
  299. }
  300. </script>
  301. <style>
  302. .communal-list {
  303. background-color: #fff;
  304. padding: 10px;
  305. box-shadow: 0 0 5px #0005;
  306. border-radius: 10px;
  307. }
  308. .communal-title {
  309. display: flex;
  310. font-size: 17px;
  311. font-weight: 600;
  312. color: #555;
  313. margin-top: 8px;
  314. margin-bottom: 10px;
  315. justify-content: space-between;
  316. align-items: center;
  317. }
  318. .communal-box {
  319. display: flex;
  320. }
  321. .communal-box>button {
  322. margin-left: 10px;
  323. padding: 8px 20px;
  324. }
  325. </style>