productModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <a-modal
  3. centered
  4. class="bulkWarehousingOrder-product-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="(itemSn ? '编辑' : '新增') + '产品'"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="800">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="bulkWarehousingOrder-product-form"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol" >
  19. <a-form-model-item label="供应商" prop="supplierSn">{{ (nowData&&nowData.supplierName) || '--' }}</a-form-model-item>
  20. <a-form-model-item label="产品编码" prop="productSn">
  21. <a-select
  22. show-search
  23. id="bulkWarehousingOrder-product-productSn"
  24. v-model="form.productSn"
  25. placeholder="请选择"
  26. :filter-option="false"
  27. :not-found-content="fetching ? undefined : null"
  28. @search="fetchUser"
  29. @change="handleChange"
  30. >
  31. <a-spin v-if="fetching" slot="notFoundContent" size="small" />
  32. <a-select-option v-for="item in productData" :key="item.product.productSn + item.product.code" :value="item.product.productSn">{{ item.product.code }}</a-select-option>
  33. </a-select>
  34. </a-form-model-item>
  35. <a-form-model-item label="产品名称" prop="productName">{{ form.productName || '--' }}</a-form-model-item>
  36. <a-form-model-item label="原厂编码" prop="productOrigCode">{{ form.productOrigCode || '--' }}</a-form-model-item>
  37. <a-form-model-item label="仓库仓位" prop="warehouse">
  38. <a-cascader
  39. @change="changeWarehouseCascade"
  40. v-model="form.warehouse"
  41. expand-trigger="hover"
  42. :allowClear="false"
  43. :options="warehouseCascadeData"
  44. :fieldNames="{ label: 'name', value: 'sn', children: 'warehouseLocationList' }"
  45. id="bulkWarehousingOrder-product-warehouse"
  46. placeholder="请选择仓库仓位"
  47. style="width: 100%;" />
  48. </a-form-model-item>
  49. <a-form-model-item label="成本价" prop="productCost">
  50. <a-input-number
  51. id="bulkWarehousingOrder-product-productCost"
  52. v-model="form.productCost"
  53. :precision="2"
  54. :min="0"
  55. :max="999999"
  56. placeholder="请输入"
  57. style="width: 100%;" />
  58. </a-form-model-item>
  59. <a-form-model-item label="数量" prop="productQty">
  60. <a-input-number
  61. id="bulkWarehousingOrder-product-productQty"
  62. v-model="form.productQty"
  63. :precision="0"
  64. :min="1"
  65. :max="999999"
  66. placeholder="请输入"
  67. style="width: 80%;" /><span>个</span>
  68. </a-form-model-item>
  69. </a-form-model>
  70. <div class="btn-cont">
  71. <a-button type="primary" id="bulkWarehousingOrder-product-modal-save" @click="handleSave">保存并新增</a-button>
  72. <a-button id="bulkWarehousingOrder-product-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
  73. </div>
  74. </a-spin>
  75. </a-modal>
  76. </template>
  77. <script>
  78. import { VSelect } from '@/components'
  79. import debounce from 'lodash/debounce'
  80. import { supplierProductList } from '@/api/supplier'
  81. import { warehouseCascadeList } from '@/api/warehouse'
  82. import { sparePartsSaveDetail, sparePartsDetailD } from '@/api/spareParts'
  83. export default {
  84. name: 'BulkWarehousingOrderBasicInfoModal',
  85. components: { VSelect },
  86. props: {
  87. openModal: { // 弹框显示状态
  88. type: Boolean,
  89. default: false
  90. },
  91. itemSn: {
  92. type: [Number, String],
  93. default: ''
  94. },
  95. nowData: {
  96. type: Object,
  97. default: () => {
  98. return null
  99. }
  100. }
  101. },
  102. data () {
  103. this.fetchUser = debounce(this.fetchUser, 800)
  104. return {
  105. isShow: this.openModal, // 是否打开弹框
  106. spinning: false,
  107. formItemLayout: {
  108. labelCol: { span: 5 },
  109. wrapperCol: { span: 16 }
  110. },
  111. form: {
  112. supplierSn: '', // 供应商
  113. productSn: undefined,
  114. productName: '',
  115. productCode: '',
  116. productOrigCode: '',
  117. warehouse: [],
  118. warehouseSn: '',
  119. warehouseLocationSn: '',
  120. productCost: '',
  121. productQty: ''
  122. },
  123. rules: {
  124. productSn: [
  125. { required: true, message: '请选择产品编码', trigger: 'change' }
  126. ],
  127. warehouse: [
  128. { required: true, message: '请选择仓库仓位', trigger: 'change' }
  129. ],
  130. productCost: [
  131. { required: true, message: '请输入成本价', trigger: 'blur' }
  132. ],
  133. productQty: [
  134. { required: true, message: '请输入数量', trigger: 'blur' }
  135. ]
  136. },
  137. fetching: false,
  138. productData: [],
  139. warehouseCascadeData: [], // 仓库仓位 下拉数据
  140. warehouseSnBackups: '', // 仓库备份数据
  141. warehouseLocationSnBackups: '', // 仓位备份数据
  142. defaultWarehouseCascade: [] // 默认仓库仓位
  143. }
  144. },
  145. methods: {
  146. // 搜索产品
  147. fetchUser (value) {
  148. console.log('fetching user', value)
  149. this.fetching = true
  150. const params = {
  151. product: {
  152. code: value
  153. },
  154. supplierSn: this.nowData.supplierSn,
  155. pageNo: 1,
  156. pageSize: 20
  157. }
  158. supplierProductList(params).then(res => {
  159. if (res.status == 200) {
  160. this.productData = res.data && res.data.list ? res.data.list : []
  161. this.fetching = false
  162. } else {
  163. this.productData = []
  164. this.fetching = false
  165. }
  166. })
  167. },
  168. // 产品编码 change
  169. handleChange (value) {
  170. const ind = this.productData.findIndex(item => item.productSn == value)
  171. this.form.productName = this.productData[ind].product.name
  172. this.form.productCode = this.productData[ind].product.code
  173. this.form.productOrigCode = this.productData[ind].product.origCode
  174. this.form.productCost = (this.productData[ind].cost && this.productData[ind].cost != 0) ? this.productData[ind].cost : ''
  175. },
  176. // 详情
  177. getDetail () {
  178. sparePartsDetailD({ sn: this.itemSn }).then(res => {
  179. if (res.status == 200) {
  180. const data = res.data
  181. this.form = Object.assign(this.form, data)
  182. this.fetchUser(this.form.productCode)
  183. this.form.warehouse = [this.form.warehouseSn, this.form.warehouseLocationSn]
  184. this.warehouseSnBackups = this.form.warehouseSn || undefined
  185. this.warehouseLocationSnBackups = this.form.warehouseLocationSn || undefined
  186. }
  187. })
  188. },
  189. // 保存
  190. handleSave () {
  191. const _this = this
  192. this.$refs.ruleForm.validate(valid => {
  193. if (valid) {
  194. const form = JSON.parse(JSON.stringify(_this.form))
  195. form.sparePartsSn = this.nowData.sparePartsSn
  196. form.sparePartsNo = this.nowData.sparePartsNo
  197. form.supplierSn = this.nowData.supplierSn
  198. if (!_this.itemSn) {
  199. delete form.id
  200. delete form.sparePartsDetailSn
  201. }
  202. _this.spinning = true
  203. sparePartsSaveDetail(form).then(res => {
  204. if (res.status == 200) {
  205. _this.$message.success(res.message)
  206. setTimeout(() => {
  207. _this.$emit('ok', res.data)
  208. _this.spinning = false
  209. _this.resetData()
  210. }, 1000)
  211. } else {
  212. _this.spinning = false
  213. }
  214. })
  215. } else {
  216. console.log('error submit!!')
  217. return false
  218. }
  219. })
  220. },
  221. changeWarehouseCascade (val) {
  222. if (val.length < 2) {
  223. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  224. this.form.warehouseSn = this.warehouseSnBackups
  225. this.form.warehouseLocationSn = this.warehouseLocationSnBackups
  226. if (this.warehouseSnBackups || this.warehouseLocationSnBackups) {
  227. this.form.warehouse = [this.warehouseSnBackups, this.warehouseLocationSnBackups]
  228. } else {
  229. this.form.warehouse = []
  230. }
  231. } else {
  232. this.form.warehouseSn = val[0] ? val[0] : ''
  233. this.form.warehouseLocationSn = val[1] ? val[1] : ''
  234. this.warehouseSnBackups = this.form.warehouseSn
  235. this.warehouseLocationSnBackups = this.form.warehouseLocationSn
  236. }
  237. },
  238. // 仓库仓位 级联 列表
  239. getWarehouseCascade () {
  240. const _this = this
  241. warehouseCascadeList({}).then(res => {
  242. if (res.status == 200) {
  243. res.data.filter(item => {
  244. // 过滤默认仓库
  245. if (item.defaultFlag == 1) { // defaultFlag为1是默认仓库
  246. _this.defaultWarehouseCascade[0] = item.warehouseSn
  247. // 过滤默认仓位
  248. item.warehouseLocationList.filter(subItem => {
  249. if (subItem.defaultFlag == 1) {
  250. _this.defaultWarehouseCascade[1] = subItem.warehouseLocationSn
  251. _this.form.warehouse = _this.defaultWarehouseCascade
  252. _this.form.warehouseSn = _this.defaultWarehouseCascade[0] || undefined
  253. _this.form.warehouseLocationSn = _this.defaultWarehouseCascade[1] || undefined
  254. _this.warehouseSnBackups = _this.defaultWarehouseCascade[0] || undefined
  255. _this.warehouseLocationSnBackups = _this.defaultWarehouseCascade[1] || undefined
  256. }
  257. })
  258. }
  259. })
  260. res.data.map(item => {
  261. item.sn = item.warehouseSn
  262. if (item.warehouseLocationList) {
  263. item.warehouseLocationList.map(subItem => {
  264. subItem.sn = subItem.warehouseLocationSn
  265. })
  266. }
  267. })
  268. this.warehouseCascadeData = res.data
  269. } else {
  270. this.warehouseCascadeData = []
  271. }
  272. })
  273. },
  274. resetData () {
  275. this.form = {
  276. supplierSn: '', // 供应商
  277. productSn: undefined,
  278. productName: '',
  279. productCode: '',
  280. productOrigCode: '',
  281. warehouse: [],
  282. warehouseSn: '',
  283. warehouseLocationSn: '',
  284. productCost: '',
  285. productQty: ''
  286. }
  287. }
  288. },
  289. watch: {
  290. // 父页面传过来的弹框状态
  291. openModal (newValue, oldValue) {
  292. this.isShow = newValue
  293. },
  294. // 重定义的弹框状态
  295. isShow (newValue, oldValue) {
  296. if (!newValue) {
  297. this.$emit('close')
  298. this.$refs.ruleForm.resetFields()
  299. this.resetData()
  300. this.warehouseSnBackups = ''
  301. this.warehouseLocationSnBackups = ''
  302. } else {
  303. this.getWarehouseCascade()
  304. }
  305. },
  306. itemSn (newValue, oldValue) {
  307. if (this.isShow && newValue) {
  308. this.getDetail()
  309. }
  310. }
  311. }
  312. }
  313. </script>
  314. <style lang="less">
  315. .bulkWarehousingOrder-product-modal{
  316. .ant-modal-body {
  317. padding: 40px 40px 24px;
  318. }
  319. .btn-cont {
  320. text-align: center;
  321. margin: 35px 0 10px;
  322. }
  323. }
  324. </style>