addEdit.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div>
  3. <el-form
  4. :model="ruleForm"
  5. :rules="rulesThis"
  6. status-icon
  7. ref="ruleForm"
  8. label-width="80px"
  9. class="demo-ruleForm"
  10. >
  11. <el-row>
  12. <el-col :span="24">
  13. <el-form-item label="盘点公司" prop="wsm_supplier">
  14. <search-supplier
  15. :value="ruleForm.wsm_supplier"
  16. :placeholder="'请选择盘点公司'"
  17. @searchChange="supplierChange"
  18. />
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="24">
  22. <el-form-item label="盘点仓库" prop="wsm_code">
  23. <search-stock
  24. :value="ruleForm.wsm_code"
  25. :isDetail="true"
  26. :placeholder="'请选择盘点仓库'"
  27. :isRelation="true"
  28. :companyCode="companyCode"
  29. :names="''"
  30. @searchChange="stockChange"
  31. />
  32. </el-form-item>
  33. </el-col>
  34. <el-col :span="24">
  35. <el-form-item label="盘点类型" prop="type">
  36. <el-select
  37. v-model="ruleForm.type"
  38. placeholder="请选择盘点类型"
  39. style="width: 100%"
  40. >
  41. <el-option
  42. v-for="item in typeList"
  43. :key="item.value"
  44. :label="item.label"
  45. :value="item.value"
  46. >
  47. </el-option>
  48. </el-select>
  49. </el-form-item>
  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-col>
  56. </el-row>
  57. </el-form>
  58. <search-good-modal
  59. :show-model="showGoodsModel"
  60. @cancel="showGoodsModel = false"
  61. @resultList="addGoodsRes"
  62. />
  63. </div>
  64. </template>
  65. <script>
  66. import asyncRequest from "@/apis/service/stock/check";
  67. import resToken from "@/mixins/resToken";
  68. import columns from "./columns";
  69. export default {
  70. name: "addEdit",
  71. props: ["id"],
  72. mixins: [resToken],
  73. data() {
  74. return {
  75. companyCode: "",
  76. loading: false,
  77. showGoodsModel: false,
  78. typeList: [
  79. {
  80. value: "1",
  81. label: "全盘",
  82. },
  83. {
  84. value: "2",
  85. label: "抽盘",
  86. },
  87. ],
  88. columns: columns,
  89. ruleForm: {
  90. wsm_supplier: [], //供应商
  91. wsm_code: [], // 盘点仓库
  92. type: "2", // 盘点类型
  93. // good_type_code: [], //商品列表
  94. },
  95. rulesThis: this.rules,
  96. rules: {
  97. wsm_supplier: [
  98. {
  99. type: "array",
  100. required: true,
  101. message: "请选择盘点公司",
  102. trigger: "change",
  103. },
  104. ],
  105. wsm_code: [
  106. {
  107. type: "array",
  108. required: true,
  109. message: "请选择盘点仓库",
  110. trigger: "change",
  111. },
  112. ],
  113. type: [
  114. {
  115. required: true,
  116. message: "请选择盘点类型",
  117. trigger: "change",
  118. },
  119. ],
  120. },
  121. };
  122. },
  123. created() {
  124. this.initForm();
  125. },
  126. watch: {
  127. id: function (val) {
  128. console.log(val);
  129. if (val) {
  130. this.initForm();
  131. }
  132. },
  133. },
  134. methods: {
  135. closeModel() {
  136. console.log("closeModel!!");
  137. },
  138. //供应商选择
  139. supplierChange(e) {
  140. if (e && e.id) {
  141. this.ruleForm.wsm_supplier = [e.code];
  142. this.companyCode = e.code;
  143. } else {
  144. this.ruleForm.wsm_supplier = [];
  145. this.companyCode = "";
  146. }
  147. this.ruleForm.wsm_code = [];
  148. this.$refs.ruleForm.validateField("wsm_supplier");
  149. this.$refs.ruleForm.validateField("wsm_code");
  150. },
  151. //仓库选择
  152. stockChange(e) {
  153. if (e && e.id) {
  154. this.ruleForm.wsm_code = [e.code];
  155. } else {
  156. this.ruleForm.wsm_code = [];
  157. }
  158. this.$refs.ruleForm.validateField("wsm_code");
  159. },
  160. deleteById(index) {
  161. this.ruleForm.good_type_code.splice(index, 1);
  162. this.$refs.ruleForm.validateField("good_type_code");
  163. },
  164. async initForm() {
  165. this.loading = true;
  166. if (this.id === "add") {
  167. this.rulesThis = this.rules;
  168. await this.resetForm();
  169. } else {
  170. this.rulesThis = this.rules;
  171. await this.resetForm();
  172. await this.initData();
  173. }
  174. this.loading = false;
  175. },
  176. async initData() {
  177. const res = await asyncRequest.detail({ id: this.id });
  178. if (res && res.code === 0 && res.data) {
  179. this.ruleForm = res.data;
  180. this.ruleForm.role_id = this.ruleForm.role;
  181. } else if (res && res.code >= 100 && res.code <= 104) {
  182. await this.logout();
  183. } else {
  184. this.$message.warning(res.message);
  185. }
  186. },
  187. async resetForm() {
  188. // 重置
  189. await this.$nextTick(() => {
  190. if (this.$refs.ruleForm) {
  191. this.$refs.ruleForm.resetFields();
  192. this.$refs.ruleForm.clearValidate();
  193. this.ruleForm = {
  194. wsm_supplier: [], // 盘点公司
  195. wsm_code: [], // 盘点仓库
  196. type: "2", // 真实姓名
  197. };
  198. }
  199. });
  200. },
  201. getId(list) {
  202. let arr = JSON.parse(JSON.stringify(list));
  203. return arr.join(",");
  204. },
  205. async submitForm() {
  206. await this.$refs.ruleForm.validate(async (valid) => {
  207. if (valid) {
  208. this.loading = true;
  209. const { wsm_code, type, good_type_code } = JSON.parse(
  210. JSON.stringify(this.ruleForm)
  211. );
  212. const model = {
  213. id: this.id,
  214. wsm_code: this.getId(wsm_code) || "", // 盘点仓库
  215. type: type || "", // 盘点类型
  216. };
  217. let res = {};
  218. if (this.id === "add") {
  219. delete model["id"];
  220. res = await asyncRequest.add(model);
  221. } else {
  222. res = await asyncRequest.update(model);
  223. }
  224. this.loading = false;
  225. if (res && res.code === 0) {
  226. const title = this.id === "add" ? "添加成功" : "修改成功";
  227. this.$notify.success({
  228. title,
  229. message: "",
  230. });
  231. // 刷新
  232. this.$emit("refresh");
  233. } else if (res && res.code >= 100 && res.code <= 104) {
  234. await this.logout();
  235. } else {
  236. this.$message.warning(res.message);
  237. }
  238. } else {
  239. console.log("error submit!!");
  240. return false;
  241. }
  242. });
  243. },
  244. },
  245. };
  246. </script>
  247. <style lang="scss" scoped>
  248. .check {
  249. }
  250. </style>