addEdit.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :center="true"
  5. align="left"
  6. top="15vh"
  7. width="700px"
  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:-20px 0 0 0;">
  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="140px"
  25. class="demo-ruleForm"
  26. >
  27. <el-form-item
  28. label="退货验收异常原因"
  29. prop="result"
  30. v-if="id === 'add' || (isDetail ? true : true)"
  31. >
  32. <el-input
  33. v-model="ruleForm.result"
  34. :disabled="isDetail"
  35. ></el-input>
  36. </el-form-item>
  37. <el-form-item
  38. label="异常备注"
  39. prop="result_desc"
  40. v-if="id === 'add' || (isDetail ? true : true)"
  41. >
  42. <el-input
  43. :autosize="{ minRows: 4, maxRows: 10 }"
  44. type="textarea"
  45. v-model="ruleForm.result_desc"
  46. :disabled="isDetail"
  47. ></el-input>
  48. </el-form-item>
  49. </el-form>
  50. </el-col>
  51. <el-col :span="24" style="text-align: right">
  52. <el-button type="primary" @click="submitForm" v-if="!isDetail"
  53. >保 存
  54. </el-button>
  55. <el-button @click="showModelThis = false">{{
  56. isDetail ? "关 闭" : "取 消"
  57. }}</el-button>
  58. </el-col>
  59. </el-row>
  60. </el-card>
  61. </el-dialog>
  62. </template>
  63. <script>
  64. import asyncRequest from "@/apis/service/serviceParam/goodsAnomaly";
  65. import resToken from "@/mixins/resToken";
  66. export default {
  67. name: "goodsAnomaly",
  68. props: ["showModel", "id", "isDetail", "sitem"],
  69. mixins: [resToken],
  70. data() {
  71. return {
  72. loading: false,
  73. title: "",
  74. showModelThis: this.showModel,
  75. ruleForm: {
  76. result: "", //入库验收异常原因
  77. result_desc: "", //入库异常备注
  78. },
  79. rulesThis: this.rules,
  80. rules: {
  81. result: [
  82. {
  83. required: true,
  84. trigger: "blur",
  85. message: "退货验收异常原因不能为空",
  86. },
  87. ],
  88. result_desc: [
  89. {
  90. required: true,
  91. trigger: "blur",
  92. message: "备注不能为空",
  93. },
  94. ],
  95. },
  96. };
  97. },
  98. watch: {
  99. showModel: function (val) {
  100. this.showModelThis = val;
  101. if (val) {
  102. this.initForm();
  103. }
  104. },
  105. showModelThis(val) {
  106. if (!val) {
  107. this.$emit("cancel");
  108. }
  109. },
  110. },
  111. methods: {
  112. async initForm() {
  113. this.loading = true;
  114. if (this.id === "add") {
  115. this.title = "添加退货验收异常原因";
  116. this.rulesThis = this.rules;
  117. await this.resetForm();
  118. } else {
  119. if (this.isDetail) {
  120. this.title = "退货验收异常原因详情";
  121. this.rulesThis = {};
  122. } else {
  123. this.title = "修改退货验收异常原因";
  124. this.rulesThis = this.rules;
  125. }
  126. await this.resetForm();
  127. await this.initData();
  128. }
  129. this.loading = false;
  130. },
  131. // 获取详情列表
  132. async initData() {
  133. const res = await asyncRequest.detail({ id: this.id });
  134. if (res && res.code === 0 && res.data) {
  135. this.ruleForm = res.data;
  136. } else if (res && res.code >= 100 && res.code <= 104) {
  137. await this.logout();
  138. } else {
  139. this.$message.warning(res.message);
  140. }
  141. },
  142. async resetForm() {
  143. // 重置
  144. await this.$nextTick(() => {
  145. if (this.$refs.ruleForm) {
  146. this.$refs.ruleForm.resetFields();
  147. this.$refs.ruleForm.clearValidate();
  148. this.ruleForm = {
  149. result: "", //入库验收异常原因
  150. result_desc: "", //入库异常备注
  151. };
  152. }
  153. });
  154. },
  155. // 提交功能
  156. async submitForm() {
  157. await this.$refs.ruleForm.validate(async (valid) => {
  158. if (valid) {
  159. this.loading = true;
  160. const { result, result_desc } = JSON.parse(
  161. JSON.stringify(this.ruleForm)
  162. );
  163. const model = {
  164. result: result || "", //入库验收异常原因
  165. result_desc: result_desc || "", //入库异常备注
  166. type:"3",
  167. id: this.id,
  168. };
  169. let res = {};
  170. if (this.id === "add") {
  171. delete model["id"];
  172. res = await asyncRequest.add(model);
  173. } else {
  174. delete model["type"];
  175. res = await asyncRequest.update(model);
  176. }
  177. this.loading = false;
  178. if (res && res.code === 0) {
  179. const title = this.id === "add" ? "添加成功" : "修改成功";
  180. this.$notify.success({
  181. title,
  182. message: "",
  183. });
  184. this.showModelThis = false;
  185. // 刷新
  186. this.$emit("refresh");
  187. } else if (res && res.code >= 100 && res.code <= 104) {
  188. await this.logout();
  189. } else {
  190. this.$message.warning(res.message);
  191. }
  192. } else {
  193. console.log("error submit!!");
  194. return false;
  195. }
  196. });
  197. },
  198. },
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. .storeAnomaly {
  203. }
  204. </style>