addEdit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :center="true"
  5. align="left"
  6. top="5vh"
  7. width="600px"
  8. @close="showModelThis = false"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. v-loading="loading"
  12. element-loading-text="拼命加载中"
  13. element-loading-spinner="el-icon-loading"
  14. element-loading-background="rgba(0, 0, 0, 0.8)"
  15. >
  16. <el-card style="margin-top: -20px">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. :model="ruleForm"
  21. status-icon
  22. :rules="rulesThis"
  23. ref="ruleForm"
  24. label-width="110px"
  25. class="demo-ruleForm"
  26. >
  27. <el-form-item label="供应商名称" prop="wsm_supplier">
  28. <el-input
  29. v-model="ruleForm.wsm_supplier"
  30. disabled
  31. placeholder="请选择供应商"
  32. />
  33. </el-form-item>
  34. <el-form-item label="仓库名称" prop="wsm_name">
  35. <el-input
  36. v-model="ruleForm.wsm_name"
  37. disabled
  38. placeholder="请选择备库仓库"
  39. />
  40. </el-form-item>
  41. <el-form-item label="商品名称" prop="good_name">
  42. <el-input v-model="ruleForm.good_name" disabled></el-input>
  43. </el-form-item>
  44. <el-form-item label="预警数量" prop="warn_stock">
  45. <el-input v-model="ruleForm.warn_stock"></el-input>
  46. </el-form-item>
  47. </el-form>
  48. </el-col>
  49. <el-col :span="24" style="text-align: right">
  50. <el-button type="primary" @click="submitForm" v-if="!isDetail"
  51. >保 存
  52. </el-button>
  53. <el-button @click="showModelThis = false">{{
  54. isDetail ? "关 闭" : "取 消"
  55. }}</el-button>
  56. </el-col>
  57. </el-row>
  58. </el-card>
  59. </el-dialog>
  60. </template>
  61. <script>
  62. import asyncRequest from "@/apis/service/stock/stockWarning";
  63. import resToken from "@/mixins/resToken";
  64. import { isnumber } from "@/utils/validate";
  65. export default {
  66. name: "stockWarning",
  67. props: ["showModel", "row", "isDetail", "sitem"],
  68. mixins: [resToken],
  69. data() {
  70. const validateWarn_stock = (rule, value, callback) => {
  71. if (value === "") {
  72. callback(new Error("预计数量不能为空!"));
  73. } else {
  74. if (isnumber(value)) {
  75. callback();
  76. } else {
  77. callback(new Error("预计数量仅支持数字!"));
  78. }
  79. }
  80. };
  81. return {
  82. title: "库存预警修改",
  83. companyCode: "",
  84. loading: false,
  85. showModelThis: this.showModel,
  86. ruleForm: {
  87. good_code: "",
  88. wsm_code: "",
  89. wsm_name: "",
  90. good_name: "",
  91. warn_stock: "",
  92. },
  93. rulesThis: this.rules,
  94. rules: {
  95. warn_stock: [
  96. {
  97. required: true,
  98. validator: validateWarn_stock,
  99. trigger: "blur",
  100. },
  101. ],
  102. good_name: [
  103. {
  104. message: "产品名称不能为空",
  105. required: true,
  106. trigger: "blur",
  107. },
  108. ],
  109. wsm_supplier: [
  110. {
  111. required: true,
  112. message: "请选择供应商",
  113. trigger: "blue",
  114. },
  115. ],
  116. wsm_name: [
  117. {
  118. required: true,
  119. message: "请选择仓库",
  120. trigger: "blur",
  121. },
  122. ],
  123. },
  124. };
  125. },
  126. watch: {
  127. showModel: function (val) {
  128. this.showModelThis = val;
  129. if (val) {
  130. this.initForm();
  131. }
  132. },
  133. showModelThis(val) {
  134. if (!val) {
  135. this.$emit("cancel");
  136. }
  137. },
  138. sitem(val) {
  139. let {
  140. good_name,
  141. warn_stock,
  142. wsm_name,
  143. wsm_supplier,
  144. wsm_code,
  145. type_code,
  146. } = val;
  147. this.ruleForm = {
  148. wsm_supplier,
  149. wsm_name,
  150. good_name,
  151. warn_stock,
  152. wsm_code,
  153. good_code: type_code,
  154. };
  155. },
  156. },
  157. methods: {
  158. // 关闭弹窗
  159. async initForm() {
  160. this.loading = true;
  161. this.title = "库存预警修改";
  162. this.rulesThis = this.rules;
  163. this.loading = false;
  164. },
  165. async submitForm() {
  166. await this.$refs.ruleForm.validate(async (valid) => {
  167. if (valid) {
  168. this.loading = true;
  169. let model = {
  170. warn_stock: this.ruleForm.warn_stock,
  171. type_code: this.ruleForm.good_code,
  172. wsm_code: this.ruleForm.wsm_code,
  173. };
  174. const res = await asyncRequest.update(model);
  175. this.loading = false;
  176. if (res && res.code === 0) {
  177. const title = this.id === "add" ? "添加成功" : "修改成功";
  178. this.$notify.success({
  179. title,
  180. message: "",
  181. });
  182. this.showModelThis = false;
  183. // 刷新
  184. this.$emit("refresh");
  185. } else if (res && res.code >= 100 && res.code <= 104) {
  186. await this.logout();
  187. } else {
  188. this.$message.warning(res.message);
  189. }
  190. } else {
  191. console.log("error submit!!");
  192. return false;
  193. }
  194. });
  195. },
  196. },
  197. };
  198. </script>