addEdit.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div>
  3. <el-form
  4. :model="ruleForm"
  5. :rules="rulesThis"
  6. status-icon
  7. :size="'mini'"
  8. ref="ruleForm"
  9. label-width="80px"
  10. class="demo-ruleForm"
  11. >
  12. <el-row>
  13. <el-col :span="id === 'add' ? 24 : 12">
  14. <el-form-item label="业务公司" prop="companyNo">
  15. <search-work-company
  16. :value="ruleForm.companyNo"
  17. :size="'mini'"
  18. :is-detail="id !== 'add'"
  19. :placeholder="'业务公司'"
  20. @searchChange="companyNoChange($event, 'companyNo')"
  21. />
  22. </el-form-item>
  23. </el-col>
  24. <!-- <el-col :span="id === 'add' ? 24 : 12">
  25. <el-form-item label="盘点公司" prop="wsm_supplier">
  26. <search-supplier
  27. :value="ruleForm.wsm_supplier"
  28. :size="'mini'"
  29. :disabled="ruleForm.companyNo === ''"
  30. :is-detail="id !== 'add'"
  31. :placeholder="'盘点公司'"
  32. :names="companyName"
  33. @searchChange="supplierChange"
  34. />
  35. </el-form-item>
  36. </el-col> -->
  37. <el-col :span="id === 'add' ? 24 : 12">
  38. <el-form-item label="盘点仓库" prop="wsm_code">
  39. <search-stock
  40. :value="ruleForm.wsm_code"
  41. :size="'mini'"
  42. :disabled="
  43. !(
  44. id === 'add' ||
  45. (status + '' === '0' && powers.some((i) => i == '005'))
  46. )
  47. "
  48. :is-detail="id !== 'add'"
  49. :placeholder="'盘点仓库'"
  50. :isRelation="true"
  51. :companyCode="companyCode"
  52. :names="''"
  53. @searchChange="stockChange"
  54. />
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="id === 'add' ? 24 : 12">
  58. <el-form-item label="盘点类型" prop="type">
  59. <el-select
  60. v-model="ruleForm.type"
  61. placeholder="盘点类型"
  62. :disabled="
  63. !(
  64. id === 'add' ||
  65. (status + '' === '0' && powers.some((i) => i == '005'))
  66. )
  67. "
  68. style="width: 100%"
  69. >
  70. <el-option
  71. v-for="item in typeList"
  72. :key="item.value"
  73. :label="item.label"
  74. :value="item.value"
  75. >
  76. </el-option>
  77. </el-select>
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="24" style="text-align: right">
  81. <el-button
  82. type="primary"
  83. @click="submitForm"
  84. :size="'mini'"
  85. v-if="
  86. id === 'add' ||
  87. (status + '' === '0' && powers.some((i) => i == '005'))
  88. "
  89. >保 存
  90. </el-button>
  91. </el-col>
  92. </el-row>
  93. </el-form>
  94. </div>
  95. </template>
  96. <script>
  97. import asyncRequest from "@/apis/service/stock/check/detail";
  98. import resToken from "@/mixins/resToken";
  99. import { mapGetters } from "vuex";
  100. import columns from "./columns";
  101. export default {
  102. name: "addEdit",
  103. props: ["id", "sitem", "newTime"],
  104. computed: {
  105. ...mapGetters(["business_companyNo"]),
  106. },
  107. mixins: [resToken],
  108. computed: {
  109. powers() {
  110. const tran =
  111. this.$store.getters.btnList.find(
  112. (item) => item.menu_route == "checkDetail"
  113. ) || {};
  114. const { action } = tran ?? {};
  115. return action ?? [];
  116. },
  117. },
  118. data() {
  119. return {
  120. status: "",
  121. companyCode: "",
  122. companyName: "",
  123. loading: false,
  124. typeList: [
  125. {
  126. value: "2",
  127. label: "抽盘",
  128. },
  129. {
  130. value: "1",
  131. label: "全盘",
  132. },
  133. ],
  134. columns: columns,
  135. ruleForm: {
  136. companyNo: "",
  137. wsm_supplier: [], //供应商
  138. wsm_code: [], // 盘点仓库
  139. type: "2", // 盘点类型
  140. // good_type_code: [], //商品列表
  141. },
  142. rulesThis: this.rules,
  143. rules: {
  144. companyNo: [
  145. {
  146. required: true,
  147. message: "业务公司",
  148. trigger: "change",
  149. },
  150. ],
  151. wsm_supplier: [
  152. {
  153. type: "array",
  154. required: true,
  155. message: "盘点公司",
  156. trigger: "change",
  157. },
  158. ],
  159. wsm_code: [
  160. {
  161. type: "array",
  162. required: true,
  163. message: "盘点仓库",
  164. trigger: "change",
  165. },
  166. ],
  167. type: [
  168. {
  169. required: true,
  170. message: "盘点类型",
  171. trigger: "change",
  172. },
  173. ],
  174. },
  175. };
  176. },
  177. mounted() {
  178. this.initForm();
  179. },
  180. watch: {
  181. newTime: function (val) {
  182. if (val) {
  183. this.initForm();
  184. }
  185. },
  186. },
  187. methods: {
  188. //业务公司选择
  189. async companyNoChange(e, key) {
  190. const { code } = e;
  191. this.ruleForm[key] = code || ""; //业务公司编码
  192. console.log(this.ruleForm[key]);
  193. this.$refs.ruleForm.validateField(key);
  194. },
  195. //供应商选择
  196. supplierChange(e) {
  197. if (e && e.id) {
  198. this.ruleForm.wsm_supplier = [e.code];
  199. this.companyCode = e.code;
  200. } else {
  201. this.ruleForm.wsm_supplier = [];
  202. this.companyCode = "";
  203. }
  204. this.ruleForm.wsm_code = [];
  205. this.$refs.ruleForm.validateField("wsm_supplier");
  206. this.$refs.ruleForm.validateField("wsm_code");
  207. },
  208. //仓库选择
  209. stockChange(e) {
  210. if (e && e.id) {
  211. this.ruleForm.wsm_code = [e.code];
  212. } else {
  213. this.ruleForm.wsm_code = [];
  214. }
  215. this.$refs.ruleForm.validateField("wsm_code");
  216. },
  217. async initForm() {
  218. this.loading = true;
  219. if (this.id === "add") {
  220. this.status = "";
  221. }
  222. this.rulesThis = this.rules;
  223. await this.resetForm();
  224. this.loading = false;
  225. },
  226. async resetForm() {
  227. // 重置
  228. await this.$nextTick(() => {
  229. if (this.$refs.ruleForm) {
  230. this.$refs.ruleForm.resetFields();
  231. this.$refs.ruleForm.clearValidate();
  232. const { companyNo, status, type, wsm_code, code, name } = this.sitem;
  233. this.status = status || "";
  234. this.companyCode = code || "";
  235. this.companyName = name || "";
  236. this.ruleForm = {
  237. companyNo: companyNo || this.business_companyNo || "",
  238. wsm_code: wsm_code ? [wsm_code] : [],
  239. type: type || "2",
  240. wsm_supplier: this.companyCode ? [this.companyCode] : [],
  241. };
  242. }
  243. });
  244. },
  245. getId(list) {
  246. let arr = JSON.parse(JSON.stringify(list));
  247. return arr.join(",");
  248. },
  249. async submitForm() {
  250. await this.$refs.ruleForm.validate(async (valid) => {
  251. if (valid) {
  252. if (this.loading) {
  253. return;
  254. }
  255. this.loading = true;
  256. const { wsm_code, type, companyNo } = JSON.parse(
  257. JSON.stringify(this.ruleForm)
  258. );
  259. const model = {
  260. companyNo: companyNo,
  261. id: this.id,
  262. wsm_code: this.getId(wsm_code) || "", // 盘点仓库
  263. type: type || "", // 盘点类型
  264. };
  265. let res = {};
  266. if (this.id === "add") {
  267. delete model["id"];
  268. res = await asyncRequest.add(model);
  269. } else {
  270. res = await asyncRequest.update(model);
  271. }
  272. this.loading = false;
  273. if (res && res.code === 0) {
  274. const title = this.id === "add" ? "添加成功" : "修改成功";
  275. this.$notify.success({
  276. title,
  277. message: "",
  278. });
  279. this.showModelThis = false;
  280. this.$emit("refresh");
  281. } else if (res && res.code >= 100 && res.code <= 104) {
  282. await this.logout();
  283. } else {
  284. this.$message.warning(res.message);
  285. }
  286. } else {
  287. console.log("error submit!!");
  288. return false;
  289. }
  290. });
  291. },
  292. },
  293. };
  294. </script>
  295. <style lang="scss" scoped>
  296. .check {
  297. }
  298. </style>