productModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. _this.spinning = true
  199. sparePartsSaveDetail(form).then(res => {
  200. if (res.status == 200) {
  201. _this.$message.success(res.message)
  202. setTimeout(() => {
  203. _this.isShow = false
  204. _this.$emit('ok', res.data)
  205. _this.spinning = false
  206. }, 1000)
  207. } else {
  208. _this.spinning = false
  209. }
  210. })
  211. } else {
  212. console.log('error submit!!')
  213. return false
  214. }
  215. })
  216. },
  217. changeWarehouseCascade (val) {
  218. if (val.length < 2) {
  219. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  220. this.form.warehouseSn = this.warehouseSnBackups
  221. this.form.warehouseLocationSn = this.warehouseLocationSnBackups
  222. if (this.warehouseSnBackups || this.warehouseLocationSnBackups) {
  223. this.form.warehouse = [this.warehouseSnBackups, this.warehouseLocationSnBackups]
  224. } else {
  225. this.form.warehouse = []
  226. }
  227. } else {
  228. this.form.warehouseSn = val[0] ? val[0] : ''
  229. this.form.warehouseLocationSn = val[1] ? val[1] : ''
  230. this.warehouseSnBackups = this.form.warehouseSn
  231. this.warehouseLocationSnBackups = this.form.warehouseLocationSn
  232. }
  233. },
  234. // 仓库仓位 级联 列表
  235. getWarehouseCascade () {
  236. const _this = this
  237. warehouseCascadeList({}).then(res => {
  238. if (res.status == 200) {
  239. res.data.filter(item => {
  240. // 过滤默认仓库
  241. if (item.defaultFlag == 1) { // defaultFlag为1是默认仓库
  242. _this.defaultWarehouseCascade[0] = item.warehouseSn
  243. // 过滤默认仓位
  244. item.warehouseLocationList.filter(subItem => {
  245. if (subItem.defaultFlag == 1) {
  246. _this.defaultWarehouseCascade[1] = subItem.warehouseLocationSn
  247. _this.form.warehouse = _this.defaultWarehouseCascade
  248. _this.form.warehouseSn = _this.defaultWarehouseCascade[0] || undefined
  249. _this.form.warehouseLocationSn = _this.defaultWarehouseCascade[1] || undefined
  250. _this.warehouseSnBackups = _this.defaultWarehouseCascade[0] || undefined
  251. _this.warehouseLocationSnBackups = _this.defaultWarehouseCascade[1] || undefined
  252. }
  253. })
  254. }
  255. })
  256. res.data.map(item => {
  257. item.sn = item.warehouseSn
  258. if (item.warehouseLocationList) {
  259. item.warehouseLocationList.map(subItem => {
  260. subItem.sn = subItem.warehouseLocationSn
  261. })
  262. }
  263. })
  264. this.warehouseCascadeData = res.data
  265. } else {
  266. this.warehouseCascadeData = []
  267. }
  268. })
  269. }
  270. },
  271. watch: {
  272. // 父页面传过来的弹框状态
  273. openModal (newValue, oldValue) {
  274. this.isShow = newValue
  275. },
  276. // 重定义的弹框状态
  277. isShow (newValue, oldValue) {
  278. if (!newValue) {
  279. this.$emit('close')
  280. this.$refs.ruleForm.resetFields()
  281. this.warehouseSnBackups = ''
  282. this.warehouseLocationSnBackups = ''
  283. } else {
  284. this.getWarehouseCascade()
  285. }
  286. },
  287. itemSn (newValue, oldValue) {
  288. if (this.isShow && newValue) {
  289. this.getDetail()
  290. }
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="less">
  296. .bulkWarehousingOrder-product-modal{
  297. .ant-modal-body {
  298. padding: 40px 40px 24px;
  299. }
  300. .btn-cont {
  301. text-align: center;
  302. margin: 35px 0 10px;
  303. }
  304. }
  305. </style>