| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <template>
- <view class="uni-app">
- <view class="status-bar" />
- <view class="main-container">
- <wk-nav-bar :title="navTitle">
- <!-- #ifndef MP-WEIXIN -->
- <button class="button white-btn" @click="handleSave">
- 保存
- </button>
- <!-- #endif -->
- </wk-nav-bar>
-
- <view class="container">
- <view class="scroll-content">
- <wk-form
- ref="form"
- :fields="fieldArr"
- :batch-id="batchId"
- @change="handleValueChange" />
-
- <product-choose-add
- v-if="productField"
- ref="product"
- :default-value="productField.value"
- @change="handleChangeProduct" />
- </view>
- </view>
-
- <!-- #ifdef MP-WEIXIN -->
- <view class="footer-btn-group">
- <button
- v-if="productField"
- class="button choose-product-btn"
- @click="handleAddProduct">
- 添加产品
- </button>
- <button class="button" @click="handleSave">
- 保存
- </button>
- </view>
- <!-- #endif -->
- </view>
- </view>
- </template>
- <script>
- import { QueryBusinessSetting } from 'API/crm/flow'
- import {
- QueryFieldList,
- AddBusiness,
- UpdateBusiness,
- QueryProduct as BusinessProduct
- } from 'API/crm/business'
-
- import ProductChooseAdd from '../components/baseAdd/productChooseAdd.vue'
-
- import CreateMixins from '../mixins/create.js'
- export default {
- name: 'CreateBusiness',
- components: {
- ProductChooseAdd
- },
- mixins: [CreateMixins],
- data() {
- return {
- moduleType: 'business',
-
- productField: null,
- defaultProductList: {},
- businessStatusList: [],
- }
- },
- onLoad() {
- QueryBusinessSetting().then(res => {
- this.businessStatusList = res
- this.getFieldList()
- }).catch(() => {})
- },
- methods: {
- /**
- * 获取表单字段
- */
- getFieldList() {
- const params = { type: 1 }
- if (this.id) params.id = this.id
- QueryFieldList(params)
- .then(res => {
- let findIndex = res.findIndex(o => o.formType === 'product')
- if (findIndex !== -1) {
- this.productField = res.splice(findIndex, 1)[0]
- }
-
- // 如果有商机阶段则删掉该字段,商机阶段只能在详情中进行修改
- findIndex = res.findIndex(o => o.formType === 'business_status')
- if (findIndex !== -1) {
- res.splice(findIndex, 1)
- }
-
- res.forEach(field => {
- // 自动编号为非必填
- if (field.autoGeneNumber === 1) {
- field.isNull = 0
- }
-
- if (!this.$isEmpty(field.authLevel)) {
- // 判断字段权限,如果没有权限则直接禁止修改
- field.disabled = this.getDisabledStatusByAuth(field)
- if (field.disabled) {
- if (field.sys_config) {
- field.sys_config.disabledMsg = ''
- }
- }
- }
-
- if (
- this.id &&
- field.formType === 'business_type' &&
- field.value
- ) {
- // 商机下 商机状态组
- field.value = this.businessStatusList.filter(o => o.flowId === field.value)
- } else {
- field.value = this.mixinsFormatFieldValue(field)
- }
- })
-
- this.fieldArr = res
- this.setForm()
- })
- .catch(() => {
- })
- },
-
- /**
- * 表单值发生改变
- * @param {Object} data
- */
- handleValueChange(data) {
- // console.log('value change: ', data)
- },
-
- /**
- * 去选择产品
- */
- handleAddProduct() {
- this.$nextTick(() => {
- if (this.$refs.product) {
- this.$refs.product.handleChoose()
- }
- })
- },
-
- /**
- * 确认选择产品后
- * @param {Object} data
- */
- handleChangeProduct(data) {
- console.log('change product: ', data)
- if (this.$refs.form) {
- this.$refs.form.setFormVal('money', data.totalMoney)
- }
- },
-
- /**
- * 保存
- */
- handleSave() {
- this.loading = true
- this.$refs.form.getForm().then(async form => {
- if (this.productField) {
- const productData = this.$refs.product.getForm()
- form.product = productData.product
- form.entity = {
- ...form.entity,
- discountRate: productData.discountRate,
- totalPrice: productData.totalPrice
- }
- }
-
- this.baseFormatSaveData(form)
- console.log('save: ', form)
- // this.loading = false
- // return
-
- const request = this.id ? UpdateBusiness : AddBusiness
- request(form).then(() => {
- this.$toast(this.id ? '修改成功' : '添加成功')
- this.$refreshAndToPrev(this)
- }).catch(() => {
- this.loading = false
- })
- }).catch(() => {
- this.loading = false
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- @import '../style/create.scss';
- </style>
|