addEdit.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. :disabled="status !== '0'"
  17. :isDetail="id !== 'add'"
  18. :placeholder="'请选择盘点公司'"
  19. :names="companyName"
  20. @searchChange="supplierChange"
  21. />
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="24">
  25. <el-form-item label="盘点仓库" prop="wsm_code">
  26. <search-stock
  27. :value="ruleForm.wsm_code"
  28. :isDetail="true"
  29. :disabled="status !== '0'"
  30. :placeholder="'请选择盘点仓库'"
  31. :isRelation="true"
  32. :companyCode="companyCode"
  33. :names="''"
  34. @searchChange="stockChange"
  35. />
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="24">
  39. <el-form-item label="盘点类型" prop="type">
  40. <el-select
  41. v-model="ruleForm.type"
  42. placeholder="请选择盘点类型"
  43. :disabled="status !== '0'"
  44. style="width: 100%"
  45. >
  46. <el-option
  47. v-for="item in typeList"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.value"
  51. >
  52. </el-option>
  53. </el-select>
  54. </el-form-item>
  55. </el-col>
  56. <el-col :span="24" style="text-align: right">
  57. <el-button
  58. @click="deleteById()"
  59. plain
  60. v-if="status !== '4'"
  61. type="danger"
  62. >作废盘点申请
  63. </el-button>
  64. <el-button
  65. type="primary"
  66. v-if="status === '1'"
  67. plain
  68. @click="submitForm"
  69. >取消流程
  70. </el-button>
  71. <el-button type="primary" @click="submitForm" v-if="status === '0'"
  72. >保 存
  73. </el-button>
  74. <el-button
  75. type="primary"
  76. @click="submitForm(true)"
  77. v-if="status === '0'"
  78. >保存并发起流程
  79. </el-button>
  80. </el-col>
  81. </el-row>
  82. </el-form>
  83. <search-good-modal
  84. :show-model="showGoodsModel"
  85. @cancel="showGoodsModel = false"
  86. @resultList="addGoodsRes"
  87. />
  88. </div>
  89. </template>
  90. <script>
  91. import asyncRequest from "@/apis/service/stock/check/detail";
  92. import resToken from "@/mixins/resToken";
  93. import columns from "./columns";
  94. export default {
  95. name: "addEdit",
  96. props: ["id"],
  97. mixins: [resToken],
  98. data() {
  99. return {
  100. status: "0",
  101. companyCode: "",
  102. companyName: "",
  103. loading: false,
  104. showGoodsModel: false,
  105. typeList: [
  106. {
  107. value: "1",
  108. label: "全盘",
  109. },
  110. {
  111. value: "2",
  112. label: "抽盘",
  113. },
  114. ],
  115. columns: columns,
  116. ruleForm: {
  117. wsm_supplier: [], //供应商
  118. wsm_code: [], // 盘点仓库
  119. type: "2", // 盘点类型
  120. // good_type_code: [], //商品列表
  121. },
  122. rulesThis: this.rules,
  123. rules: {
  124. wsm_supplier: [
  125. {
  126. type: "array",
  127. required: true,
  128. message: "请选择盘点公司",
  129. trigger: "change",
  130. },
  131. ],
  132. wsm_code: [
  133. {
  134. type: "array",
  135. required: true,
  136. message: "请选择盘点仓库",
  137. trigger: "change",
  138. },
  139. ],
  140. type: [
  141. {
  142. required: true,
  143. message: "请选择盘点类型",
  144. trigger: "change",
  145. },
  146. ],
  147. },
  148. };
  149. },
  150. created() {
  151. this.initForm();
  152. },
  153. watch: {
  154. id: function (val) {
  155. // console.log(val);
  156. if (val) {
  157. this.initForm();
  158. }
  159. },
  160. },
  161. methods: {
  162. closeModel() {
  163. console.log("closeModel!!");
  164. },
  165. //供应商选择
  166. supplierChange(e) {
  167. if (e && e.id) {
  168. this.ruleForm.wsm_supplier = [e.code];
  169. this.companyCode = e.code;
  170. } else {
  171. this.ruleForm.wsm_supplier = [];
  172. this.companyCode = "";
  173. }
  174. this.ruleForm.wsm_code = [];
  175. this.$refs.ruleForm.validateField("wsm_supplier");
  176. this.$refs.ruleForm.validateField("wsm_code");
  177. },
  178. //仓库选择
  179. stockChange(e) {
  180. if (e && e.id) {
  181. this.ruleForm.wsm_code = [e.code];
  182. } else {
  183. this.ruleForm.wsm_code = [];
  184. }
  185. this.$refs.ruleForm.validateField("wsm_code");
  186. },
  187. async deleteById() {
  188. await this.$confirm("确定要作废?", {
  189. confirmButtonText: "确定",
  190. cancelButtonText: "取消",
  191. type: "warning",
  192. })
  193. .then(async () => {
  194. const model = {
  195. id: this.id,
  196. };
  197. const res = await asyncRequest.delete(model);
  198. if (res && res.code === 0) {
  199. this.$notify.success({
  200. title: "作废成功!",
  201. message: "",
  202. });
  203. this.routeGoto("check", {});
  204. } else if (res && res.code >= 100 && res.code <= 104) {
  205. await this.logout();
  206. } else {
  207. this.$message.warning(res.message);
  208. }
  209. })
  210. .catch(() => {
  211. console.log("取消");
  212. });
  213. },
  214. async initForm() {
  215. this.loading = true;
  216. if (this.id === "add") {
  217. this.status = "0";
  218. this.rulesThis = this.rules;
  219. await this.resetForm();
  220. } else {
  221. this.rulesThis = this.rules;
  222. await this.resetForm();
  223. await this.initData();
  224. }
  225. this.loading = false;
  226. },
  227. async initData() {
  228. const res = await asyncRequest.detail({ id: this.id });
  229. if (res && res.code === 0 && res.data) {
  230. const { status, type, wsm_code } = res.data;
  231. this.status = status;
  232. this.companyCode = "GYS-20210517-0009";
  233. this.companyName = "北京长跃科技发展有限公司";
  234. this.ruleForm = {
  235. wsm_code: [wsm_code],
  236. type: type,
  237. wsm_supplier: [this.companyCode],
  238. };
  239. } else if (res && res.code >= 100 && res.code <= 104) {
  240. await this.logout();
  241. } else {
  242. this.$message.warning(res.message);
  243. }
  244. },
  245. async resetForm() {
  246. // 重置
  247. await this.$nextTick(() => {
  248. if (this.$refs.ruleForm) {
  249. this.$refs.ruleForm.resetFields();
  250. this.$refs.ruleForm.clearValidate();
  251. this.ruleForm = {
  252. wsm_supplier: [], // 盘点公司
  253. wsm_code: [], // 盘点仓库
  254. type: "2", // 真实姓名
  255. };
  256. }
  257. });
  258. },
  259. getId(list) {
  260. let arr = JSON.parse(JSON.stringify(list));
  261. return arr.join(",");
  262. },
  263. async submitForm(status) {
  264. await this.$refs.ruleForm.validate(async (valid) => {
  265. if (valid) {
  266. this.loading = true;
  267. const { wsm_code, type, good_type_code } = JSON.parse(
  268. JSON.stringify(this.ruleForm)
  269. );
  270. const model = {
  271. id: this.id,
  272. wsm_code: this.getId(wsm_code) || "", // 盘点仓库
  273. type: type || "", // 盘点类型
  274. };
  275. let res = {};
  276. if (this.id === "add") {
  277. delete model["id"];
  278. res = await asyncRequest.add(model);
  279. } else {
  280. res = await asyncRequest.update(model);
  281. }
  282. this.loading = false;
  283. if (res && res.code === 0) {
  284. const title = this.id === "add" ? "添加成功" : "修改成功";
  285. this.$notify.success({
  286. title,
  287. message: "",
  288. });
  289. // 刷新
  290. this.$emit("refresh");
  291. if (status) {
  292. await this.setProcess("1");
  293. }
  294. } else if (res && res.code >= 100 && res.code <= 104) {
  295. await this.logout();
  296. } else {
  297. this.$message.warning(res.message);
  298. }
  299. } else {
  300. console.log("error submit!!");
  301. return false;
  302. }
  303. });
  304. },
  305. async setProcess(status) {
  306. if (this.loading === false) {
  307. this.loading = true;
  308. }
  309. let model = {
  310. id: this.id,
  311. status: status,
  312. };
  313. let res = await asyncRequest.update(model);
  314. if (res && res.code === 0) {
  315. const title =
  316. status === "1" ? "发起审核流程成功!" : "取消审核流程成功!";
  317. this.$notify.success({
  318. title,
  319. message: "",
  320. });
  321. this.initForm();
  322. } else if (res && res.code >= 100 && res.code <= 104) {
  323. await this.logout();
  324. } else {
  325. this.$message.warning(res.message);
  326. }
  327. this.loading = false;
  328. },
  329. },
  330. };
  331. </script>
  332. <style lang="scss" scoped>
  333. .check {
  334. }
  335. </style>