index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <script>
  2. import useColumns from "./columns";
  3. import dealerApi from "@/api/marketing/dealer-authorization";
  4. export default {
  5. name: "authprivAdd",
  6. props: {
  7. dict: {
  8. type: Object,
  9. },
  10. },
  11. components: {
  12. ElSuperForm: () => import("@/components/super-form/index.vue"),
  13. },
  14. data() {
  15. const { FormColumns } = useColumns();
  16. const rules = this.$init.rules([...FormColumns]);
  17. const params = this.$init.params(FormColumns);
  18. return {
  19. visible: false,
  20. loading: false,
  21. FormColumns: FormColumns,
  22. params: params,
  23. rules: rules,
  24. width: "500px",
  25. option: "add",
  26. };
  27. },
  28. computed: {
  29. title: {
  30. get() {
  31. if (this.option === "edit") {
  32. return "编 辑";
  33. } else if (this.option === "check") {
  34. return "查 看";
  35. } else {
  36. return "新 增";
  37. }
  38. },
  39. set() {},
  40. },
  41. disabled: {
  42. get() {
  43. if (this.option === "check") return true;
  44. return false;
  45. },
  46. set() {},
  47. },
  48. },
  49. methods: {
  50. // 控制弹窗展示
  51. setVisible(val) {
  52. this.visible = val;
  53. },
  54. setFormData(data, op) {
  55. this.option = op;
  56. if (data.id) {
  57. this.loading = true;
  58. this.params = {
  59. ...data,
  60. time: [data.startTime, data.endTime],
  61. };
  62. setTimeout(() => {
  63. this.loading = false;
  64. }, 250);
  65. return;
  66. }
  67. },
  68. // 取消
  69. handleCancel() {
  70. this.params = this.$init.params(this.FormColumns);
  71. this.$refs["authprivAdd"].resetFields();
  72. this.setVisible(false);
  73. this.$emit("close");
  74. },
  75. // 确定
  76. handleConfirm(formName) {
  77. this.$refs[formName].validate(async (valid) => {
  78. if (valid) {
  79. // 校验通过
  80. let isTime =
  81. this.params.time &&
  82. this.params.time != "" &&
  83. this.params.time.length;
  84. // name:工号 nickName:名字
  85. const { name, nickName } = this.$store.state.user;
  86. let params = {
  87. ...this.params,
  88. startTime: isTime ? this.params.time[0] : "",
  89. endTime: isTime ? this.params.time[1] : "",
  90. updatePerson: nickName,
  91. updateBy: name,
  92. updateTime: new Date().Format(),
  93. ...(this.option === "add"
  94. ? {
  95. status: "0",
  96. createPerson: nickName,
  97. createBy: name,
  98. createTime: new Date().Format(),
  99. }
  100. : {}),
  101. };
  102. delete params["time"];
  103. try {
  104. this.loading = true;
  105. let { code, msg } = await (this.option === "add"
  106. ? dealerApi.insert(params)
  107. : dealerApi.update(params));
  108. if (code === 200) {
  109. this.handleCancel();
  110. }
  111. } catch (error) {
  112. console.log(error, "error");
  113. } finally {
  114. this.loading = false;
  115. }
  116. } else {
  117. return false;
  118. }
  119. });
  120. },
  121. },
  122. };
  123. </script>
  124. <template>
  125. <el-dialog
  126. :width="width"
  127. :title="title"
  128. :visible.sync="visible"
  129. :close-on-click-modal="false"
  130. :close-on-press-escape="false"
  131. @close="handleCancel"
  132. >
  133. <el-super-form
  134. v-model="params"
  135. :dict="dict"
  136. :rules="rules"
  137. :size="$attrs.size"
  138. :disabled="disabled"
  139. :columns="FormColumns"
  140. ref="authprivAdd"
  141. label-width="auto"
  142. label-position="right"
  143. style="padding: 20px"
  144. >
  145. </el-super-form>
  146. <div slot="footer" v-if="this.option !== 'check'">
  147. <el-button
  148. type="primary"
  149. :size="$attrs.size"
  150. @click="handleConfirm('authprivAdd')"
  151. >确 定</el-button
  152. >
  153. <el-button :size="$attrs.size" @click="handleCancel">取 消</el-button>
  154. </div>
  155. </el-dialog>
  156. </template>
  157. <style scoped>
  158. >>> .el-dialog__body {
  159. padding: 0px 20px;
  160. }
  161. ::v-deep.superForm .el-form-item {
  162. margin: 0 0 16px !important;
  163. }
  164. </style>