addEditRate.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="'设置毛利率'"
  5. :center="true"
  6. align="left"
  7. top="12vh"
  8. width="600px"
  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="0">
  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="110px"
  26. class="demo-ruleForm"
  27. >
  28. <el-form-item label="分类名称" prop="cat_name">
  29. <el-input
  30. v-model="ruleForm.cat_name"
  31. disabled
  32. placeholder="分类名称"
  33. maxlength="20"
  34. ><template slot="prepend" v-if="pid_name">{{
  35. pid_name
  36. }}</template></el-input
  37. >
  38. </el-form-item>
  39. <el-form-item label="财务核算码" prop="fund_code">
  40. <el-input
  41. v-model="ruleForm.fund_code"
  42. disabled
  43. placeholder="财务核算码"
  44. maxlength="50"
  45. />
  46. </el-form-item>
  47. <el-form-item label="预算→成本" prop="order_rate">
  48. <digital-input
  49. :values="ruleForm.order_rate"
  50. :placeholder="'预算→成本'"
  51. :min="0"
  52. :max="100000000000"
  53. :position="'right'"
  54. :precision="2"
  55. :size="'mini'"
  56. :controls="false"
  57. :append="'%'"
  58. @reschange="rate_change($event, 'order_rate')"
  59. />
  60. </el-form-item>
  61. <el-form-item label="成本→售价" prop="sale_rate">
  62. <digital-input
  63. :values="ruleForm.sale_rate"
  64. :placeholder="'成本→售价'"
  65. :min="-100"
  66. :max="100000000000"
  67. :position="'right'"
  68. :precision="2"
  69. :size="'mini'"
  70. :controls="false"
  71. :append="'%'"
  72. @reschange="rate_change($event, 'sale_rate')"
  73. />
  74. </el-form-item>
  75. <el-form-item label="主管利率" prop="rate">
  76. <digital-input
  77. :values="ruleForm.rate"
  78. :placeholder="'主管利率'"
  79. :min="-100"
  80. :max="100000000000"
  81. :position="'right'"
  82. :precision="2"
  83. :size="'mini'"
  84. :controls="false"
  85. :append="'%'"
  86. @reschange="rate_change($event, 'rate')"
  87. />
  88. </el-form-item>
  89. <el-form-item label="财务利率" prop="money_rate">
  90. <digital-input
  91. :values="ruleForm.money_rate"
  92. :placeholder="'财务利率'"
  93. :min="-100"
  94. :max="100000000000"
  95. :position="'right'"
  96. :precision="2"
  97. :size="'mini'"
  98. :controls="false"
  99. :append="'%'"
  100. @reschange="rate_change($event, 'money_rate')"
  101. />
  102. </el-form-item>
  103. <el-form-item label="项目最低毛利" prop="low_rate">
  104. <digital-input
  105. :values="ruleForm.low_rate"
  106. :placeholder="'项目最低毛利'"
  107. :min="-100"
  108. :max="100000000000"
  109. :position="'right'"
  110. :precision="2"
  111. :size="'mini'"
  112. :controls="false"
  113. :append="'%'"
  114. @reschange="rate_change($event, 'low_rate')"
  115. />
  116. </el-form-item>
  117. <!-- <el-form-item label="BOSS毛利率" prop="lower_rate">
  118. <digital-input
  119. :values="ruleForm.lower_rate"
  120. :placeholder="'BOSS毛利率'"
  121. :min="-100"
  122. :max="100000000000"
  123. :position="'right'"
  124. :precision="2"
  125. :size="'mini'"
  126. :controls="false"
  127. :append="'%'"
  128. @reschange="rate_change($event, 'lower_rate')"
  129. />
  130. </el-form-item>-->
  131. </el-form>
  132. </el-col>
  133. <el-col :span="24" style="text-align: right">
  134. <el-button
  135. v-if="id !== '007'"
  136. type="primary"
  137. :size="'small'"
  138. @click="submitForm"
  139. >保 存
  140. </el-button>
  141. <el-button :size="'small'" @click="showModelThis = false">{{
  142. id == "007" ? "关 闭" : "取 消"
  143. }}</el-button>
  144. </el-col>
  145. </el-row>
  146. </el-card>
  147. </el-dialog>
  148. </template>
  149. <script>
  150. import asyncRequest from "@/apis/service/goodStore/sort";
  151. import resToken from "@/mixins/resToken";
  152. export default {
  153. name: "sort",
  154. props: ["showModel", "id", "sitem", "titleList"],
  155. mixins: [resToken],
  156. data() {
  157. const validate_rate = (rule, value, callback) => {
  158. const { required } = rule;
  159. if (value === "" && required) {
  160. callback(new Error("主管利率毛利率不能为空!"));
  161. } else {
  162. callback();
  163. }
  164. };
  165. const validate_order_rate = (rule, value, callback) => {
  166. const { required } = rule;
  167. if (value === "" && required) {
  168. callback(new Error("预算→成本毛利率不能为空!"));
  169. } else {
  170. callback();
  171. }
  172. };
  173. const validate_sale_rate = (rule, value, callback) => {
  174. const { required } = rule;
  175. if (value === "" && required) {
  176. callback(new Error("成本→售价毛利率不能为空!"));
  177. } else {
  178. callback();
  179. }
  180. };
  181. const validate_lower_rate = (rule, value, callback) => {
  182. const { required } = rule;
  183. if (value === "" && required) {
  184. callback(new Error("BOSS毛利率不能为空!"));
  185. } else {
  186. callback();
  187. }
  188. };
  189. const validate_low_rate = (rule, value, callback) => {
  190. const { required } = rule;
  191. if (value === "" && required) {
  192. callback(new Error("项目最低毛利率不能为空!"));
  193. } else {
  194. callback();
  195. }
  196. };
  197. const validate_money_rate = (rule, value, callback) => {
  198. const { required } = rule;
  199. if (value === "" && required) {
  200. callback(new Error("财务毛利率不能为空!"));
  201. } else {
  202. callback();
  203. }
  204. };
  205. return {
  206. loading: false,
  207. showModelThis: this.showModel,
  208. pid_name: "",
  209. ruleForm: {
  210. id: "",
  211. cat_name: "",
  212. order_rate: "0",
  213. sale_rate: "0",
  214. lower_rate: "0",
  215. rate: "0",
  216. low_rate: "0",
  217. money_rate: "0",
  218. },
  219. rulesThis: this.rules,
  220. rules: {
  221. order_rate: [
  222. { required: true, validator: validate_order_rate, trigger: "blur" },
  223. ],
  224. sale_rate: [
  225. { required: true, validator: validate_sale_rate, trigger: "blur" },
  226. ],
  227. lower_rate: [
  228. { required: false, validator: validate_lower_rate, trigger: "blur" },
  229. ],
  230. rate: [{ required: true, validator: validate_rate, trigger: "blur" }],
  231. low_rate: [
  232. { required: true, validator: validate_low_rate, trigger: "blur" },
  233. ],
  234. money_rate: [
  235. { required: true, validator: validate_money_rate, trigger: "blur" },
  236. ],
  237. },
  238. };
  239. },
  240. watch: {
  241. showModel: function (val) {
  242. this.showModelThis = val;
  243. if (val) {
  244. this.initForm();
  245. }
  246. },
  247. showModelThis(val) {
  248. if (!val) {
  249. this.$emit("cancel");
  250. }
  251. },
  252. },
  253. methods: {
  254. async initForm() {
  255. this.loading = true;
  256. this.pid_name = "";
  257. this.titleList.forEach((e, i) => {
  258. this.pid_name += i !== 0 ? `${e.titleName}/` : "";
  259. });
  260. this.rulesThis = this.rules;
  261. await this.resetForm();
  262. await this.initData();
  263. this.loading = false;
  264. },
  265. async resetForm() {
  266. // 重置
  267. await this.$nextTick(() => {
  268. if (this.$refs.ruleForm) {
  269. this.$refs.ruleForm.resetFields();
  270. this.$refs.ruleForm.clearValidate();
  271. const {
  272. pid,
  273. id,
  274. cat_name,
  275. order_rate,
  276. sale_rate,
  277. lower_rate,
  278. rate,
  279. fund_code,
  280. low_rate,
  281. money_rate,
  282. } = this.sitem;
  283. this.ruleForm = {
  284. pid: pid || "",
  285. id: id || "",
  286. cat_name: cat_name || "",
  287. fund_code: fund_code || "",
  288. order_rate: order_rate || "0",
  289. sale_rate: sale_rate || "0",
  290. lower_rate: lower_rate || "0",
  291. rate: rate || "0",
  292. low_rate: low_rate || "0",
  293. money_rate: money_rate || "0",
  294. };
  295. }
  296. });
  297. },
  298. rate_change(e, key) {
  299. this.ruleForm[key] = e + "";
  300. this.$refs.ruleForm.validateField(key);
  301. },
  302. async initData() {
  303. const { code, data, message } = await asyncRequest.detail({
  304. id: this.sitem.id,
  305. });
  306. if (code === 0) {
  307. const {
  308. pid,
  309. id,
  310. cat_name,
  311. order_rate,
  312. sale_rate,
  313. lower_rate,
  314. rate,
  315. fund_code,
  316. low_rate,
  317. money_rate,
  318. } = data;
  319. this.ruleForm = {
  320. pid: pid || "",
  321. id: id || "",
  322. cat_name: cat_name || "",
  323. fund_code: fund_code || "",
  324. order_rate: order_rate || "0",
  325. sale_rate: sale_rate || "0",
  326. lower_rate: lower_rate || "0",
  327. rate: rate || "0",
  328. low_rate: low_rate || "0",
  329. money_rate: money_rate || "0",
  330. };
  331. } else if (code >= 100 && code <= 104) {
  332. await this.logout();
  333. } else {
  334. this.$message.warning(message);
  335. }
  336. },
  337. async submitForm() {
  338. await this.$refs.ruleForm.validate(async (valid) => {
  339. if (valid) {
  340. if (!this.loading) {
  341. this.loading = true;
  342. let model = JSON.parse(JSON.stringify(this.ruleForm));
  343. delete model["cat_name"];
  344. delete model["pid"];
  345. delete model["fund_code"];
  346. let res = await asyncRequest.editRate(model);
  347. this.loading = false;
  348. if (res && res.code === 0) {
  349. this.$notify.success({
  350. title: "毛利率设置成功!",
  351. message: "",
  352. });
  353. this.showModelThis = false;
  354. // 刷新
  355. this.$emit("refresh");
  356. } else if (res && res.code >= 100 && res.code <= 104) {
  357. await this.logout();
  358. } else {
  359. this.$message.warning(res.message);
  360. }
  361. }
  362. } else {
  363. console.log("error submit!!");
  364. return false;
  365. }
  366. });
  367. },
  368. },
  369. };
  370. </script>
  371. <style lang="scss" scoped>
  372. .sort {
  373. }
  374. </style>