productModal.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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"
  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 { sparePartsSaveDetail, sparePartsDetailD } from '@/api/spareParts'
  81. export default {
  82. name: 'BulkWarehousingOrderBasicInfoModal',
  83. components: { VSelect },
  84. props: {
  85. openModal: { // 弹框显示状态
  86. type: Boolean,
  87. default: false
  88. },
  89. itemSn: {
  90. type: [Number, String],
  91. default: ''
  92. },
  93. nowData: {
  94. type: Object,
  95. default: () => {
  96. return null
  97. }
  98. }
  99. },
  100. data () {
  101. this.fetchUser = debounce(this.fetchUser, 800)
  102. return {
  103. isShow: this.openModal, // 是否打开弹框
  104. formItemLayout: {
  105. labelCol: { span: 5 },
  106. wrapperCol: { span: 16 }
  107. },
  108. form: {
  109. supplierSn: '', // 供应商
  110. productSn: undefined,
  111. productName: '',
  112. productCode: '',
  113. productOrigCode: '',
  114. warehouse: [],
  115. warehouseSn: '',
  116. warehouseLocationSn: '',
  117. productCost: '',
  118. productQty: ''
  119. },
  120. rules: {
  121. productSn: [
  122. { required: true, message: '请选择产品编码', trigger: 'change' }
  123. ],
  124. warehouse: [
  125. { required: true, message: '请选择仓库仓位', trigger: 'change' }
  126. ],
  127. productCost: [
  128. { required: true, message: '请输入成本价', trigger: 'blur' }
  129. ],
  130. productQty: [
  131. { required: true, message: '请输入数量', trigger: 'blur' }
  132. ]
  133. },
  134. fetching: false,
  135. productData: [],
  136. warehouseCascadeData: [], // 仓库仓位 下拉数据
  137. warehouseSnBackups: '', // 仓库备份数据
  138. warehouseLocationSnBackups: '' // 仓位备份数据
  139. }
  140. },
  141. methods: {
  142. // 搜索产品
  143. fetchUser (value) {
  144. console.log('fetching user', value)
  145. this.fetching = true
  146. const params = {
  147. product: {
  148. code: value
  149. },
  150. supplierSn: this.nowData.supplierSn,
  151. onlineFalg: '1', // 已上线
  152. pageNo: 1,
  153. pageSize: 20
  154. }
  155. supplierProductList(params).then(res => {
  156. if (res.status == 200) {
  157. this.productData = res.data.list
  158. this.fetching = false
  159. } else {
  160. this.productData = []
  161. this.fetching = false
  162. }
  163. })
  164. },
  165. // 调往对象名称 change
  166. handleChange (value) {
  167. const ind = this.productData.findIndex(item => item.productSn == value)
  168. this.form.productName = this.productData[ind].product.name
  169. this.form.productCode = this.productData[ind].product.code
  170. this.form.productOrigCode = this.productData[ind].product.origCode
  171. this.form.productCost = (this.productData[ind].cost && this.productData[ind].cost != 0) ? this.productData[ind].cost : this.productData[ind].cost == 0 ? 0.1 : ''
  172. },
  173. // 详情
  174. getDetail () {
  175. sparePartsDetailD({ sn: this.itemSn }).then(res => {
  176. if (res.status == 200) {
  177. const data = res.data
  178. this.form = Object.assign(this.form, data)
  179. this.fetchUser(this.form.productCode)
  180. this.form.warehouse = [this.form.warehouseSn, this.form.warehouseLocationSn]
  181. this.warehouseSnBackups = this.form.warehouseSn || undefined
  182. this.warehouseLocationSnBackups = this.form.warehouseLocationSn || undefined
  183. }
  184. })
  185. },
  186. // 保存
  187. handleSave () {
  188. const _this = this
  189. this.$refs.ruleForm.validate(valid => {
  190. if (valid) {
  191. const form = JSON.parse(JSON.stringify(_this.form))
  192. form.sparePartsSn = this.nowData.sparePartsSn
  193. form.sparePartsNo = this.nowData.sparePartsNo
  194. form.supplierSn = this.nowData.supplierSn
  195. sparePartsSaveDetail(form).then(res => {
  196. if (res.status == 200) {
  197. _this.$message.success(res.message)
  198. setTimeout(() => {
  199. _this.isShow = false
  200. _this.$emit('ok', res.data)
  201. }, 1000)
  202. }
  203. })
  204. } else {
  205. console.log('error submit!!')
  206. return false
  207. }
  208. })
  209. },
  210. changeWarehouseCascade (val) {
  211. if (val.length < 2) {
  212. this.$message.warning('当前仓库无仓位,请选择其他仓库')
  213. this.form.warehouseSn = this.warehouseSnBackups
  214. this.form.warehouseLocationSn = this.warehouseLocationSnBackups
  215. if (this.warehouseSnBackups || this.warehouseLocationSnBackups) {
  216. this.form.warehouse = [this.warehouseSnBackups, this.warehouseLocationSnBackups]
  217. } else {
  218. this.form.warehouse = []
  219. }
  220. } else {
  221. this.form.warehouseSn = val[0] ? val[0] : ''
  222. this.form.warehouseLocationSn = val[1] ? val[1] : ''
  223. this.warehouseSnBackups = this.form.warehouseSn
  224. this.warehouseLocationSnBackups = this.form.warehouseLocationSn
  225. }
  226. },
  227. // 仓库仓位
  228. getWarehouseCascade () {
  229. warehouseCascadeList({}).then(res => {
  230. if (res.status == 200) {
  231. res.data.map(item => {
  232. item.sn = item.warehouseSn
  233. if (item.warehouseLocationList) {
  234. item.warehouseLocationList.map(subItem => {
  235. subItem.sn = subItem.warehouseLocationSn
  236. })
  237. }
  238. })
  239. this.warehouseCascadeData = res.data
  240. } else {
  241. this.warehouseCascadeData = []
  242. }
  243. })
  244. }
  245. },
  246. watch: {
  247. // 父页面传过来的弹框状态
  248. openModal (newValue, oldValue) {
  249. this.isShow = newValue
  250. },
  251. // 重定义的弹框状态
  252. isShow (newValue, oldValue) {
  253. if (!newValue) {
  254. this.$emit('close')
  255. this.$refs.ruleForm.resetFields()
  256. this.warehouseSnBackups = ''
  257. this.warehouseLocationSnBackups = ''
  258. } else {
  259. if (this.warehouseCascadeData.length == 0) {
  260. this.getWarehouseCascade()
  261. }
  262. }
  263. },
  264. itemSn (newValue, oldValue) {
  265. if (this.isShow && newValue) {
  266. this.getDetail()
  267. }
  268. }
  269. }
  270. }
  271. </script>
  272. <style lang="less">
  273. .bulkWarehousingOrder-product-modal{
  274. .ant-modal-body {
  275. padding: 40px 40px 24px;
  276. }
  277. .btn-cont {
  278. text-align: center;
  279. margin: 35px 0 10px;
  280. }
  281. }
  282. </style>