123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <template>
- <a-modal
- centered
- class="shelfSet-bindProduct-modal"
- :footer="null"
- :maskClosable="false"
- :title="modalTit"
- v-model="isShow"
- @cancle="isShow=false"
- :width="600">
- <a-spin :spinning="spinning" tip="Loading...">
- <a-form-model
- id="shelfSet-bindProduct-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol">
- <a-form-model-item label="货架名称">{{ nowData&&nowData.shelfName || '--' }}</a-form-model-item>
- <a-form-model-item label="货位号">{{ nowData&&nowData.shelfPlaceCode || '--' }}</a-form-model-item>
- <a-form-model-item :label="type == 'replace' ? '原绑定产品':'绑定产品'" v-if="type != 'bind'">
- {{ productInfo&&productInfo.productCode }}
- <p style="margin: 0;">{{ productInfo&&productInfo.productName || '--' }}</p>
- </a-form-model-item>
- <a-form-model-item label="绑定产品" prop="productSn" v-if="type == 'bind'">
- <productJqList ref="productJqList" :params="{customerSn:nowData&&nowData.customerSn}" @change="productJqChange"></productJqList>
- </a-form-model-item>
- <a-form-model-item label="新绑定产品" prop="productSn" v-if="type == 'replace'">
- <productJqList ref="productJqList" :params="{customerSn:nowData&&nowData.customerSn}" @change="productJqChange"></productJqList>
- <span v-if="form.productSn">{{ productName || '--' }}</span>
- </a-form-model-item>
- <a-form-model-item label="销售价" prop="price">
- <a-row>
- <a-col :span="20">
- <a-input-number
- id="shelfSet-bindProduct-price"
- v-model="form.price"
- :precision="2"
- :min="0.01"
- :max="999999"
- placeholder="请输入正数(最多允许两位小数)"
- suffix="元"
- style="width: 100%;display: inline-block;" />
- </a-col>
- <a-col :span="4"><span style="margin-left: 10px;">元</span></a-col>
- </a-row>
- </a-form-model-item>
- <a-form-model-item label="结算价" prop="cost">
- <a-row>
- <a-col :span="20">
- <a-input-number
- id="shelfSet-bindProduct-cost"
- v-model="form.cost"
- :precision="2"
- :min="0"
- :max="999999"
- placeholder="请输入正数(最多允许两位小数)"
- suffix="元"
- style="width: 100%;display: inline-block;" />
- </a-col>
- <a-col :span="4"><span style="margin-left: 10px;">元</span></a-col>
- </a-row>
- </a-form-model-item>
- <a-form-model-item label="最大库容" prop="maxQty">
- <a-input-number
- id="shelfSet-bindProduct-maxQty"
- v-model="form.maxQty"
- :precision="0"
- :min="0"
- :max="999999"
- placeholder="请输入最大库容(正整数或0)"
- suffix="元"
- style="width: 100%;display: inline-block;" />
- </a-form-model-item>
- </a-form-model>
- <div class="btn-cont">
- <a-button type="primary" id="shelfSet-bindProduct-modal-save" @click="handleSave">保存</a-button>
- <a-button id="shelfSet-bindProduct-modal-back" @click="isShow=false" style="margin-left: 15px;">取消</a-button>
- </div>
- </a-spin>
- </a-modal>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { VSelect } from '@/components'
- import productJqList from '@/views/common/productJqList.vue'
- import { shelfProductSave, shelfProductDetail } from '@/api/shelf'
- export default {
- name: 'ShelfSetBasicInfoModal',
- components: { VSelect, productJqList },
- mixins: [commonMixin],
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- type: {
- type: String,
- default: ''
- },
- nowData: {
- type: Object,
- default: () => {
- return {}
- }
- }
- },
- data () {
- return {
- spinning: false,
- isShow: this.openModal, // 是否打开弹框
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 18 }
- },
- form: {
- productSn: undefined,
- productCode: undefined,
- price: '',
- cost: '',
- maxQty: ''
- },
- rules: {
- productSn: [{ required: true, message: '请选择绑定产品', trigger: 'change' }],
- price: [{ required: true, message: '请输入销售价', trigger: 'blur' }],
- cost: [{ required: true, message: '请输入结算价', trigger: 'blur' }],
- maxQty: [{ required: true, message: '请输入最大库容', trigger: 'blur' }]
- },
- productName: '',
- productInfo: null
- }
- },
- computed: {
- modalTit () {
- let title = ''
- if (this.type == 'edit') {
- title = '修改信息'
- } else if (this.type == 'bind') {
- title = '绑定产品'
- } else if (this.type == 'replace') {
- title = '更换产品'
- }
- return title
- }
- },
- methods: {
- // 产品 change
- productJqChange (obj) {
- this.form.productSn = obj.key || undefined
- this.form.productCode = obj && obj.row && obj.row.code || ''
- this.form.price = obj && obj.row && obj.row.price || ''
- this.form.cost = obj && obj.row && obj.row.cost || ''
- this.productName = obj && obj.row && obj.row.name || ''
- },
- // 保存
- handleSave () {
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const form = JSON.parse(JSON.stringify(_this.form))
- form.shelfPlaceSn = _this.nowData && _this.nowData.shelfPlaceSn
- if (this.type != 'bind') { // 修改信息、更换产品
- form.shelfProductSn = _this.nowData && _this.nowData.shelfProductApiEntity && _this.nowData.shelfProductApiEntity.shelfProductSn
- }
- if (this.type == 'replace') { // 更换产品
- form.updateProductFlag = 1
- }
- _this.spinning = true
- shelfProductSave(form).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.isShow = false
- _this.$emit('ok', res.data)
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- } else {
- console.log('error submit!!')
- return false
- }
- })
- },
- // 获取产品信息
- getProductInfo () {
- shelfProductDetail({ shelfPlaceSn: this.nowData && this.nowData.shelfPlaceSn }).then(res => {
- if (res.status == 200 && res.data) {
- this.productInfo = res.data
- if (this.type == 'edit') {
- this.form.productSn = res.data.productSn
- this.form.productCode = res.data.productCode
- }
- this.form.price = res.data.price
- this.form.cost = res.data.cost
- this.form.maxQty = res.data.maxQty
- } else {
- this.productInfo = null
- this.$refs.ruleForm.resetFields()
- }
- })
- },
- resetData () {
- this.form.productSn = undefined
- this.form.productCode = undefined
- this.form.price = ''
- this.form.cost = ''
- this.form.maxQty = ''
- if (this.$refs.productJqList) {
- this.$refs.productJqList.resetForm()
- }
- this.$refs.ruleForm.resetFields(['productSn'])
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.resetData()
- this.productName = ''
- this.productInfo = null
- } else {
- if (this.type != 'bind') { // 修改信息、更换产品
- this.getProductInfo()
- }
- }
- }
- }
- }
- </script>
- <style lang="less">
- .shelfSet-bindProduct-modal {
- .ant-modal-body {
- padding: 40px 40px 24px;
- }
- .ant-form-item{
- margin-bottom: 15px;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- }
- </style>
|