index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="my-container">
  3. <div class="bill-main">
  4. <module-view :propConfig="config" ref="moduleView" @pagination="getDataList" @search="getDataList"
  5. @resert="onRefresh" @clickHandle="clickHandle" @detail="openEdit" @onRefresh="onRefresh">
  6. </module-view>
  7. </div>
  8. <!-- 新增/编辑弹窗 -->
  9. <el-dialog :title="popTitle+'品牌'" :visible.sync="dialogFormVisible" width="30%">
  10. <by-form :propConfig="addConfig" ref="addFormId">
  11. <template v-slot:status class="clearfix">
  12. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="0">正常</el-radio>
  13. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="1">禁用</el-radio>
  14. </template>
  15. </by-form>
  16. <div slot="footer" class="dialog-footer">
  17. <el-button @click="dialogFormVisible = false">取 消</el-button>
  18. <el-button type="primary" @click="confirm">确 定</el-button>
  19. </div>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script lang="ts">
  24. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  25. // import Parent from "@/components/Parent/Parent";
  26. import api from "@/api/currency";
  27. import Assembly from "@/components/Assembly/material.vue";
  28. @Component
  29. export default class Brand extends Vue {
  30. timeNum = 0;
  31. timer : any = null
  32. popTitle : any = ''
  33. radio : any = 0
  34. dialogFormVisible : boolean = false
  35. config : any = {
  36. attr:{
  37. calculateH:true
  38. },
  39. search: {
  40. attr: {
  41. size: 'mini',
  42. },
  43. columns: [
  44. [{
  45. span: 6,
  46. label: '名称',
  47. prop: 'name',
  48. component: 'by-input',
  49. labelWidth: '70px',
  50. compConfig: {
  51. attr: {
  52. placeholder: '请输入名称',
  53. clearable: true
  54. },
  55. },
  56. }, {
  57. span: 6,
  58. label: '简称',
  59. prop: 'shortName',
  60. component: 'by-input',
  61. labelWidth: '70px',
  62. compConfig: {
  63. attr: {
  64. placeholder: '请输入简称',
  65. clearable: true
  66. }
  67. }
  68. },
  69. {
  70. span: 6,
  71. label: '状态',
  72. prop: 'status',
  73. labelWidth: '70px',
  74. component: 'by-select',
  75. compConfig: {
  76. attr: {
  77. placeholder: '请选择状态',
  78. clearable: true,
  79. size: 'small',
  80. data: [{
  81. value: 0,
  82. label: '正常'
  83. }, {
  84. value: 1,
  85. label: '禁用'
  86. }]
  87. }
  88. }
  89. },
  90. ]
  91. ]
  92. },
  93. tool: {
  94. tools: {
  95. add: true,
  96. delete: true,
  97. search: true,
  98. refresh: true
  99. }
  100. },
  101. table: {
  102. attr: {
  103. size: 'mini',
  104. align: 'left',
  105. checkbox: true,
  106. },
  107. columns: [{
  108. title: '名称',
  109. field: 'name',
  110. isDetail: true,
  111. width: 300,
  112. }, {
  113. title: '简称',
  114. field: 'shortName',
  115. width: 300,
  116. },
  117. {
  118. width: 500,
  119. title: '备注',
  120. field: 'remark',
  121. },
  122. {
  123. width: 80,
  124. title: '状态',
  125. field: 'status',
  126. align: 'center',
  127. component: Assembly,
  128. },
  129. {
  130. width: 120,
  131. title: '操作',
  132. action: true,
  133. plugins: [{
  134. icon: 'el-icon-edit',
  135. name: '编辑',
  136. audit: '',
  137. event: {
  138. click: (item : any) => {
  139. (this as any).openEdit(item)
  140. }
  141. }
  142. }, {
  143. name: '删除',
  144. event: {
  145. click: (item : any) => (this as any).doDelete(item)
  146. }
  147. }]
  148. }]
  149. },
  150. }
  151. addConfig = {
  152. attr: {
  153. size: 'small',
  154. rules: {
  155. name: [{
  156. required: true, message: '请输入名称', trigger: 'blur'
  157. }],
  158. shortName: [{
  159. required: true, message: '请输入简称', trigger: 'blur'
  160. }]
  161. }
  162. },
  163. columns: [
  164. [
  165. {
  166. span: 23,
  167. labelWidth: '70px',
  168. label: '名称',
  169. prop: 'name',
  170. component: 'by-input',
  171. },
  172. {
  173. span: 23,
  174. labelWidth: '70px',
  175. label: '简称',
  176. prop: 'shortName',
  177. component: 'by-input',
  178. },
  179. {
  180. span: 23,
  181. labelWidth: '70px',
  182. label: '状态',
  183. slot: true,
  184. prop: 'status',
  185. },
  186. ],
  187. [
  188. {
  189. span: 23,
  190. labelWidth: '70px',
  191. label: '备注',
  192. prop: 'remark',
  193. component: 'by-input',
  194. compConfig: {
  195. attr: {
  196. size: 'mini',
  197. placeholder: '请输入备注',
  198. type: 'textarea'
  199. },
  200. }
  201. },
  202. ]
  203. ]
  204. }
  205. mounted() {
  206. this.timer = setInterval(() => {
  207. this.getDataList()
  208. }, 300)
  209. }
  210. // 确认新增/编辑
  211. confirm() {
  212. (this as any).$refs.addFormId.validate().then(() => {
  213. let query = (this as any).$refs.addFormId.getValue();
  214. // console.log(query);
  215. query.status = this.radio;
  216. this.dialogFormVisible = false;
  217. if (this.popTitle === '新增') {
  218. api.saveList(query, 'maindataMaterialBrand').then((res : any) => {
  219. if (res.code === 200) {
  220. this.$message.success('新增成功');
  221. this.getDataList();
  222. } else this.$message.error(res.msg);
  223. }).catch(() => {});
  224. } else if (this.popTitle === '编辑') {
  225. api.updateList(query, 'maindataMaterialBrand').then((res : any) => {
  226. if (res.code === 200) {
  227. this.$message.success('编辑成功');
  228. this.getDataList();
  229. } else this.$message.error(res.msg);
  230. }).catch(() => {});
  231. }
  232. }).catch(() => {});
  233. }
  234. // 获取列表数据
  235. getDataList() {
  236. if (!this.$refs.moduleView) {
  237. if (this.timeNum > 5) {
  238. clearInterval(this.timer)
  239. }
  240. this.timeNum++;
  241. return
  242. }
  243. clearInterval(this.timer)
  244. let query = (this.$refs.moduleView as any).getQuery();
  245. this.getPageList(query);
  246. }
  247. getPageList(query : any) {
  248. let loading = this.$loading({ target: '.main-container' });
  249. api.pageList(query, 'maindataMaterialBrand').then((res : any) => {
  250. loading.close();
  251. if (res.code === 200) {
  252. (this.$refs.moduleView as any).setTableValue(res.data.records);
  253. let page = {
  254. pageNo: res.data.current, //当前页
  255. pageSize: res.data.size, //每页条数
  256. total: res.data.total //总条数
  257. };
  258. (this.$refs.moduleView as any).setPage(page);
  259. } else this.$message.error(res.msg);
  260. }).catch(() => loading.close());
  261. }
  262. // 工具栏方法
  263. clickHandle(e : any) {
  264. if (e === 'onAdd') this.onAdd();
  265. if (e === 'onDelete') this.onDelete();
  266. }
  267. // 打开新增
  268. onAdd() {
  269. this.popTitle = '新增';
  270. this.dialogFormVisible = true;
  271. this.radio = 0;
  272. this.$nextTick(() => (this as any).$refs.addFormId.setValue());
  273. }
  274. // 打开编辑
  275. openEdit(e : any) {
  276. this.popTitle = '编辑';
  277. let loading = this.$loading({ target: '.main-container' });
  278. api.single({ id: e.id }, 'maindataMaterialBrand').then((res : any) => {
  279. loading.close();
  280. if (res.code === 200) {
  281. let data = res.data;
  282. this.dialogFormVisible = true;
  283. this.radio = data.status;
  284. this.$nextTick(() => (this as any).$refs.addFormId.setValue(data));
  285. }
  286. }).catch(() => loading.close());
  287. }
  288. // 工具栏删除
  289. onDelete() {
  290. let selectData = (this.$refs.moduleView as any).getSelectData()
  291. let ids = '';
  292. if (selectData.length > 0) {
  293. selectData.map((v : any) => {
  294. ids += v.id + ','
  295. })
  296. } else return this.$message.warning('请选择删除数据');
  297. ids = ids.slice(0, ids.length - 1);
  298. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  299. confirmButtonText: '确定',
  300. cancelButtonText: '取消',
  301. type: 'warning',
  302. center: true
  303. }).then(() => {
  304. api.deleteList({ ids: ids }, 'maindataMaterialBrand').then((res : any) => {
  305. if (res.code === 200) {
  306. this.getDataList();
  307. this.$message.success('删除成功');
  308. } else this.$message.error(res.msg);
  309. }).catch(() => {});
  310. }).catch(() => this.$message.info('已取消删除'));
  311. }
  312. // 操作删除
  313. doDelete(item : any) {
  314. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  315. confirmButtonText: '确定',
  316. cancelButtonText: '取消',
  317. type: 'warning',
  318. center: true
  319. }).then(() => {
  320. api.deleteList({ ids: item.id }, 'maindataMaterialBrand').then((res : any) => {
  321. if (res.code === 200) {
  322. this.getDataList();
  323. this.$message.success('删除成功');
  324. } else this.$message.error(res.msg);
  325. }).catch(() => {});
  326. }).catch(() => this.$message.info('已取消删除'));
  327. }
  328. // 刷新/重置
  329. onRefresh() {
  330. (this as any).$refs.moduleView.clearSearch();
  331. this.getDataList();
  332. }
  333. }
  334. </script>
  335. <style lang="scss" scoped>
  336. .my-container {
  337. width: 100%;
  338. box-sizing: border-box;
  339. display: flex;
  340. padding: 16px;
  341. height: 100%;
  342. .bill-left {
  343. position: relative;
  344. border-right: solid #EEE 1px;
  345. flex-shrink: 0;
  346. .bill-tab {
  347. width: 150px;
  348. height: 100%;
  349. transition: all .5s;
  350. overflow: hidden;
  351. }
  352. .tab-title {
  353. font-size: 16px;
  354. padding-bottom: 16px;
  355. width: 200px;
  356. }
  357. }
  358. .bill-main {
  359. width: 100%;
  360. box-sizing: border-box;
  361. position: relative;
  362. height: 100%;
  363. overflow-y: hidden;
  364. }
  365. }
  366. </style>