grossForm.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <el-form
  3. ref="ruleForm"
  4. :model="ruleForm"
  5. status-icon
  6. :size="'mini'"
  7. :rules="rulesThis"
  8. label-width="112px"
  9. >
  10. <el-row>
  11. <el-col :span="12">
  12. <el-form-item label="项目毛利率" prop="rate">
  13. <digital-input
  14. :values="ruleForm.rate"
  15. :placeholder="'项目毛利率'"
  16. :min="0"
  17. :max="100000000000"
  18. :position="'right'"
  19. :precision="2"
  20. :size="'mini'"
  21. :disabled="false"
  22. :controls="false"
  23. :append="'%'"
  24. @reschange="rate_change"
  25. />
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="12" style="text-align: right">
  29. <el-button type="primary" :size="'mini'" @click="submitForm"
  30. >保 存
  31. </el-button>
  32. </el-col>
  33. </el-row>
  34. </el-form>
  35. </template>
  36. <script>
  37. import asyncRequest from "@/apis/service/sheetOrder/project";
  38. import resToken from "@/mixins/resToken";
  39. export default {
  40. name: "Account",
  41. props: ["showModel", "sitem", "id", "type"],
  42. mixins: [resToken],
  43. watch: {
  44. // showModel: function (val) {
  45. // this.showModelThis = val;
  46. // if (val) {
  47. // this.initForm();
  48. // }
  49. // },
  50. // showModelThis(val) {
  51. // if (!val) {
  52. // this.$emit("cancel");
  53. // }
  54. // },
  55. },
  56. data() {
  57. const validate_sale_price = (rule, value, callback) => {
  58. if (value === "") {
  59. callback(new Error("项目毛利率不能为空!"));
  60. } else if (
  61. value === "0" ||
  62. value === "0." ||
  63. value === "0.0" ||
  64. value === "0.00"
  65. ) {
  66. callback(new Error("项目毛利率不能为零!"));
  67. } else {
  68. callback();
  69. }
  70. };
  71. return {
  72. loading: false,
  73. ruleForm: {
  74. projectNo: "",
  75. rate: "0",
  76. },
  77. rulesThis: this.rules,
  78. rules: {
  79. rate: [
  80. {
  81. required: true,
  82. validator: validate_sale_price,
  83. trigger: "blur",
  84. },
  85. ],
  86. },
  87. };
  88. },
  89. mounted() {
  90. this.initForm();
  91. },
  92. methods: {
  93. //项目毛利率编辑
  94. rate_change(e) {
  95. this.ruleForm.rate = e + "";
  96. this.$refs.ruleForm.validateField("rate");
  97. },
  98. //初始化整个组件
  99. async initForm() {
  100. this.loading = true;
  101. this.company = "";
  102. this.ruleForm = {
  103. projectNo: "",
  104. rate: "0",
  105. };
  106. this.rulesThis = this.rules;
  107. await this.resetForm();
  108. this.loading = false;
  109. },
  110. //初始化整个表单
  111. async resetForm() {
  112. // 重置
  113. await this.$nextTick(() => {
  114. if (this.$refs.ruleForm) {
  115. this.$refs.ruleForm.resetFields();
  116. this.$refs.ruleForm.clearValidate();
  117. const { rate, projectNo } = this.sitem;
  118. this.ruleForm = {
  119. projectNo: projectNo || "",
  120. rate: rate || "0",
  121. };
  122. }
  123. });
  124. },
  125. async submitForm() {
  126. await this.$refs.ruleForm.validate(async (valid) => {
  127. if (valid) {
  128. this.loading = true;
  129. let model = JSON.parse(JSON.stringify(this.ruleForm));
  130. let res = await asyncRequest.rateEdit(model);
  131. this.loading = false;
  132. if (res && res.code === 0) {
  133. this.$notify.success({
  134. title: "设置成功!",
  135. message: "",
  136. });
  137. this.showModelThis = false;
  138. // 刷新
  139. this.$emit("refresh", res.data);
  140. } else if (res && res.code >= 100 && res.code <= 104) {
  141. await this.logout();
  142. } else {
  143. this.$message.warning(res.message);
  144. }
  145. } else {
  146. console.log("error submit!!");
  147. return false;
  148. }
  149. });
  150. },
  151. },
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. .account {
  156. }
  157. </style>