costFormAddEdit.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="18vh"
  8. width="500px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="showModelThis = false"
  15. >
  16. <el-card style="margin: -20px 0 0 0">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. :size="'small'"
  24. :rules="rulesThis"
  25. label-width="80px"
  26. class="demo-ruleForm"
  27. >
  28. <el-form-item label="起订量" prop="min_num">
  29. <el-input
  30. placeholder="起订量"
  31. v-model="ruleForm.min_num"
  32. type="number"
  33. :min="0"
  34. :max="9999999999"
  35. :step="0"
  36. />
  37. </el-form-item>
  38. <el-form-item label="成本合计" prop="nake_fee">
  39. <el-input
  40. placeholder="成本合计"
  41. v-model="ruleForm.nake_fee"
  42. type="number"
  43. :min="0"
  44. :max="9999999999.99"
  45. :step="2"
  46. >
  47. <template slot="append"></template>
  48. </el-input>
  49. </el-form-item>
  50. <el-form-item label="工艺费" prop="cost_fee">
  51. <el-input
  52. placeholder="工艺费"
  53. v-model="ruleForm.cost_fee"
  54. type="number"
  55. :min="0"
  56. :max="9999999999.99"
  57. :step="2"
  58. >
  59. <template slot="append"></template>
  60. </el-input>
  61. </el-form-item>
  62. <el-form-item label="其中运费" prop="delivery_fee">
  63. <el-input
  64. placeholder="其中运费"
  65. v-model="ruleForm.delivery_fee"
  66. type="number"
  67. :min="0"
  68. :max="9999999999.99"
  69. :step="2"
  70. >
  71. <template slot="append"></template>
  72. </el-input>
  73. </el-form-item>
  74. </el-form>
  75. </el-col>
  76. <el-col :span="24" style="text-align: right">
  77. <el-button :size="'small'" type="primary" @click="submitForm"
  78. >保 存
  79. </el-button>
  80. <el-button @click="showModelThis = false" :size="'small'">{{
  81. "取 消"
  82. }}</el-button>
  83. </el-col>
  84. </el-row>
  85. </el-card>
  86. </el-dialog>
  87. </template>
  88. <script>
  89. import resToken from "@/mixins/resToken";
  90. export default {
  91. name: "brand",
  92. props: ["showModel", "index", "sitem"],
  93. mixins: [resToken],
  94. data() {
  95. return {
  96. loading: false,
  97. title: "",
  98. showModelThis: this.showModel,
  99. ruleForm: {},
  100. rulesThis: this.rules,
  101. rules: {
  102. min_num: [
  103. { required: true, message: "起订量应为合法数字", trigger: "blur" },
  104. ],
  105. cost_fee: [
  106. { required: true, message: "工艺费应为合法数字", trigger: "blur" },
  107. ],
  108. nake_fee: [
  109. { required: true, message: "成本合计应为合法数字", trigger: "blur" },
  110. ],
  111. delivery_fee: [
  112. { required: true, message: "其中运费应为合法数字", trigger: "blur" },
  113. ],
  114. },
  115. };
  116. },
  117. watch: {
  118. showModel: function (val) {
  119. this.showModelThis = val;
  120. if (val) {
  121. this.initForm();
  122. }
  123. },
  124. showModelThis(val) {
  125. if (!val) {
  126. this.$emit("cancel");
  127. }
  128. },
  129. },
  130. methods: {
  131. async initForm() {
  132. this.loading = true;
  133. await this.resetFormData();
  134. console.log(this.index);
  135. if (this.index + "" === "-1") {
  136. this.title = "添加成本阶梯";
  137. } else {
  138. this.title = "修改成本阶梯";
  139. }
  140. await this.resetForm();
  141. this.loading = false;
  142. },
  143. async resetForm() {
  144. // 重置
  145. await this.$nextTick(async () => {
  146. if (this.$refs.ruleForm) {
  147. this.$refs.ruleForm.resetFields();
  148. this.$refs.ruleForm.clearValidate();
  149. await this.resetFormData();
  150. }
  151. });
  152. },
  153. async resetFormData() {
  154. const { id, min_num, cost_fee, nake_fee, delivery_fee } = this.sitem;
  155. this.ruleForm = {
  156. id: id || "",
  157. index: this.index,
  158. min_num: min_num || "",
  159. cost_fee: cost_fee || "",
  160. nake_fee: nake_fee || "",
  161. delivery_fee: delivery_fee || "",
  162. };
  163. },
  164. async submitForm() {
  165. await this.$refs.ruleForm.validate(async (valid) => {
  166. if (valid) {
  167. this.showModelThis = false;
  168. // 刷新
  169. this.$emit("refresh", this.ruleForm);
  170. } else {
  171. console.log("error submit!!");
  172. return false;
  173. }
  174. });
  175. },
  176. },
  177. };
  178. </script>
  179. <style lang="scss" scoped>
  180. .brand {
  181. }
  182. </style>