productModal.vue 9.3 KB

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