MrShi
2024-11-19 56edbd80963acea41d9b9737bb9264f57a6e4ae2
company/src/components/business/OperaSolutionsWindow.vue
@@ -7,325 +7,270 @@
        @confirm="confirm"
    >
        <el-form :model="form" ref="form" :rules="rules">
            <el-form-item label="方案名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入" v-trim/>
            </el-form-item>
            <el-form-item label="保险公司" prop="insuranceId">
                <el-select v-model="form.insuranceId" @change="getAllWorktype1" placeholder="请选择">
            <el-form-item label="主方案" prop="parentId">
                <el-select v-model="form.parentId" filterable @change="changeParent" placeholder="请选择">
                    <el-option
                        v-for="item in company"
                        v-for="item in list"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="承保公司" prop="companyName">
                <el-input v-model="form.companyName" placeholder="请输入" v-trim/>
            </el-form-item>
            <el-form-item label="投保年龄" prop="minAge">
                <div style="display: flex; align-items: center;">
                    <el-select v-model="form.minAge" style="flex: 1;" placeholder="请选择">
                        <el-option
                            v-for="item in 60"
                            :key="item"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                    <span style="margin: 0 30px;">至</span>
                    <el-select v-model="form.maxAge" style="flex: 1;" placeholder="请选择">
                        <el-option
                            v-for="item in 60"
                            :key="item"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                </div>
            <el-form-item label="子方案名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入" v-trim/>
            </el-form-item>
            <el-form-item label="保险费用" prop="price">
                <div style="display: flex; align-items: center;">
                    <el-input v-model="form.price" style="flex: 1;" placeholder="请输入" v-trim/>
                    <span style="margin: 0 30px;">元/人</span>
                    <el-select v-model="form.timeUnit" style="flex: 1;" placeholder="请选择">
                    <el-select v-model="form.timeUnit" style="flex: 1;" placeholder="请选择周期单位" @change="changeTimeUnit">
                        <el-option label="天" :value="0"></el-option>
<!--                        <el-option label="半月" :value="1"></el-option>-->
                        <!--                        <el-option label="半月" :value="1"></el-option>-->
                        <el-option label="月" :value="2"></el-option>
                        <el-option label="年" :value="3"></el-option>
                        <el-option label="季度" :value="3"></el-option>
                        <el-option label="半年" :value="4"></el-option>
                        <el-option label="年" :value="5"></el-option>
                    </el-select>
                </div>
            </el-form-item>
            <el-form-item label="投保周期" prop="insureCycle">
            <el-form-item label="批改计费规则" prop="insureCycleUnit">
                <div style="display: flex; align-items: center;">
                    <el-input v-model="form.insureCycle" style="flex: 1;" placeholder="请输入" v-trim/>
                    <span style="margin: 0 30px;"></span>
                    <el-select v-model="form.insureCycleUnit" style="flex: 1;" placeholder="请选择">
                        <el-option label="天" :value="0"></el-option>
<!--                        <el-option label="半月" :value="1"></el-option>-->
                        <el-option label="月" :value="2"></el-option>
                        <el-option label="年" :value="3"></el-option>
                        <el-option  label="天" :value="0"></el-option>
                        <el-option v-if="form.timeUnit>=1"  label="半月" :value="1"></el-option>
                        <el-option v-if="form.timeUnit>=2"  label="月" :value="2"></el-option>
                        <el-option v-if="form.timeUnit>=3"  label="季度" :value="3"></el-option>
                        <el-option  v-if="form.timeUnit>=4"  label="半年" :value="4"></el-option>
                        <el-option v-if="form.timeUnit>=5" label="年" :value="5"></el-option>
                    </el-select>
                </div>
            </el-form-item>
            <el-form-item label="生效时间" prop="validTypeNum">
                <div style="width: 100%; display: flex; align-items: center;">
                    <div style="flex-shrink: 0;">
                        <el-radio-group v-model="form.validType" @change="form.validTypeNum = ''">
                            <el-radio :label="0">日后生效</el-radio>
                            <el-radio :label="1">次月生效</el-radio>
                        </el-radio-group>
                    </div>
                    <el-input style="margin-left: 20px;" type="number" v-model="form.validTypeNum" placeholder="请输入延迟天数" v-if="form.validType === 0"></el-input>
                </div>
            </el-form-item>
            <el-form-item label="投保类型" prop="type">
                <el-radio-group v-model="form.type">
                <el-radio-group v-model="form.type" :disabled="form.id!=null" @change="form.signType = ''">
                    <el-radio :label="0">直保</el-radio>
                    <el-radio :label="1">委托投保</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="委托商户" prop="shopId" :rules="form.type === 1 ? [{required:true,message:'请选择商户'}] : [{ required:false }]">
                <el-select v-model="form.shopId" filterable placeholder="请选择委托商户">
                    <el-option
                        v-for="item in shops"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="签章方式" prop="signType" v-if="form.type === 1">
                <el-select v-model="form.signType" placeholder="请选择委托商户">
                    <el-option label="商户签署商户上传投保单" :value="0"></el-option>
                    <el-option label="商户签投保申请" :value="1"></el-option>
                    <el-option label="商户无需签章" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="有派遣单位" prop="hasDispatchUnit">
                <el-radio-group v-model="form.hasDispatchUnit">
                    <el-radio :label="0">有</el-radio>
                    <el-radio :label="1">无</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="需要复核" prop="retrial">
                <el-radio-group v-model="form.retrial">
                    <el-radio :label="1">需要</el-radio>
                    <el-radio :label="0">不需要</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="上传方案确认书:" prop="fanganFile" :rules="[{required:true,message:'请上传方案确认书'}]">
                <div>
                    <UploadFile @remove="deleFile" :uploadData="{ folder: 'apply', fileType:'.pdf' }" :fileList="form.fileList1" @uploadSuccess="editFanganFile" />
                </div>
            </el-form-item>
            <el-form-item label="接收文件邮箱" prop="email">
                <el-input v-model="form.email" placeholder="请输入" v-trim/>
            </el-form-item>
            <el-form-item label="投保单签章关键字(如有多个关键字,请使用英文分号 ; 隔开)" prop="signKeyword">
                <el-input v-model="form.signKeyword" placeholder="多个英文分号 ; 隔开" v-trim/>
            </el-form-item>
            <el-button type="primary" @click="add">添加工种</el-button>
            <el-table
                :data="form.worktypeIdList"
                border
                style="width: 100%; margin-bottom: 20px;">
                <el-table-column
                    label="序号"
                    align="center"
                    width="80">
                    <template slot-scope="scope">
                        <span>{{scope.$index + 1}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    align="center"
                    label="所属工种">
                    <template slot-scope="{row}">
                        <el-select filterable v-model="row.worktypeId" placeholder="请选择">
                            <el-option
                                v-for="item in typeWork"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    align="center"
                    width="100">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" style="color: red;" @click="dele(scope.$index)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-form-item label="特别约定" prop="specialAgreement">
                <el-input type="textarea" v-model="form.specialAgreement" placeholder="请输入特别约定" v-trim/>
            </el-form-item>
            <el-form-item label="特别说明" prop="specialInfo">
                <el-input type="textarea" v-model="form.specialInfo" placeholder="请输入特别说明" v-trim/>
            </el-form-item>
            <el-form-item label="其他说明" prop="ortherInfo">
                <el-input type="textarea" v-model="form.ortherInfo" placeholder="请输入其他说明" v-trim/>
            </el-form-item>
        </el-form>
    </GlobalWindow>
</template>
<script>
    import BaseOpera from '@/components/base/BaseOpera'
    import GlobalWindow from '@/components/common/GlobalWindow'
    import { all } from '@/api/business/insurance'
    import { all as allWorktype } from '@/api/business/worktype'
    import { solutionsId } from '@/api/business/solutions'
    export default {
        name: 'OperaSolutionsWindow',
        extends: BaseOpera,
        components: { GlobalWindow },
        data () {
            var validType = (rule, value, callback) => {
                if (this.form.validType === 0 && !value) {
                    return callback(new Error('延迟天数不能为空'));
                } else if (!/^[0-9]*[1-9][0-9]*$/.test(value)) {
                    return callback(new Error('延迟天数只能为正整数'));
                }
                callback();
            }
            return {
                // 表单数据
                form: {
                    id: null,
                    name: '',
                    companyName: '',
                    insuranceId: '',
                    validType: 0,
                    type: 0,
                    minAge: '',
                    maxAge: '',
                    price: '',
                    timeUnit: '',
                    insureCycle: '',
                    insureCycleUnit: '',
                    email: '',
                    specialAgreement: '',
                    specialInfo: '',
                    ortherInfo: '',
                    signKeyword: '',
                    validTypeNum: '',
                    worktypeIdList: [{ worktypeId: '' }]
                },
                // 验证规则
                rules: {
                    name: [
                        { required: true, message: '请输入方案名称' }
                    ],
                    insuranceId: [
                        { required: true, message: '请选择保险公司' }
                    ],
                    companyName: [
                        { required: true, message: '请输入承保公司' }
                    ],
                    minAge: [
                        { required: true, message: '请选择投保年龄' }
                    ],
                    price: [
                        { required: true, message: '请输入保险费用' }
                    ],
                    insureCycle: [
                        { required: true, message: '请输入投保周期' }
                    ],
                    validTypeNum: [
                        { required: true, validator: validType }
                    ],
                    type: [
                        { required: true, message: '请选择投保类型' }
                    ],
                    signKeyword: [
                        { required: true, message: '请输入投保单签章关键字' }
                    ]
                },
                company: [],
                typeWork: []
            }
        },
        created () {
            this.config({
                api: '/business/solutions',
                'field.id': 'id'
            })
        },
        methods: {
            // 切换公司
            getAllWorktype1() {
                this.form.worktypeIdList = [{ worktypeId: '' }]
                this.getAllWorktype()
            },
            // 确认新建/修改
            confirm () {
                let data = JSON.parse(JSON.stringify(this.form))
                data.worktypeIdList = data.worktypeIdList.map(item => item.worktypeId)
                this.$refs.form.validate((valid) => {
                    if (!valid) {
                        return
                    }
                    // 调用新建接口
                    this.isWorking = true
                    if (data.id == null || data.id === '') {
                        this.api.create(data)
                            .then(() => {
                                this.visible = false
                                this.$tip.apiSuccess('新建成功')
                                this.$emit('success')
                            })
                            .catch(e => {
                                this.$tip.apiFailed(e)
                            })
                            .finally(() => {
                                this.isWorking = false
                            })
                    } else {
                        this.api.updateById(data)
                            .then(() => {
                                this.visible = false
                                this.$tip.apiSuccess('修改成功')
                                this.$emit('success')
                            })
                            .catch(e => {
                                this.$tip.apiFailed(e)
                            })
                            .finally(() => {
                                this.isWorking = false
                            })
                    }
                })
            },
            open (title, target) {
                this.title = title
                this.form.maxAge = ''
                this.form.timeUnit = ''
                this.form.insureCycleUnit = ''
                this.form.validTypeNum = ''
                this.visible = true
                this.form.worktypeIdList = [{ worktypeId: '' }]
                this.allCompany()
                // 新建
                if (target == null) {
                    this.$nextTick(() => {
                        this.$refs.form.resetFields()
                        this.form[this.configData['field.id']] = null
                    })
                    return
                }
                // 编辑
                this.$nextTick(() => {
                    solutionsId(target.id)
                        .then(res => {
                            for (const key in this.form) {
                                this.form[key] = res[key]
                            }
                            this.form.worktypeIdList = res.worktypeList.map(item => {
                                return {
                                    worktypeId: item.worktypeId
                                }
                            })
                            this.getAllWorktype()
                        })
                })
            },
            // 查询保险公司下全部工种
            getAllWorktype() {
                allWorktype({
                    insuranceId: this.form.insuranceId
                }).then(res => {
                    this.typeWork = res
                })
            },
            // 查询全部保险公司
            allCompany() {
                all({ dataType: 2, status: 0 })
                    .then(res => {
                        console.log(res)
                        this.company = res
                    })
            },
            add() {
                this.form.worktypeIdList.push({ worktypeId: '' })
            },
            dele(index) {
                if (this.form.worktypeIdList.length === 1) {
                    this.$message.warning('至少要保留一项')
                    return
                }
                this.form.worktypeIdList.splice(index, 1)
            }
        }
  import BaseOpera from '@/components/base/BaseOpera'
  import GlobalWindow from '@/components/common/GlobalWindow'
  import { all } from '@/api/business/insurance'
  import { solutionsId } from '@/api/business/solutions'
  import { list } from '@/api/business/solutionsBase'
  import { pageAll as shopList } from '@/api/business/company'
  import UploadFile from '@/components/common/UploadFile'
  import RichEditor from '@/components/common/RichEditor'
  export default {
  name: 'OperaSolutionsWindow',
  extends: BaseOpera,
  components: { GlobalWindow, UploadFile, RichEditor },
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        name: '',
        parentId: '',
        signType: '',
        type: 0,
        price: '',
        timeUnit: '',
        shopId: null,
        retrial: 0,
        hasDispatchUnit: 0,
        insureCycleUnit: '',
        email: '',
        fileList1: [],
        fanganFile: null
      },
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入方案名称' }
        ],
        parentId: [
          { required: true, message: '请选择主方案' }
        ],
        signType: [
          { required: true, message: '请选择签章方式' }
        ],
        price: [
          { required: true, message: '请输入方案费用' }
        ],
        insureCycleUnit: [
          { required: true, message: '请输入批改计费单位' }
        ],
        type: [
          { required: true, message: '请选择投保类型' }
        ]
      },
      list: [],
      shops: [],
      company: []
    }
  },
  created () {
    this.config({
      api: '/business/solutions',
      'field.id': 'id'
    })
  },
  methods: {
    changeParent(e) {
      let name = this.list.filter(item => {
        if (e === item.id) {
          return item.name
        }
      })
      this.form.name = name[0].name
    },
    async getList() {
      this.list = await list({})
    },
    changeTimeUnit () {
      if (this.form.timeUnit < this.form.insureCycleUnit) {
        this.form.insureCycleUnit = null
      }
    },
    editFanganFile (data) {
      this.form.fanganFile = data
    },
    // 确认新建/修改
    confirm () {
      const data = JSON.parse(JSON.stringify(this.form))
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        if (data.type === 1 && (!data.fanganFile || !data.fanganFile.fileurl)) {
          this.$message.error('请上传方案确认书!')
          return
        }
        // 调用新建接口
        this.isWorking = true
        if (data.id == null || data.id === '') {
          this.api.create(data)
            .then(() => {
              this.visible = false
              this.$tip.apiSuccess('新建成功')
              this.$emit('success')
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
        } else {
          this.api.updateById(data)
            .then(() => {
              this.visible = false
              this.$tip.apiSuccess('修改成功')
              this.$emit('success')
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
        }
      })
    },
    deleFile () {
      this.form.fanganFile = {}
    },
    open (title, target) {
      this.title = title
      this.visible = true
      this.form.timeUnit = ''
      this.form.insureCycleUnit = ''
      this.form.fanganFile = null
      this.form.fileList1 = []
      this.allCompany()
      this.allShops()
      this.getList()
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form.timeUnit = ''
          this.form.insureCycleUnit = ''
          this.form.fanganFile = null
          this.form.fileList1 = []
          this.form[this.configData['field.id']] = null
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        solutionsId(target.id)
          .then(res => {
            for (const key in this.form) {
              this.form[key] = res[key]
            }
            if (this.form.fanganFile && this.form.fanganFile.fileurl) {
              this.form.fileList1 = [{ url: this.form.fanganFile.fileurlFull, name: this.form.fanganFile.name }]
            }
          })
      })
    },
    // 查询全部保险公司
    allCompany () {
      all({ dataType: 2, status: 0 })
        .then(res => {
          this.company = res
        })
    },
    allShops () {
      shopList({ type: 1, status: 0 })
        .then(res => {
          this.shops = res
        })
    }
  }
}
</script>