grossForm.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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="
  22. (status === '5' || status === '6') &&
  23. powers &&
  24. powers.length > 0 &&
  25. powers.some((item) => item == '060')
  26. "
  27. :controls="false"
  28. :append="'%'"
  29. @reschange="rate_change"
  30. />
  31. </el-form-item>
  32. </el-col>
  33. <el-col
  34. :span="12"
  35. style="text-align: right"
  36. v-if="
  37. (status !== '5' || status !== '6') &&
  38. powers &&
  39. powers.length > 0 &&
  40. powers.some((item) => item == '060')
  41. "
  42. >
  43. <el-button type="primary" :size="'mini'" @click="submitForm"
  44. >保 存
  45. </el-button>
  46. </el-col>
  47. </el-row>
  48. </el-form>
  49. </template>
  50. <script>
  51. import asyncRequest from "@/apis/service/sellOut/project";
  52. import resToken from "@/mixins/resToken";
  53. export default {
  54. name: "Account",
  55. props: ["showModel", "sitem", "id", "type"],
  56. mixins: [resToken],
  57. computed: {
  58. powers() {
  59. let tran =
  60. this.$store.getters.btnList.find(
  61. (item) => item.menu_route == "projectDetail"
  62. ) || {};
  63. if (tran && tran.action && tran.action.length > 0) {
  64. return tran.action;
  65. } else {
  66. return [];
  67. }
  68. },
  69. },
  70. watch: {
  71. // showModel: function (val) {
  72. // this.showModelThis = val;
  73. // if (val) {
  74. // this.initForm();
  75. // }
  76. // },
  77. // showModelThis(val) {
  78. // if (!val) {
  79. // this.$emit("cancel");
  80. // }
  81. // },
  82. },
  83. data() {
  84. const validate_sale_price = (rule, value, callback) => {
  85. if (value === "") {
  86. callback(new Error("项目毛利率不能为空!"));
  87. } else if (
  88. value === "0" ||
  89. value === "0." ||
  90. value === "0.0" ||
  91. value === "0.00"
  92. ) {
  93. callback(new Error("项目毛利率不能为零!"));
  94. } else {
  95. callback();
  96. }
  97. };
  98. return {
  99. loading: false,
  100. ruleForm: {
  101. projectNo: "",
  102. rate: "0",
  103. },
  104. rulesThis: this.rules,
  105. rules: {
  106. rate: [
  107. {
  108. required: true,
  109. validator: validate_sale_price,
  110. trigger: "blur",
  111. },
  112. ],
  113. },
  114. };
  115. },
  116. mounted() {
  117. this.initForm();
  118. },
  119. methods: {
  120. //项目毛利率编辑
  121. rate_change(e) {
  122. this.ruleForm.rate = e + "";
  123. this.$refs.ruleForm.validateField("rate");
  124. },
  125. //初始化整个组件
  126. async initForm() {
  127. this.loading = true;
  128. this.company = "";
  129. this.ruleForm = {
  130. projectNo: "",
  131. rate: "0",
  132. };
  133. this.rulesThis = this.rules;
  134. await this.resetForm();
  135. this.loading = false;
  136. },
  137. //初始化整个表单
  138. async resetForm() {
  139. // 重置
  140. await this.$nextTick(() => {
  141. if (this.$refs.ruleForm) {
  142. this.$refs.ruleForm.resetFields();
  143. this.$refs.ruleForm.clearValidate();
  144. const { low_rate, projectNo, status } = this.sitem;
  145. this.status = status || "";
  146. this.ruleForm = {
  147. projectNo: projectNo || "",
  148. rate: low_rate || "0",
  149. };
  150. }
  151. });
  152. },
  153. async submitForm() {
  154. await this.$refs.ruleForm.validate(async (valid) => {
  155. if (valid) {
  156. this.loading = true;
  157. let model = JSON.parse(JSON.stringify(this.ruleForm));
  158. let res = await asyncRequest.rateEdit(model);
  159. this.loading = false;
  160. if (res && res.code === 0) {
  161. this.$notify.success({
  162. title: "设置成功!",
  163. message: "",
  164. });
  165. this.showModelThis = false;
  166. // 刷新
  167. this.$emit("refresh", res.data);
  168. } else if (res && res.code >= 100 && res.code <= 104) {
  169. await this.logout();
  170. } else {
  171. this.$message.warning(res.message);
  172. }
  173. } else {
  174. console.log("error submit!!");
  175. return false;
  176. }
  177. });
  178. },
  179. },
  180. };
  181. </script>
  182. <style lang="scss" scoped>
  183. .account {
  184. }
  185. </style>