123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <template>
- <a-modal
- centered
- class="purchaseOrder-basicInfo-modal"
- :footer="null"
- :maskClosable="false"
- title="新增采购单"
- v-model="isShow"
- @cancel="cancel"
- :width="800">
- <a-spin :spinning="spinning" tip="Loading...">
- <a-form-model
- id="purchaseOrder-basicInfo-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol" >
- <a-form-model-item label="供应商" prop="purchaseTargetSn">
- <a-radio-group
- name="radioGroup"
- v-model="form.purchaseTargetSn"
- @change="tragetTypeChange"
- id="purchaseOrder-basicInfo-purchaseTargetSn" >
- <a-radio v-for="item in purchaseTragetType" :key="item.purchaseTargetSn" :value="item.purchaseTargetSn" class="radio-s">{{ item.purchaseTargetName }}</a-radio>
- </a-radio-group>
- </a-form-model-item>
- <a-form-model-item label="支付方式" prop="settleStyleSn">
- <a-select placeholder="请选择支付方式" v-model="form.settleStyleSn">
- <a-select-option v-for="item in settleStyleList" :key="item.settleStyleSn" :value="item.settleStyleSn">
- {{ item.name }}
- </a-select-option>
- </a-select>
- </a-form-model-item>
- <a-form-model-item>
- <span slot="label"><i style="color: red;">*</i> 收货地址</span>
- {{ chooseAddr }}
- <a-button type="link" id="purchaseOrder-basicInfo-chooseAddr" @click="handleChoose">{{ addressVal }} >></a-button>
- </a-form-model-item>
- <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
- <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
- <a-button @click="cancel" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
- </a-form-model-item>
- </a-form-model>
- </a-spin>
- <!-- 选择地址 -->
- <choose-address-modal :openModal="openAddrModal" @ok="handleOk" @verify="verifyFun" @close="openAddrModal=false" />
- </a-modal>
- </template>
- <script>
- import { VSelect } from '@/components'
- import chooseAddressModal from './receivingAddress/chooseAddressModal.vue'
- import { settleStyleQueryAll } from '@/api/settleStyle'
- import { shippingAddressQuery } from '@/api/shippingAddress'
- import { purchaseSave, purchaseTargetList } from '@/api/purchase'
- export default {
- name: 'BasicInfoModal',
- components: { VSelect, chooseAddressModal },
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- }
- },
- data () {
- return {
- spinning: false,
- confirmLoading: false,
- isShow: this.openModal, // 是否打开弹框
- settleStyleList: [], // 支付方式
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 18 }
- },
- form: {
- purchaseTargetType: '', // 供应商
- shippingAddressProvinceName: '', // 省
- shippingAddressCityName: '', // 市
- shippingAddressCountyName: '', // 区
- shippingAddress: '', // 详细地址
- consigneeTel: '', // 联系电话
- consigneeName: '', // 联系人名称
- settleStyleSn: undefined, // 支付方式
- purchaseTargetSn: undefined,
- purchaseTargetName: ''
- },
- rules: {
- purchaseTargetSn: [
- { required: true, message: '请选择供应商', trigger: 'change' }
- ],
- settleStyleSn: [
- { required: true, message: '请选择支付方式', trigger: 'change' }
- ]
- },
- purchaseTragetType: [],
- addressVal: '选择地址', // 选择地址/更换地址
- chooseAddr: '', // 当前已选地址信息
- addressId: undefined,
- openAddrModal: false // 选择地址弹框是否显示
- }
- },
- methods: {
- resetForm () {
- this.$refs.ruleForm.resetFields()
- this.chooseAddr = ''
- this.addressVal = '选择地址'
- this.form.shippingAddressProvinceName = ''// 省
- this.form.shippingAddressCityName = '' // 市
- this.form.shippingAddressCountyName = '' // 区
- this.form.shippingAddress = ''// 详细地址
- this.form.consigneeTel = '' // 联系电话
- this.form.consigneeName = ''
- this.form.purchaseTargetType = ''
- this.form.purchaseTargetSn = undefined
- this.form.purchaseTargetName = ''
- },
- // 供应商change
- tragetTypeChange (e) {
- const val = e.target.value
- const ind = this.purchaseTragetType.findIndex(item => item.purchaseTargetSn == val)
- if (ind != -1) {
- this.form.purchaseTargetType = this.purchaseTragetType[ind].purchaseTargetType
- this.form.purchaseTargetName = this.purchaseTragetType[ind].purchaseTargetName
- }
- },
- // 保存
- handleSubmit (e) {
- e.preventDefault()
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- if (_this.form.consigneeTel == '') {
- _this.$message.info('请选择收货地址')
- return false
- }
- _this.spinning = true
- purchaseSave(_this.form).then(res => {
- if (res.status == 200) {
- _this.isShow = false
- _this.$emit('ok', res.data)
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- _this.$message.info(res.message)
- })
- } else {
- return false
- }
- })
- },
- // 取消
- cancel () {
- this.$emit('cancel')
- },
- // 选择地址
- handleChoose () {
- this.openAddrModal = true
- },
- // 地址保存
- handleOk (data) {
- this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '') + ')' + ' ' + (data.address || '')
- this.addressVal = '更换地址'
- this.form.shippingAddressProvinceName = data.provinceName // 省
- this.form.shippingAddressCityName = data.cityName // 市
- this.form.shippingAddressCountyName = data.countyName // 区
- this.form.shippingAddress = data.addr// 详细地址
- this.form.consigneeTel = data.consigneeTel // 联系电话
- this.form.consigneeName = data.consigneeName
- this.openAddrModal = false
- },
- // 编辑信息
- setData (data) {
- this.form = JSON.parse(JSON.stringify(data))
- this.chooseAddr = data.consigneeName + '(' + data.consigneeTel + ')' + ' ' + data.shippingAddressProvinceName + '-' + data.shippingAddressCityName + '-' + data.shippingAddressCountyName + ' ' + data.shippingAddress
- this.addressVal = '更换地址'
- },
- // 获取收款方式
- getSettleStyle () {
- settleStyleQueryAll().then(res => {
- if (res.status == 200) {
- this.settleStyleList = res.data
- }
- })
- },
- getParentDealer () {
- purchaseTargetList({}).then(res => {
- if (res.status == 200) {
- this.purchaseTragetType = res.data
- } else {
- this.purchaseTragetType = []
- }
- })
- },
- // 获取默认地址
- getDefaultAddress () {
- shippingAddressQuery({ defaultFlag: 1 }).then(res => {
- if (res.status == 200) {
- if (res.data.length == 1) {
- res.data[0].address = res.data[0].provinceName + '-' + res.data[0].cityName + '-' + res.data[0].countyName + '-' + res.data[0].addr
- this.addressId = res.data[0].id || undefined
- this.handleOk(res.data[0])
- }
- }
- })
- },
- verifyFun (id) {
- if (id == this.addressId) {
- this.chooseAddr = ''
- this.addressVal = '选择地址'
- this.form.shippingAddressProvinceName = ''// 省
- this.form.shippingAddressCityName = '' // 市
- this.form.shippingAddressCountyName = '' // 区
- this.form.shippingAddress = ''// 详细地址
- this.form.consigneeTel = '' // 联系电话
- this.form.consigneeName = ''
- }
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.resetForm()
- } else {
- this.getSettleStyle()
- this.getParentDealer()
- this.getDefaultAddress()
- }
- }
- }
- }
- </script>
- <style lang="less">
- .purchaseOrder-basicInfo-modal{
- .ant-modal-body {
- padding: 40px 40px 24px;
- }
- .radio-s{
- margin-bottom: 8px;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- }
- </style>
|