addEdit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <div>
  3. <el-form
  4. :model="ruleForm"
  5. :rules="rulesThis"
  6. status-icon
  7. ref="ruleForm"
  8. label-width="120px"
  9. class="demo-ruleForm"
  10. >
  11. <el-row>
  12. <!-- 商品名称 -->
  13. <el-col :span="24">
  14. <el-form-item label="商品名称" prop="goods_name">
  15. <el-input
  16. :disabled="ruleForm.status !== '0' && id != 'add'"
  17. v-model="ruleForm.goods_name"
  18. readonly="true"
  19. @focus="hand"
  20. ></el-input>
  21. <!-- <search-good-modal /> -->
  22. </el-form-item>
  23. </el-col>
  24. <!-- 采购数量 -->
  25. <el-col :span="24">
  26. <el-form-item label="采购数量" prop="goods_num">
  27. <el-input
  28. :disabled="ruleForm.status != '0' && id != 'add'"
  29. v-model="ruleForm.goods_num"
  30. placeholder="请输入内容"
  31. :size="searchSize"
  32. ></el-input>
  33. </el-form-item>
  34. </el-col>
  35. <!-- 最晚入库时间 -->
  36. <el-col :span="24">
  37. <el-form-item label="最晚入库时间" prop="last_go_stock">
  38. <el-date-picker
  39. :size="searchSize"
  40. v-model="ruleForm.last_go_stock"
  41. type="date"
  42. style="width: 100%"
  43. value-format="yyyy-MM-dd HH:mm:ss"
  44. placeholder="选择日期"
  45. :picker-options="pickerOptions"
  46. @change="selectTime"
  47. :disabled="ruleForm.status !== '0' && id != 'add'"
  48. >
  49. </el-date-picker>
  50. </el-form-item>
  51. </el-col>
  52. <!-- 供应商选择 -->
  53. <el-col :span="24">
  54. <el-form-item label="供应商名称" prop="supplier_code">
  55. <search-supplier
  56. :disabled="ruleForm.status !== '0' && id != 'add'"
  57. :value="ruleForm.supplier_code"
  58. :placeholder="'请选择供应商'"
  59. @searchChange="selectSupplier"
  60. />
  61. </el-form-item>
  62. </el-col>
  63. <!-- 仓库名称 -->
  64. <el-col :span="24">
  65. <el-form-item label="仓库名称" prop="stock_code">
  66. <search-stock
  67. :disabled="ruleForm.status !== '0' && id != 'add'"
  68. :value="ruleForm.stock_code"
  69. :isDetail="true"
  70. :placeholder="'请选择备库仓库'"
  71. :isRelation="true"
  72. :companyCode="companyCode"
  73. @searchChange="selectStock"
  74. />
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="24" style="text-align: right">
  78. <el-button
  79. type="primary"
  80. @click="submitForm"
  81. v-if="id == 'add' || ruleForm.status == '0'"
  82. >保 存</el-button
  83. >
  84. <el-button
  85. type="primary"
  86. @click="statusConfirm('1', '发起审核流程')"
  87. v-if="
  88. id != 'add' && ruleForm.status != '1' && ruleForm.status != '2'
  89. "
  90. >发起备货申请
  91. </el-button>
  92. <el-button
  93. @click="statusConfirm('0', '取消审核流程')"
  94. plain
  95. v-if="ruleForm.status == '1' && id !== ''"
  96. >取消备货申请</el-button
  97. >
  98. <el-button
  99. v-if="id != 'add' && ruleForm.status != '2'"
  100. @click="statusConfirm('-1', '作废该条信息')"
  101. type="danger"
  102. plain
  103. >作废该条信息</el-button
  104. >
  105. <el-button
  106. @click="statusConfirm('2', '通过审核')"
  107. type="primary"
  108. v-if="ruleForm.status === '1'"
  109. >反馈备货信息</el-button
  110. >
  111. </el-col>
  112. </el-row>
  113. </el-form>
  114. <search-stock-good-modal
  115. :once="true"
  116. :show-model="showGoodsModel"
  117. @cancel="showGoodsModel = false"
  118. @searchChange="addGoodsRes"
  119. />
  120. </div>
  121. </template>
  122. <script>
  123. import resToken from "@/mixins/resToken";
  124. import asyncRequest from "@/apis/service/purchaseIn/storeManage";
  125. export default {
  126. name: "storeManage",
  127. props: ["id", "isDetail", "sitem"],
  128. mixins: [resToken],
  129. data() {
  130. return {
  131. pickerOptions: {
  132. disabledDate(time) {
  133. return time.getTime() < Date.now();
  134. },
  135. },
  136. // id: "",
  137. routerId: "",
  138. stockCode: "",
  139. companyCode: "",
  140. showGoodsModel: "", //打开新弹窗
  141. loading: false,
  142. title: "新建备货申请",
  143. ruleForm: {
  144. id: "", //保存路由来的id
  145. good_code: "",
  146. good_type_code: "",
  147. goods_name: "", //商品名称
  148. goods_num: "", //商品数量
  149. last_go_stock: "", //最晚入库时间
  150. supplier_code: [], //供应商名称
  151. stock_code: [],
  152. status: "", //当前状态
  153. },
  154. rulesThis: this.rules,
  155. rules: {
  156. //出入库规则
  157. goods_name: [
  158. {
  159. required: true,
  160. message: "商品名称不能为空",
  161. trigger: "blur",
  162. },
  163. ],
  164. goods_num: [
  165. {
  166. required: true,
  167. message: "请选择入库仓库",
  168. trigger: "blur",
  169. },
  170. ],
  171. last_go_stock: [
  172. {
  173. // type: "date",
  174. required: true,
  175. message: "请输入入库最晚时间",
  176. // trigger: "blur" ,
  177. trigger: ["blur", "change"],
  178. },
  179. ],
  180. supplier_code: [
  181. {
  182. type: "array",
  183. required: true,
  184. message: "请选择供应商",
  185. trigger: "change",
  186. },
  187. ],
  188. stock_code: [
  189. {
  190. type: "array",
  191. required: true,
  192. message: "请选择仓库",
  193. trigger: "change",
  194. },
  195. ],
  196. },
  197. };
  198. },
  199. mounted() {
  200. this.routerId = this.$route.query.id;
  201. this.searchList();
  202. this.initForm();
  203. },
  204. methods: {
  205. async initForm() {
  206. this.loading = true;
  207. // await this.getRole();
  208. if (this.id === "add") {
  209. this.rulesThis = this.rules;
  210. await this.resetForm();
  211. } else {
  212. if (this.isDetail) {
  213. this.rulesThis = {};
  214. } else {
  215. this.rulesThis = this.rules;
  216. }
  217. console.log(this.id);
  218. await this.resetForm();
  219. // await this.initData();
  220. }
  221. this.loading = false;
  222. },
  223. // 获取备库详情
  224. async searchList() {
  225. this.loading = true;
  226. const res = await asyncRequest.detail({ id: this.routerId });
  227. if (res && res.code === 0 && res.data) {
  228. let {
  229. good_code,
  230. good_name, //商品名
  231. good_num, //采购数量
  232. good_type_code, //商品属性code
  233. wsm_code, //仓库code
  234. lasttime, //最晚入库时间
  235. wsm_name, //仓库名
  236. status,
  237. } = res.data;
  238. this.ruleForm = {
  239. good_code,
  240. id: this.routerId,
  241. goods_name: good_name, //商品名
  242. goods_num: good_num, //采购数量
  243. last_go_stock: lasttime, //最晚入库时间
  244. good_type_code, //商品属性code
  245. wsm_code, //仓库code
  246. supplier_code: ["缺供应商"],
  247. stock_code: wsm_name.split(","), //仓库名
  248. status,
  249. // 缺少供应商名称和供应商code
  250. };
  251. } else if (res && res.code >= 100 && res.code <= 104) {
  252. await this.logout();
  253. } else {
  254. this.tableData = [];
  255. }
  256. this.loading = false;
  257. },
  258. // 选择仓库
  259. selectStock(e) {
  260. if (e && e.id) {
  261. this.ruleForm.stock_code = [e.code];
  262. this.stockCode = e.code;
  263. } else {
  264. this.ruleForm.stock_code = [];
  265. this.stockCode = "";
  266. }
  267. this.$refs.ruleForm.validateField("stock_code");
  268. },
  269. // 选择供应商
  270. selectSupplier(e) {
  271. if (e && e.id) {
  272. this.ruleForm.supplier_code = [e.code];
  273. this.companyCode = e.code;
  274. } else {
  275. this.ruleForm.supplier_code = [];
  276. this.companyCode = "";
  277. this.ruleForm.stock_code = [];
  278. this.stockCode = "";
  279. }
  280. this.$refs.ruleForm.validateField("supplier_code");
  281. },
  282. // 执行点击商品名称的抛出事件
  283. addGoodsRes(e) {
  284. let { good_code, type_code, good_name } = e[0];
  285. this.ruleForm.goods_name = good_name;
  286. this.ruleForm.good_type_code = type_code;
  287. this.ruleForm.good_code = good_code;
  288. this.$refs.ruleForm.validateField("goods_name");
  289. },
  290. hand() {
  291. this.showGoodsModel = true;
  292. },
  293. // 最晚入库时间选择
  294. selectTime(e) {
  295. this.ruleForm.last_go_stock = e;
  296. },
  297. closeModel() {
  298. console.log("closeModel!!");
  299. this.$emit("closeModel");
  300. },
  301. // 重置
  302. async resetForm() {
  303. // 重置
  304. await this.$nextTick(() => {
  305. if (this.$refs.ruleForm) {
  306. this.$refs.ruleForm.resetFields();
  307. this.$refs.ruleForm.clearValidate();
  308. this.ruleForm = {
  309. stock_code: [],
  310. supplier_code: [],
  311. good_code: "",
  312. good_type_code: "",
  313. goods_name: "", //商品名称
  314. goods_num: "", //商品数量
  315. last_go_stock: "", //最晚入库时间
  316. stock_in_rule: "", //入库仓库
  317. };
  318. }
  319. });
  320. },
  321. // 保存更改
  322. async submitForm() {
  323. await this.$refs.ruleForm.validate(async (valid) => {
  324. if (valid) {
  325. this.loading = true;
  326. const {
  327. id, //申请单ID
  328. stock_code, //仓库编码
  329. good_code, //商品code
  330. good_type_code, //商品属性code
  331. last_go_stock, //最晚入库时间
  332. goods_num, //入库数量
  333. } = this.ruleForm;
  334. const model = {
  335. id,
  336. good_code: good_code || "",
  337. good_type_code: good_type_code || "",
  338. good_num: goods_num || "",
  339. wsm_code: stock_code.toString() || "",
  340. lastime: last_go_stock || "",
  341. };
  342. let res = {};
  343. if (this.id === "add") {
  344. delete model["id"];
  345. res = await asyncRequest.add(model);
  346. } else {
  347. res = await asyncRequest.update(model);
  348. }
  349. this.loading = false;
  350. if (res && res.code === 0) {
  351. const title = this.id === "add" ? "添加成功" : "修改成功";
  352. this.$notify.success({
  353. title,
  354. message: "",
  355. });
  356. this.$emit("closeModel");
  357. this.routeGoto("storeManage", {});
  358. } else if (res && res.code >= 100 && res.code <= 104) {
  359. await this.logout();
  360. } else {
  361. this.$message.warning(res.message);
  362. }
  363. } else {
  364. console.log("error submit!!");
  365. return false;
  366. }
  367. });
  368. },
  369. // 发起申请
  370. async statusConfirm(status, message) {
  371. await this.$confirm(`确定要${message}?`, {
  372. confirmButtonText: "确定",
  373. cancelButtonText: "取消",
  374. type: "warning",
  375. })
  376. .then(async () => {
  377. if (status === "-1") {
  378. await this.deleteById(message);
  379. } else {
  380. await this.setStatus(status, message);
  381. }
  382. })
  383. .catch(() => {
  384. console.log("取消");
  385. });
  386. },
  387. // 作废该条信息
  388. async deleteById(message) {
  389. const res = await asyncRequest.delete({ id: this.routerId });
  390. if (res && res.code === 0) {
  391. this.$notify.success({
  392. title: message + "成功!",
  393. message: "",
  394. });
  395. this.routeGoto("storeManage", {});
  396. this.searchList();
  397. } else if (res && res.code >= 100 && res.code <= 104) {
  398. await this.logout();
  399. } else {
  400. this.$message.warning(res.message);
  401. }
  402. },
  403. // 状态修改
  404. async setStatus(status, message) {
  405. let model = {
  406. id: this.routerId,
  407. remark: "",
  408. status: status,
  409. };
  410. const res = await asyncRequest.status(model);
  411. this.loading = false;
  412. if (res && res.code === 0) {
  413. this.$notify.success({
  414. title: message + "成功!",
  415. message: "",
  416. });
  417. this.searchList();
  418. } else if (res && res.code >= 100 && res.code <= 104) {
  419. await this.logout();
  420. } else {
  421. this.$message.warning(res.message);
  422. }
  423. },
  424. },
  425. };
  426. </script>