DepositoryForm copy.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <a-form-model ref="form" :model="model" layout="horizontal" :rules="validatorRules" slot="detail">
  5. <a-row :gutter="2" align="top" type="flex">
  6. <a-col :span="5" flex>
  7. <a-form-item label="" prop="depositoryList">
  8. <a-select v-model="model.depositoryId" style="width: 100%" placeholder="入仓仓库" :allowClear="true">
  9. <a-select-option v-for="(item, index) in depositoryList" :key="index" :value="item.id">{{ item.name }}</a-select-option>
  10. </a-select>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :span="5">
  14. <a-form-item label="" prop="supplierList">
  15. <a-select v-model="model.supplierId" style="width: 100%" placeholder="供应商" :allowClear="true">
  16. <a-select-option v-for="(item, index) in supplierList" :key="index" :value="item.id">{{ item.name }}</a-select-option>
  17. </a-select>
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="5">
  21. <a-form-item label="" prop="storageTypeList">
  22. <a-select v-model="model.stockType" style="width: 100%" placeholder="入库类型" :allowClear="true">
  23. <a-select-option v-for="(item, index) in storageTypeList" :key="index" :value="item.value">{{ item.title }}</a-select-option>
  24. </a-select>
  25. </a-form-item>
  26. </a-col>
  27. <a-col :span="6" style="margin-top:5px;">
  28. <a-button :disabled="!model.supplierId" @click="handleGoods" type="primary" icon="plus">批量添加</a-button>
  29. </a-col>
  30. </a-row>
  31. </a-form-model>
  32. </j-form-container>
  33. <!-- 查询区域-END -->
  34. <div>
  35. <a-table :scroll="{ y: 540 }" ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="false" :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">
  36. <span slot="state" slot-scope="record">
  37. {{ record ? "启用" : "停用" }}
  38. <!-- {{record}} -->
  39. </span>
  40. <template slot="price" slot-scope="record">
  41. <a-input-number :min="0" :placeholder="record.costPrice" v-model="record.costPrice"></a-input-number>
  42. </template>
  43. <template slot="num" slot-scope="record">
  44. <a-input-number :min="0" v-model="record.num"></a-input-number>
  45. </template>
  46. <span slot="action" slot-scope="text, record">
  47. <!-- <a @click="handleEdit(record)">修改</a>
  48. <a-divider type="vertical" />
  49. <a @click="moreSet(record)">更多设置</a>
  50. <a-divider type="vertical" /> -->
  51. <a-popconfirm title="确定删除吗?" @confirm="() => deleteGoods(record.id)">
  52. <a>删除</a>
  53. </a-popconfirm>
  54. </span>
  55. </a-table>
  56. </div>
  57. <a-row>
  58. <a-col :span="12">
  59. <a-form-item label="备注" :label-col="labelCol">
  60. <a-textarea v-model="model.remarks" :rows="4" />
  61. </a-form-item>
  62. </a-col>
  63. </a-row>
  64. <supplier-in-goods-modal ref="modalSelectGoodsForm" @ok="selectOk"></supplier-in-goods-modal>
  65. </a-spin>
  66. </template>
  67. <script>
  68. import {
  69. httpAction,
  70. getAction
  71. } from "@/api/manage";
  72. import {
  73. validateDuplicateValue
  74. } from "@/utils/util";
  75. import {
  76. JeecgListMixin
  77. } from "@/mixins/JeecgListMixin";
  78. import SupplierInGoodsModal from "./DepositorySelectGoods/selectGoodsModal.vue";
  79. export default {
  80. name: "PosTypeForm",
  81. mixins: [JeecgListMixin],
  82. components: {
  83. SupplierInGoodsModal,
  84. },
  85. props: {
  86. //表单禁用
  87. disabled: {
  88. type: Boolean,
  89. default: false,
  90. required: false,
  91. },
  92. },
  93. watch:{
  94. "model.supplierId":function(newVal, oldVal){
  95. if (newVal!=oldVal) {
  96. this.dataSource = [];
  97. }
  98. }
  99. },
  100. data() {
  101. return {
  102. model: {
  103. code: "",
  104. createAt: "",
  105. createTime: "",
  106. // depositoryId: "",
  107. hotelId: "",
  108. id: "",
  109. remarks: "",
  110. status: 0,
  111. num: 0,
  112. // stockInfo: "",
  113. // stockType: 0,
  114. // supplierId: "",
  115. tenantId: "",
  116. type: 2,
  117. verifyAt: "",
  118. verifyRemarks: "",
  119. verifyTime: ""
  120. },
  121. labelCol: {
  122. xs: {
  123. span: 24,
  124. },
  125. sm: {
  126. span: 5,
  127. },
  128. },
  129. wrapperCol: {
  130. xs: {
  131. span: 24,
  132. },
  133. sm: {
  134. span: 16,
  135. },
  136. },
  137. confirmLoading: false,
  138. validatorRules: {
  139. depositoryList: [{
  140. required: true,
  141. message: "请选择入库仓库!",
  142. }, ],
  143. supplierList: [{
  144. required: true,
  145. message: "请选择供应商!",
  146. }, ],
  147. storageTypeList: [{
  148. required: true,
  149. message: "请选择入库类型!",
  150. }, ],
  151. },
  152. // 表头
  153. columns: [{
  154. title: "商品名称",
  155. align: "center",
  156. dataIndex: "name",
  157. },
  158. {
  159. title: "单位",
  160. align: "center",
  161. dataIndex: "goodUnit",
  162. },
  163. {
  164. title: "商品规格",
  165. align: "center",
  166. dataIndex: "spec",
  167. },
  168. {
  169. title: "成本价",
  170. align: "center",
  171. // dataIndex: "costPrice",
  172. scopedSlots: {
  173. customRender: "price"
  174. },
  175. },
  176. {
  177. title: "出入库数量",
  178. align: "center",
  179. // dataIndex: "spec",
  180. scopedSlots: {
  181. customRender: "num"
  182. },
  183. },
  184. {
  185. title: '操作',
  186. dataIndex: 'action',
  187. key: 'action',
  188. scopedSlots: {
  189. customRender: "action"
  190. },
  191. align: 'center',
  192. fixed: "right",
  193. width: 200,
  194. }
  195. ],
  196. url: {
  197. list: 2,
  198. add: "/kc/kcStock/add",
  199. edit: "/kc/kcStock/edit",
  200. queryById: "/kc/kcDepository/queryById",
  201. },
  202. depositoryList: [],
  203. supplierList: [],
  204. storageTypeList: [],
  205. dataSource: []
  206. };
  207. },
  208. computed: {
  209. formDisabled() {
  210. return this.disabled;
  211. },
  212. },
  213. created() {
  214. var _info = JSON.parse(localStorage.getItem("storeInfo"));
  215. if (_info) {
  216. this.model.hotelId = _info.id;
  217. }
  218. //备份model原始值
  219. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  220. getAction("/kc/kcDepository/list", {
  221. state: 1,
  222. }).then((res) => {
  223. if (res.success) {
  224. this.depositoryList = res.result.records;
  225. }
  226. });
  227. getAction("/kc/kcSupplier/list", {
  228. state: 1,
  229. }).then((res) => {
  230. if (res.success) {
  231. this.supplierList = res.result.records;
  232. }
  233. });
  234. getAction("/kc/kcStock/storageTypeList", {}).then((res) => {
  235. if (res.success) {
  236. this.storageTypeList = res.result;
  237. }
  238. });
  239. },
  240. methods: {
  241. handleGoods(row) {
  242. this.$refs.modalSelectGoodsForm.add();
  243. this.$refs.modalSelectGoodsForm.title = "供货商品";
  244. this.$refs.modalSelectGoodsForm.disableSubmit = false;
  245. this.$refs.modalSelectGoodsForm.supplierId = this.model.supplierId;
  246. },
  247. /**
  248. * 删除商品
  249. */
  250. deleteGoods(id) {
  251. this.dataSource = this.dataSource.filter(item => item.id !== id)
  252. },
  253. selectOk(e) {
  254. console.log(e);
  255. this.dataSource = JSON.parse(JSON.stringify(e))
  256. console.log(this.dataSource);
  257. },
  258. add() {
  259. this.edit(this.modelDefault,1);
  260. },
  261. edit(record, type) {
  262. if (type) {
  263. return
  264. }
  265. this.model = Object.assign({}, record);
  266. this.model.stockType = this.model.stockType.toString()
  267. console.log(this.model);
  268. getAction(`/kc/kcStockDetail/list?stockId=${this.model.code}`).then(res=>{
  269. console.log(res);
  270. if ( res.code==200 ) {
  271. this.dataSource = res.result.records
  272. this.dataSource.forEach(ele=>{
  273. ele.costPrice = ele.price
  274. })
  275. }
  276. })
  277. this.visible = true;
  278. },
  279. submitForm() {
  280. const that = this;
  281. // 触发表单验证
  282. this.$refs.form.validate((valid) => {
  283. if (valid) {
  284. that.confirmLoading = true;
  285. let httpurl = "";
  286. let method = "";
  287. if (!this.model.id) {
  288. httpurl += this.url.add;
  289. method = "post";
  290. } else {
  291. httpurl += this.url.edit;
  292. method = "put";
  293. }
  294. this.model.stockDetailList = this.dataSource
  295. this.model.stockDetailList.forEach(element => {
  296. element.supplierInGoodsId = element.supplierInGoodsId;
  297. element.price = element.costPrice;
  298. element.num = Number(element.num);
  299. });
  300. httpAction(httpurl, this.model, method)
  301. .then((res) => {
  302. if (res.success) {
  303. that.$message.success(res.message);
  304. that.$emit("ok");
  305. } else {
  306. that.$message.warning(res.message);
  307. }
  308. })
  309. .finally(() => {
  310. that.confirmLoading = false;
  311. });
  312. }
  313. });
  314. },
  315. },
  316. };
  317. </script>