PagePropEdit.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="page-prop-edit">
  3. <el-form ref="form" :model="form" label-width="70px">
  4. <el-form-item label="纸张规格">
  5. <el-select
  6. v-model="form.pageSize"
  7. placeholder="请选择"
  8. :disabled="pageSizeOptions.length < 2"
  9. @change="modifyPageSize"
  10. >
  11. <el-option
  12. v-for="item in pageSizeOptions"
  13. :key="item"
  14. :label="item"
  15. :value="item"
  16. >
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="禁答区域">
  21. <el-checkbox
  22. v-model="form.showForbidArea"
  23. @change="showForbidAreaChange"
  24. >启用</el-checkbox
  25. >
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. </template>
  30. <script>
  31. import { mapState, mapMutations, mapActions } from "vuex";
  32. import { objAssign } from "../../../plugins/utils";
  33. import { getModel as getPageModel } from "../../../elements/page/model";
  34. const COLUMN_OPTIONS = [
  35. {
  36. value: 1,
  37. title: "一栏",
  38. label: "one",
  39. sizeValid: ["A3", "A4"]
  40. },
  41. {
  42. value: 2,
  43. title: "二栏",
  44. label: "two",
  45. sizeValid: ["A3", "A4"]
  46. },
  47. {
  48. value: 3,
  49. title: "三栏",
  50. label: "three",
  51. sizeValid: ["A3"]
  52. },
  53. {
  54. value: 4,
  55. title: "四栏",
  56. label: "four",
  57. sizeValid: ["A3"]
  58. }
  59. ];
  60. export default {
  61. name: "page-prop-edit",
  62. data() {
  63. return {
  64. columnOptions: [],
  65. pageSizeOptions: ["A3", "A4"],
  66. form: {
  67. pageSize: "A3",
  68. columnNumber: 2,
  69. showForbidArea: false
  70. },
  71. prePageSize: "A3"
  72. };
  73. },
  74. computed: {
  75. ...mapState("free", ["curPageNo", "pages", "cardConfig"]),
  76. curPage() {
  77. return this.pages[this.curPageNo];
  78. }
  79. },
  80. watch: {
  81. cardConfig: {
  82. immediate: true,
  83. handler(val) {
  84. this.form = objAssign(this.form, val);
  85. this.prePageSize = this.form.pageSize;
  86. this.columnOptions = COLUMN_OPTIONS.filter(item =>
  87. item.sizeValid.includes(this.form.pageSize)
  88. );
  89. }
  90. }
  91. },
  92. methods: {
  93. ...mapMutations("free", [
  94. "setPages",
  95. "setCurElement",
  96. "setCardConfig",
  97. "setCurPageNo"
  98. ]),
  99. ...mapActions("free", ["modifyAllPageShowForbidArea"]),
  100. showForbidAreaChange() {
  101. this.setCardConfig(this.form);
  102. this.modifyAllPageShowForbidArea(this.form.showForbidArea);
  103. },
  104. configChange() {
  105. this.setCardConfig(this.form);
  106. const page = getPageModel(this.form);
  107. this.setPages([page]);
  108. this.setCurPageNo(0);
  109. this.setCurElement({});
  110. },
  111. modifyPageSize() {
  112. this.$confirm("此操作将会重置所有页面, 是否继续?", "提示", {
  113. type: "warning"
  114. })
  115. .then(() => {
  116. this.columnOptions = COLUMN_OPTIONS.filter(item =>
  117. item.sizeValid.includes(this.form.pageSize)
  118. );
  119. this.form.columnNumber = this.columnOptions[0].value;
  120. this.configChange();
  121. })
  122. .catch(() => {
  123. this.form.pageSize = this.prePageSize;
  124. });
  125. }
  126. }
  127. };
  128. </script>