editPrice.vue 5.0 KB

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