addPage.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="organizationalStructure-addPage">
  3. <div class="page-form-title-box">
  4. <el-form :model="queryParams" class="form-box" ref="queryForm"
  5. :inline="true" style="width:100%;">
  6. <el-form-item label="" prop="searchValue">
  7. <el-input
  8. maxLength="30"
  9. v-model="queryParams.searchValue"
  10. placeholder="请输入关键词"
  11. clearable
  12. style="width: 200px"
  13. />
  14. </el-form-item>
  15. <el-form-item label="" prop="state ">
  16. <el-select v-model="queryParams.state " clearable placeholder="请选择状态" style="width: 200px">
  17. <el-option
  18. v-for="dict in options"
  19. :key="dict.value"
  20. :label="dict.label"
  21. :value="dict.value"
  22. />
  23. </el-select>
  24. </el-form-item>
  25. <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
  26. <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
  27. <p class="page-submit-common-style-button"
  28. style="float: right;"
  29. @click="dialogOpen"
  30. v-hasPermiRouter="['demo:demo:add']"
  31. >新增</p>
  32. <p class="page-out-common-style-button"
  33. style="float: right;margin-right:20px;"
  34. @click="backPage"
  35. v-hasPermiRouter="['demo:demo:add']"
  36. >返回</p>
  37. </el-form>
  38. </div>
  39. <div class="content-box">
  40. <el-table class="table-box" v-loading="loading" border :data="dataList">
  41. <el-table-column label="序号" type="index" align="center" width="50"/>
  42. <el-table-column label="名称" align="left" prop="dictKey"/>
  43. <el-table-column label="关联值" align="left" prop="dictValue" show-overflow-tooltip/>
  44. <el-table-column label="排序" align="left" prop="sort" width="80" show-overflow-tooltip/>
  45. <el-table-column label="状态" align="left" prop="state" width="120" show-overflow-tooltip>
  46. <template slot-scope="scope">
  47. {{scope.row.state?'启用':'停用'}}
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="创建时间" align="left" prop="createTime" width="180" show-overflow-tooltip>
  51. <template slot-scope="scope">
  52. <span>{{ parseTime(scope.row.createTime) }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="260">
  56. <template slot-scope="scope">
  57. <div class="table-button-box">
  58. <p class="table-button-null"></p>
  59. <p class="table-button-p"
  60. @click="tableButton(1,scope.row)"
  61. >编辑</p>
  62. <p class="table-button-p"
  63. @click="tableButton(2,scope.row)"
  64. >删除</p>
  65. <p class="table-button-null"></p>
  66. </div>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <pagination :page-sizes="[20, 30, 40, 50]"
  71. v-show="total>0"
  72. :total="total"
  73. :page.sync="queryParams.page"
  74. :limit.sync="queryParams.pageSize"
  75. @pagination="getList"
  76. />
  77. </div>
  78. <el-dialog class="classConfig-dialog" :title='dialogTitle' width="540px" append-to-body
  79. :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
  80. :close-on-click-modal="false" :close-on-press-escape="false">
  81. <el-form :model="dialogForm" ref="dialogForm" :inline="true" :rules="dialogRules" class="addCheckPage-min" label-width="80px">
  82. <el-form-item label="名称" prop="dictKey">
  83. <el-input v-model="dialogForm.dictKey" placeholder="请输入名称" maxLength="10" style="width:320px;"/>
  84. </el-form-item>
  85. <el-form-item label="关联值" prop="dictValue">
  86. <el-input v-model="dialogForm.dictValue" placeholder="请输入标识" maxLength="20" style="width:320px;"/>
  87. </el-form-item>
  88. <el-form-item label="排序" prop="sort">
  89. <el-input-number v-model="dialogForm.sort" controls-position="right" :min="1" :max="9999" style="width:320px;"></el-input-number>
  90. </el-form-item>
  91. <el-form-item label="状态" prop="state">
  92. <el-radio-group v-model="dialogForm.state" style="width:320px;">
  93. <el-radio :label="true">启用</el-radio>
  94. <el-radio :label="false">禁用</el-radio>
  95. </el-radio-group>
  96. </el-form-item>
  97. </el-form>
  98. <div slot="footer" class="dialog-footer dialog-footer-box">
  99. <p class="dialog-footer-button-null"></p>
  100. <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
  101. <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
  102. <p class="dialog-footer-button-null"></p>
  103. </div>
  104. </el-dialog>
  105. </div>
  106. </template>
  107. <script>
  108. import { iotParamValueList,iotParamValueAdd,
  109. iotParamValueUpdate,iotParamValueDelete,iotParamValueDetail } from "@/api/iotDevice/index";
  110. export default {
  111. name: 'addPage',
  112. props:{
  113. propsData:{},
  114. },
  115. data(){
  116. return{
  117. loading:false,
  118. showType:false,
  119. newData:{},
  120. options:[{label:'启用',value:true},{label:'停用',value:false}],
  121. queryParams:{
  122. page:1,
  123. pageSize:20,
  124. searchValue:"",
  125. state :null,
  126. },
  127. dataList:[],
  128. total:0,
  129. dialogTitle:null,
  130. dialogType:false,
  131. dialogForm:{},
  132. dialogRules:{
  133. dictKey: [
  134. { required: true, message: "请输入名称", trigger: "blur" },
  135. { required: true, message: "请输入名称", validator: this.spaceJudgment, trigger: "blur" }
  136. ],
  137. dictValue: [
  138. { required: true, message: "请输入关联值", trigger: "blur" },
  139. { required: true, message: "请输入关联值", validator: this.spaceJudgment, trigger: "blur" }
  140. ],
  141. sort: [
  142. { required: true, message: "请输入排序", trigger: "blur" },
  143. { required: true, message: "请输入排序", validator: this.spaceJudgment, trigger: "blur" }
  144. ],
  145. state: [
  146. { required: true, message: "请选择状态", trigger: "blur" },
  147. ],
  148. },
  149. }
  150. },
  151. created(){
  152. },
  153. mounted(){
  154. this.getList();
  155. },
  156. methods:{
  157. // 返回按钮
  158. backPage(){
  159. this.$parent.tableButton(4);
  160. },
  161. handleQuery(){
  162. this.$set(this.queryParams,'page',1);
  163. this.getList();
  164. },
  165. resetQuery(){
  166. this.$set(this,'queryParams',{
  167. page:1,
  168. pageSize:20,
  169. searchValue:"",
  170. state :null,
  171. });
  172. this.getList();
  173. },
  174. //获取数据列表
  175. getList(){
  176. this.$set(this,'loading',true);
  177. let obj = JSON.parse(JSON.stringify(this.queryParams))
  178. obj.paramId = this.propsData.id;
  179. iotParamValueList(obj).then(response => {
  180. this.$set(this,'loading',false);
  181. this.$set(this,'dataList',response.data.records);
  182. this.$set(this,'total',response.data.total);
  183. });
  184. },
  185. dialogFormReset(){
  186. this.$set(this,'dialogForm',{
  187. dictKey:'',
  188. dictValue:'',
  189. sort:1,
  190. state:true,
  191. });
  192. },
  193. //弹层关闭
  194. dialogOff(){
  195. this.$set(this,'dialogType',false);
  196. },
  197. //弹层开启
  198. dialogOpen(){
  199. this.dialogFormReset();
  200. this.$set(this,'dialogTitle','新增');
  201. this.$set(this,'dialogType',true);
  202. },
  203. //弹层确定
  204. dialogSubmit(){
  205. this.$refs["dialogForm"].validate(valid => {
  206. if (valid) {
  207. if(this.dialogForm.id){
  208. let obj = {
  209. paramId:this.propsData.id,
  210. id:this.dialogForm.id,
  211. dictKey:this.dialogForm.dictKey,
  212. dictValue:this.dialogForm.dictValue,
  213. sort:this.dialogForm.sort,
  214. state:this.dialogForm.state,
  215. }
  216. iotParamValueUpdate(obj).then(response => {
  217. this.msgSuccess(response.message);
  218. this.getList();
  219. this.$set(this,'dialogType',false);
  220. });
  221. }else{
  222. let obj = {
  223. paramId:this.propsData.id,
  224. dictKey:this.dialogForm.dictKey,
  225. dictValue:this.dialogForm.dictValue,
  226. sort:this.dialogForm.sort,
  227. state:this.dialogForm.state,
  228. }
  229. iotParamValueAdd(obj).then(response => {
  230. this.msgSuccess(response.message);
  231. this.getList();
  232. this.$set(this,'dialogType',false);
  233. });
  234. }
  235. }
  236. })
  237. },
  238. tableButton(type,row){
  239. let self = this;
  240. if(type == 1){
  241. //编辑
  242. iotParamValueDetail({id:row.id}).then(response => {
  243. this.dialogFormReset();
  244. this.$set(this,'dialogTitle','编辑');
  245. this.$set(this,'dialogForm',{
  246. id:response.data.id,
  247. dictKey:response.data.dictKey,
  248. dictValue:response.data.dictValue,
  249. sort:response.data.sort,
  250. state:response.data.state,
  251. });
  252. this.$set(this,'dialogType',true);
  253. });
  254. }else if(type == 2){
  255. //删除
  256. this.$confirm('是否确认删除?', "警告", {
  257. confirmButtonText: "确定",
  258. cancelButtonText: "取消",
  259. type: "warning"
  260. }).then(function() {
  261. }).then(() => {
  262. iotParamValueDelete({id:row.id}).then(response => {
  263. self.msgSuccess(response.message)
  264. self.getList();
  265. });
  266. }).catch(() => {});
  267. }
  268. },
  269. },
  270. }
  271. </script>
  272. <style scoped lang="scss">
  273. .organizationalStructure-addPage{
  274. flex:1;
  275. display: flex;
  276. flex-direction: column;
  277. overflow: hidden;
  278. .title-box{
  279. padding-top:20px;
  280. border-bottom:1px solid #dedede;
  281. display: flex;
  282. }
  283. .content-box{
  284. flex: 1;
  285. display: flex;
  286. flex-direction: column;
  287. padding:20px;
  288. overflow: hidden;
  289. }
  290. }
  291. </style>