costFormAddEdit.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. <digital-input
  30. :values="ruleForm.min_num"
  31. :placeholder="'起订量'"
  32. :min="0"
  33. :name="'ruleForm.min_num'"
  34. :disabled="false"
  35. :max="100000000000"
  36. :position="'right'"
  37. :precision="0"
  38. :size="'mini'"
  39. :controls="false"
  40. :append="''"
  41. @reschange="number_change($event, 'min_num')"
  42. />
  43. </el-form-item>
  44. <el-form-item label="成本合计" prop="nake_fee">
  45. <digital-input
  46. :values="ruleForm.nake_fee"
  47. :placeholder="'成本合计'"
  48. :min="0"
  49. :name="'ruleForm.nake_fee'"
  50. :disabled="false"
  51. :max="100000000000"
  52. :position="'right'"
  53. :precision="2"
  54. :size="'mini'"
  55. :controls="false"
  56. :append="'元'"
  57. @reschange="number_change($event, 'nake_fee')"
  58. />
  59. </el-form-item>
  60. <el-form-item label="工艺费" prop="cost_fee">
  61. <digital-input
  62. :values="ruleForm.cost_fee"
  63. :placeholder="'工艺费'"
  64. :min="0"
  65. :name="'ruleForm.cost_fee'"
  66. :disabled="false"
  67. :max="100000000000"
  68. :position="'right'"
  69. :precision="2"
  70. :size="'mini'"
  71. :controls="false"
  72. :append="'元'"
  73. @reschange="number_change($event, 'cost_fee')"
  74. />
  75. </el-form-item>
  76. <el-form-item label="物流费" prop="delivery_fee">
  77. <digital-input
  78. :values="ruleForm.delivery_fee"
  79. :placeholder="'物流费'"
  80. :min="0"
  81. :name="'ruleForm.delivery_fee'"
  82. :disabled="false"
  83. :max="100000000000"
  84. :position="'right'"
  85. :precision="2"
  86. :size="'mini'"
  87. :controls="false"
  88. :append="'元'"
  89. @reschange="number_change($event, 'delivery_fee')"
  90. />
  91. </el-form-item>
  92. </el-form>
  93. </el-col>
  94. <el-col :span="24" style="text-align: right">
  95. <el-button :size="'small'" type="primary" @click="submitForm"
  96. >保 存
  97. </el-button>
  98. <el-button @click="showModelThis = false" :size="'small'">{{
  99. "取 消"
  100. }}</el-button>
  101. </el-col>
  102. </el-row>
  103. </el-card>
  104. </el-dialog>
  105. </template>
  106. <script>
  107. import resToken from "@/mixins/resToken";
  108. export default {
  109. name: "brand",
  110. props: ["showModel", "index", "sitem"],
  111. mixins: [resToken],
  112. data() {
  113. const validate_num_0 = (rule, value, callback) => {
  114. if (value === "") {
  115. callback(new Error("起订量不能为空!"));
  116. } else if (value === "0") {
  117. callback(new Error("起订量不能为零!"));
  118. } else {
  119. callback();
  120. }
  121. };
  122. return {
  123. loading: false,
  124. title: "",
  125. showModelThis: this.showModel,
  126. ruleForm: {},
  127. rulesThis: this.rules,
  128. rules: {
  129. min_num: [
  130. { required: true, validator: validate_num_0, trigger: "blur" },
  131. ],
  132. cost_fee: [
  133. { required: true, message: "工艺费不能为空!", trigger: "blur" },
  134. ],
  135. nake_fee: [
  136. { required: true, message: "成本合计不能为空!", trigger: "blur" },
  137. ],
  138. delivery_fee: [
  139. { required: true, message: "物流费不能为空!", trigger: "blur" },
  140. ],
  141. },
  142. };
  143. },
  144. watch: {
  145. showModel: function (val) {
  146. this.showModelThis = val;
  147. if (val) {
  148. this.initForm();
  149. }
  150. },
  151. showModelThis(val) {
  152. if (!val) {
  153. this.$emit("cancel");
  154. }
  155. },
  156. },
  157. methods: {
  158. async initForm() {
  159. this.loading = true;
  160. // await this.resetFormData();
  161. console.log(this.index);
  162. if (this.index + "" === "-1") {
  163. this.title = "添加成本阶梯";
  164. } else {
  165. this.title = "修改成本阶梯";
  166. }
  167. this.rulesThis = this.rules;
  168. await this.resetForm();
  169. this.loading = false;
  170. },
  171. async resetForm() {
  172. // 重置
  173. await this.$nextTick(async () => {
  174. if (this.$refs.ruleForm) {
  175. this.$refs.ruleForm.resetFields();
  176. this.$refs.ruleForm.clearValidate();
  177. await this.resetFormData();
  178. }
  179. });
  180. },
  181. async resetFormData() {
  182. if (this.index + "" === "-1") {
  183. this.ruleForm = {
  184. id: "",
  185. index: "-1",
  186. min_num: "0",
  187. cost_fee: "0",
  188. nake_fee: "0",
  189. delivery_fee: "0",
  190. };
  191. } else {
  192. const { id, min_num, cost_fee, nake_fee, delivery_fee } = this.sitem;
  193. this.ruleForm = {
  194. id: id || "",
  195. index: this.index,
  196. min_num: min_num || "0",
  197. cost_fee: cost_fee || "0",
  198. nake_fee: nake_fee || "0",
  199. delivery_fee: delivery_fee || "0",
  200. };
  201. }
  202. },
  203. number_change(e, key) {
  204. this.ruleForm[key] = e + "" || "0";
  205. this.$refs.ruleForm.validateField(key);
  206. },
  207. async submitForm() {
  208. await this.$refs.ruleForm.validate(async (valid) => {
  209. if (valid) {
  210. this.showModelThis = false;
  211. // 刷新
  212. this.$emit("refresh", this.ruleForm);
  213. } else {
  214. console.log("error submit!!");
  215. return false;
  216. }
  217. });
  218. },
  219. },
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .brand {
  224. }
  225. </style>