|
|
@@ -0,0 +1,432 @@
|
|
|
+<template>
|
|
|
+ <el-dialog :title="title" :visible.sync="editVisible" @close="handleClose">
|
|
|
+ <el-form ref="editForm" :model="editForm" :rules="editRules">
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="合同编号" prop="contractCode">
|
|
|
+ <el-input v-model="editForm.contractCode" placeholder="请输入合同编号" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="合同名称" prop="contractName">
|
|
|
+ <el-input v-model="editForm.contractName" placeholder="请输入合同名称" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="关联项目" prop="nboName">
|
|
|
+ <el-input
|
|
|
+ ref="businessInput"
|
|
|
+ v-model="editForm.nboName"
|
|
|
+ placeholder="请选择关联项目"
|
|
|
+ @focus="openProject" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="客户名称" prop="nboId">
|
|
|
+ <el-input v-model="editForm.custName" disabled />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="合同开始时间" prop="contractStartTime">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="editForm.contractStartTime"
|
|
|
+ :picker-options="pickerOptionsStart"
|
|
|
+ placeholder="选择开始日期"
|
|
|
+ style="width: 100%"
|
|
|
+ type="date"
|
|
|
+ value-format="yyyy-MM-dd" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="合同结束时间" prop="contractEndTime">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="editForm.contractEndTime"
|
|
|
+ :picker-options="pickerOptionsEnd"
|
|
|
+ placeholder="选择结束日期"
|
|
|
+ style="width: 100%"
|
|
|
+ type="date"
|
|
|
+ value-format="yyyy-MM-dd" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="负责人" prop="inchargeId">
|
|
|
+ <el-select
|
|
|
+ v-model="editForm.inchargeId"
|
|
|
+ placeholder="请选择负责人"
|
|
|
+ style="width: 100%"
|
|
|
+ @change="changeIncharge">
|
|
|
+ <el-option v-for="item in usersList" :key="item.id" :label="item.userName" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="公司签约人" prop="signatoryName">
|
|
|
+ <el-input
|
|
|
+ ref="userInput"
|
|
|
+ v-model="editForm.signatoryName"
|
|
|
+ placeholder="请选择公司签约人"
|
|
|
+ @focus="openUser" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="经销商" prop="distributorName">
|
|
|
+ <el-input
|
|
|
+ ref="distributorInput"
|
|
|
+ v-model="editForm.distributorName"
|
|
|
+ placeholder="请选择经销商"
|
|
|
+ @focus="openDistributor" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="合同类型" prop="contractType">
|
|
|
+ <el-select v-model="editForm.contractType" placeholder="合同类型" style="width: 100%">
|
|
|
+ <el-option v-for="item in contractOptions" :key="item.value" :label="item.value" :value="item.value" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-form-item label="备注" prop="remark">
|
|
|
+ <el-input v-model="editForm.remark" placeholder="请输入备注" :rows="5" type="textarea" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form>
|
|
|
+ <!-- 产品分类 -->
|
|
|
+ <el-row>
|
|
|
+ <el-row class="mb10" :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <p>产品:</p>
|
|
|
+ </el-col>
|
|
|
+ <el-col class="proj-col" :span="12">
|
|
|
+ <el-button type="primary" @click="$refs.product.open()">选择产品</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24">
|
|
|
+ <product-table
|
|
|
+ ref="productTable"
|
|
|
+ :product-data="productData"
|
|
|
+ @changeProductData="changeProductData"
|
|
|
+ @delProductData="delProductData" />
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <span slot="footer">
|
|
|
+ <el-button v-show="!editForm.id" type="primary" @click="contractSave">保存</el-button>
|
|
|
+ <el-button v-show="editForm.id" type="primary" @click="contractEdit">保存</el-button>
|
|
|
+ <el-button @click="editVisible = false">取消</el-button>
|
|
|
+ </span>
|
|
|
+ <!-- 选择项目 -->
|
|
|
+ <select-business ref="project" :multiple="false" @save="getBusinessInfo" />
|
|
|
+ <!-- 选择经销商 -->
|
|
|
+ <select-distributor ref="distributor" :multiple="false" @save="getDistributor" />
|
|
|
+ <!-- 选择公司签约人 -->
|
|
|
+ <select-user ref="user" :multiple="false" @save="getUser" />
|
|
|
+ <!-- 选择产品 -->
|
|
|
+ <select-product ref="product" :multiple="true" @save="getProduct" />
|
|
|
+ </el-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import { mapGetters } from 'vuex'
|
|
|
+ import to from 'await-to-js'
|
|
|
+ import contractApi from '@/api/contract'
|
|
|
+ import businessApi from '@/api/proj/business'
|
|
|
+ import ProductTable from './ProductTable'
|
|
|
+ import SelectBusiness from '@/components/select/SelectBusiness'
|
|
|
+ import SelectDistributor from '@/components/select/SelectDistributor'
|
|
|
+ import SelectUser from '@/components/select/SelectUser'
|
|
|
+ import SelectProduct from '@/components/select/SelectProduct'
|
|
|
+ export default {
|
|
|
+ components: {
|
|
|
+ ProductTable,
|
|
|
+ SelectBusiness,
|
|
|
+ SelectDistributor,
|
|
|
+ SelectUser,
|
|
|
+ SelectProduct,
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ usersList: {
|
|
|
+ type: Array,
|
|
|
+ default: () => [],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ title: '新增客户信息',
|
|
|
+ editVisible: false,
|
|
|
+ editForm: {
|
|
|
+ contractCode: '', //合同编号
|
|
|
+ contractName: '', //合同名称
|
|
|
+ contractType: '', //合同类型
|
|
|
+ nboId: null, //项目id
|
|
|
+ nboName: '', //项目名称
|
|
|
+ custName: '', // 客户名称
|
|
|
+ inchargeId: null, //负责人
|
|
|
+ inchargeName: '', //负责人姓名
|
|
|
+ contractStartTime: '', //合同开始时间
|
|
|
+ contractEndTime: '', //合同结束时间
|
|
|
+ signatoryName: '', //公司签约人
|
|
|
+ signatoryId: null, //公司签约人id
|
|
|
+ distributorId: null, //经销商id
|
|
|
+ distributorName: '', //经销商name
|
|
|
+ remark: '', //备注
|
|
|
+ },
|
|
|
+ editRules: {
|
|
|
+ contractCode: [{ required: true, trigger: 'blur', message: '请输入合同编号' }],
|
|
|
+ contractName: [{ required: true, trigger: 'blur', message: '请输入合同名称' }],
|
|
|
+ contractType: [{ required: true, trigger: 'change', message: '请选择合同类型' }],
|
|
|
+ nboName: [{ required: true, trigger: 'change', message: '请选择关联项目' }],
|
|
|
+ contractStartTime: [
|
|
|
+ { required: true, trigger: 'change', validator: this.pickerOptionsStart, message: '请选择开始时间' },
|
|
|
+ ],
|
|
|
+ contractEndTime: [
|
|
|
+ { required: true, trigger: 'change', validator: this.pickerOptionsEnd, message: '请选择结束时间' },
|
|
|
+ ],
|
|
|
+ inchargeId: [{ required: true, trigger: 'change', message: '请选择负责人' }],
|
|
|
+ signatoryName: [{ required: true, trigger: 'change', message: '请选择公司签约人' }],
|
|
|
+ distributorName: [{ required: true, trigger: 'change', message: '请选择经销商' }],
|
|
|
+ },
|
|
|
+ pickerOptionsStart: {
|
|
|
+ disabledDate: (time) => {
|
|
|
+ let endDateVal = this.editForm.contractEndTime
|
|
|
+ if (endDateVal) {
|
|
|
+ return time.getTime() > new Date(endDateVal).getTime()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ pickerOptionsEnd: {
|
|
|
+ disabledDate: (time) => {
|
|
|
+ let beginDateVal = this.editForm.contractStartTime
|
|
|
+ if (beginDateVal) {
|
|
|
+ return time.getTime() < new Date(beginDateVal).getTime() - 1 * 24 * 60 * 60 * 1000
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ contractOptions: [], //合同类型
|
|
|
+ productData: [],
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapGetters({
|
|
|
+ userId: 'user/id',
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.getOptions()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getOptions() {
|
|
|
+ Promise.all([this.getDicts('contract_type')])
|
|
|
+ .then(([contract]) => {
|
|
|
+ this.contractOptions = contract.data.values || []
|
|
|
+ // 设置负责人默认为当前用户
|
|
|
+ this.editForm.inchargeId = this.userId
|
|
|
+ this.editForm.inchargeName = this.usersList.filter((item) => item.id == this.userId)[0]['userName']
|
|
|
+ })
|
|
|
+ .catch((err) => console.log(err))
|
|
|
+ },
|
|
|
+ async init(id) {
|
|
|
+ if (!id) {
|
|
|
+ this.title = '新增合同信息'
|
|
|
+ } else {
|
|
|
+ this.title = '编辑合同'
|
|
|
+ const [err, res] = await to(contractApi.getDetails({ id }))
|
|
|
+ if (err) return
|
|
|
+ if (res.data) {
|
|
|
+ // eslint-disable-next-line no-unused-vars
|
|
|
+ let { product, ...data } = res.data
|
|
|
+ this.editForm = data
|
|
|
+ this.productData =
|
|
|
+ product.length > 0
|
|
|
+ ? product.map((item) => ({
|
|
|
+ id: item.prodId,
|
|
|
+ prodName: item.prodName,
|
|
|
+ prodClass: item.prodClass,
|
|
|
+ guidPrice: item.sugSalesPrice,
|
|
|
+ price: item.tranPrice,
|
|
|
+ count: item.prodNum,
|
|
|
+ }))
|
|
|
+ : []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.editVisible = true
|
|
|
+ },
|
|
|
+ // 修改责任人
|
|
|
+ changeIncharge(selectedId) {
|
|
|
+ this.editForm.inchargeName = this.usersList.filter((item) => item.id == selectedId)[0]['userName']
|
|
|
+ },
|
|
|
+ // 打开选择项目
|
|
|
+ openProject() {
|
|
|
+ this.$refs.project.open()
|
|
|
+ this.$refs.businessInput.blur()
|
|
|
+ },
|
|
|
+ // 关闭选择项目获取项目信息
|
|
|
+ getBusinessInfo(data) {
|
|
|
+ let business = data[0] || null
|
|
|
+ if (!business) return
|
|
|
+ this.editForm.custName = business.custName
|
|
|
+ this.editForm.nboId = business.id
|
|
|
+ this.editForm.nboName = business.nboName
|
|
|
+ // 获取产品信息
|
|
|
+ this.getProjectInfo(business.id)
|
|
|
+ },
|
|
|
+ // 打开选择经销商
|
|
|
+ openDistributor() {
|
|
|
+ this.$refs.distributor.open()
|
|
|
+ this.$refs.distributorInput.blur()
|
|
|
+ },
|
|
|
+ // 关闭经销商获取经销商信息
|
|
|
+ getDistributor(data) {
|
|
|
+ let distributor = data[0] || null
|
|
|
+ if (!distributor) return
|
|
|
+ this.editForm.distributorName = distributor.distName
|
|
|
+ this.editForm.distributorId = distributor.id
|
|
|
+ },
|
|
|
+ // 打开选择公司签约人
|
|
|
+ openUser() {
|
|
|
+ this.$refs.user.open()
|
|
|
+ this.$refs.userInput.blur()
|
|
|
+ },
|
|
|
+ // 获取签约人信息
|
|
|
+ getUser(data) {
|
|
|
+ let user = data[0] || null
|
|
|
+ if (!user) return
|
|
|
+ this.editForm.signatoryName = user.userName
|
|
|
+ this.editForm.signatoryId = user.id
|
|
|
+ },
|
|
|
+ // 获取产品信息
|
|
|
+ getProduct(data) {
|
|
|
+ // 重构产品数据结构
|
|
|
+ if (data.length > 0) this.setProductData(data)
|
|
|
+ },
|
|
|
+ // 根据项目id获取产品信息
|
|
|
+ getProjectInfo(id) {
|
|
|
+ let params = { id }
|
|
|
+ businessApi.getProductByBusinessId(params).then((res) => {
|
|
|
+ if (res.data && res.data.length > 0) this.setProductData(res.data)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ setProductData(data) {
|
|
|
+ let projData = data.map((item) => ({
|
|
|
+ id: item.id,
|
|
|
+ prodName: item.prodName,
|
|
|
+ prodClass: item.prodClass,
|
|
|
+ guidPrice: item.guidPrice,
|
|
|
+ price: item.guidPrice,
|
|
|
+ count: 1,
|
|
|
+ }))
|
|
|
+ this.productData.push(...projData)
|
|
|
+ this.productData = this.removeDuplicateObj(this.productData)
|
|
|
+ },
|
|
|
+ // 数组对象去重
|
|
|
+ removeDuplicateObj(arr) {
|
|
|
+ let obj = {}
|
|
|
+ arr = arr.reduce((newArr, next) => {
|
|
|
+ obj[next.id] ? '' : (obj[next.id] = true && newArr.push(next))
|
|
|
+ return newArr
|
|
|
+ }, [])
|
|
|
+ return arr
|
|
|
+ },
|
|
|
+ // 修改产品列表数据
|
|
|
+ changeProductData(data) {
|
|
|
+ this.productData = this.productData.map((item) => {
|
|
|
+ return item.id === data.id ? data : item
|
|
|
+ })
|
|
|
+ },
|
|
|
+ delProductData(data) {
|
|
|
+ this.productData = this.productData.filter((item) => item.id != data.id)
|
|
|
+ },
|
|
|
+ // 保存合同
|
|
|
+ async contractSave() {
|
|
|
+ let product = this.productData.map((item) => ({
|
|
|
+ prodId: item.id,
|
|
|
+ prodNum: item.count,
|
|
|
+ maintTerm: 1,
|
|
|
+ sugSalesPrice: item.guidPrice,
|
|
|
+ tranPrice: this.delcommafy(item.price),
|
|
|
+ remark: '',
|
|
|
+ }))
|
|
|
+ let params = Object.assign({ ...this.editForm }, { product })
|
|
|
+ const [valid] = await to(this.$refs.editForm.validate())
|
|
|
+ if (valid == false) return
|
|
|
+ if (product.length == 0) return this.$message.warning('请选择产品信息')
|
|
|
+ const [err, res] = await to(contractApi.addContract(params))
|
|
|
+ if (err) return
|
|
|
+ if (res.code == 200) this.$message.success(res.msg)
|
|
|
+ else return
|
|
|
+ this.editVisible = false
|
|
|
+ this.$emit('contractSave')
|
|
|
+ },
|
|
|
+ // 编辑合同
|
|
|
+ async contractEdit() {
|
|
|
+ let product = this.productData.map((item) => ({
|
|
|
+ prodId: item.id,
|
|
|
+ prodNum: item.count,
|
|
|
+ maintTerm: 1,
|
|
|
+ sugSalesPrice: item.guidPrice,
|
|
|
+ tranPrice: this.delcommafy(item.price),
|
|
|
+ remark: '',
|
|
|
+ }))
|
|
|
+ let params = Object.assign({ ...this.editForm }, { product })
|
|
|
+ const [valid] = await to(this.$refs.editForm.validate())
|
|
|
+ if (valid == false) return
|
|
|
+ if (product.length == 0) return this.$message.warning('请选择产品信息')
|
|
|
+ const [err, res] = await to(contractApi.updateContract(params))
|
|
|
+ if (err) return
|
|
|
+ if (res.code == 200) this.$message.success(res.msg)
|
|
|
+ else return
|
|
|
+ this.editVisible = false
|
|
|
+ this.$emit('contractSave')
|
|
|
+ },
|
|
|
+ handleClose() {
|
|
|
+ this.editForm = {
|
|
|
+ contractCode: '', //合同编号
|
|
|
+ contractName: '', //合同名称
|
|
|
+ contractType: '', //合同类型
|
|
|
+ nboId: null, //项目id
|
|
|
+ nboName: '', //项目名称
|
|
|
+ custName: '', // 客户名称
|
|
|
+ inchargeId: null, //负责人
|
|
|
+ inchargeName: '', //负责人名称
|
|
|
+ contractStartTime: '', //合同开始时间
|
|
|
+ contractEndTime: '', //合同结束时间
|
|
|
+ signatoryName: '', //公司签约人
|
|
|
+ signatoryId: null, //公司签约人id
|
|
|
+ distributorId: null, //经销商id
|
|
|
+ distributorName: '', //经销商name
|
|
|
+ remark: '', //备注
|
|
|
+ }
|
|
|
+ this.productData = []
|
|
|
+ this.$refs.editForm.resetFields()
|
|
|
+ },
|
|
|
+ delcommafy(num) {
|
|
|
+ if (!num) return 0
|
|
|
+ num = num.toString()
|
|
|
+ num = num.replace(/,/gi, '')
|
|
|
+ if (num.indexOf('.00') > 0) num = parseInt(num)
|
|
|
+ return Number(num)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+ .mb10 {
|
|
|
+ margin-bottom: 10px;
|
|
|
+ }
|
|
|
+ .proj-col {
|
|
|
+ text-align: right;
|
|
|
+ }
|
|
|
+</style>
|