index.vue 8.6 KB

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