| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- <!--
- * @Author: liuzhenlin 461480418@qq.ocm
- * @Date: 2023-01-12 11:57:48
- * @LastEditors: liuzhenlin
- * @LastEditTime: 2023-01-30 16:43:05
- * @Description: file content
- * @FilePath: \crm\pages\customer\add.vue
- -->
- <template>
- <view class="home">
- <view class="nav">
- <view :style="{ paddingTop }">
- <view class="title" :style="[{ height }, { lineHeight: height }]">
- <view class="back" @click="goBack()">
- <u-icon custName="arrow-left" color="#ffffff" size="22"></u-icon>
- </view>
- <text>新增客户</text>
- </view>
- </view>
- </view>
- <view class="main">
- <u-form :model="addForm" :rules="rules" ref="addForm" label-width="0">
- <u-form-item prop="custName" borderBottom customStyle="padding:40rpx 0 30rpx">
- <view class="form-label flex_l">
- <view class="label-tag"></view>
- 客户名称
- </view>
- <u-input placeholder="输入客户名称" v-model="addForm.custName" border="none" suffixIcon="account"
- suffixIconStyle="color:#CDCDCD" clearable customStyle="padding: 0 30rpx 0 12rpx"></u-input>
- </u-form-item>
- <u-form-item prop="industry" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showIndustry = true">
- <view class="form-label flex_l">
- <view class="label-tag"></view>
- 客户行业
- </view>
- <u-input :readonly="true" placeholder="请选择客户行业" v-model="addForm.industry" border="none"
- suffixIcon="arrow-down" suffixIconStyle="color:#CDCDCD" clearable customStyle="padding: 0 30rpx 0 12rpx">
- </u-input>
- </u-form-item>
- <!-- <u-form-item prop="level" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showLevel = true">
- <view class="form-label flex_l">
- <view class="label-tag"></view>
- 客户级别
- </view>
- <u-input
- :readonly="true"
- placeholder="请选择客户级别"
- v-model="addForm.level"
- border="none"
- suffixIcon="arrow-down"
- suffixIconStyle="color:#CDCDCD"
- clearable
- customStyle="padding: 0 30rpx 0 12rpx"></u-input>
- </u-form-item> -->
- <u-form-item prop="custSource" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showSource = true">
- <view class="form-label flex_l">
- <view class="label-tag"></view>
- 客户来源
- </view>
- <u-input :readonly="true" placeholder="请选择客户来源" v-model="addForm.custSource" border="none"
- suffixIcon="arrow-down" suffixIconStyle="color:#CDCDCD" clearable customStyle="padding: 0 30rpx 0 12rpx">
- </u-input>
- </u-form-item>
- <u-form-item prop="area" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showArea = true">
- <view class="form-label flex_l">
- <view class="label-tag"></view>
- 所在地区
- </view>
- <u-input :readonly="true" placeholder="请选择所在地区" v-model="addForm.area" border="none" suffixIcon="arrow-down"
- suffixIconStyle="color:#CDCDCD" clearable customStyle="padding: 0 30rpx 0 12rpx"></u-input>
- </u-form-item>
- <u-form-item borderBottom customStyle="padding:40rpx 0 30rpx">
- <view class="form-label flex_l">
- 备注
- </view>
- <u-input placeholder="输入备注" v-model="addForm.remark" border="none" clearable
- customStyle="padding: 0 30rpx 0 12rpx"></u-input>
- </u-form-item>
- </u-form>
- <view class="save" @click="handleAdd">保存</view>
- </view>
- <!-- 选择客户行业 -->
- <u-picker :show="showIndustry" :columns="industryColumns" keyName="value" @cancel="showIndustry = false"
- @confirm="pickIndustry"></u-picker>
- <!-- 选择客户级别 -->
- <!-- <u-picker
- :show="showLevel"
- :columns="levelColumns"
- keyName="value"
- @cancel="showLevel = false"
- @confirm="pickLevel"></u-picker> -->
- <!-- 选择客户来源 -->
- <u-picker :show="showSource" :columns="sourceColumns" keyName="value" @cancel="showSource = false"
- @confirm="pickSource"></u-picker>
- <!-- 选择地区 -->
- <u-picker :show="showArea" @cancel="showArea = false" @close="showArea = false" :columns="addressColumns"
- @confirm="localConfirm" title="请选择所在地" keyName="distName" itemHeight="80" closeOnClickOverlay ref="areaPicker"
- @change="changeHandler" immediateChange></u-picker>
- <u-notify ref="uNotify"></u-notify>
- <u-toast ref="uToast"></u-toast>
- </view>
- </template>
- <script>
- import distrApi from '../../api/base/distr'
- import customerApi from '../../api/customer'
- import to from 'await-to-js'
- export default {
- name: 'omsIndex',
- data() {
- return {
- height: '',
- paddingTop: '',
- showIndustry: false, //选择行业
- // showLevel: false, //选择级别
- showSource: false, //选择来源
- showArea: false, //选择地区
- industryColumns: [],
- // levelColumns: [],
- sourceColumns: [],
- areaLoading: false,
- areaColumns: [], //省份数据
- addressColumns: [], //数据数组
- addForm: {
- custName: '', //客户姓名
- industry: '', //行业
- industryId: null,
- // level: '', //级别
- // levelId: null,
- custSource: '', //来源
- custSourceId: null,
- area: "",
- CustProvinceId: null, //省
- CustProvince: '',
- CustCityId: null, //市
- CustCity: '',
- CustRegionId: null, //区、县
- CustRegion: '',
- remark: '', //备注
- },
- rules: {
- custName: {
- type: 'string',
- required: true,
- message: '请填写客户名称',
- trigger: ['blur'],
- },
- industry: {
- type: 'string',
- required: true,
- message: '请选择客户行业',
- trigger: ['blur', 'change'],
- },
- // level: {
- // type: 'string',
- // required: true,
- // message: '请选择客户级别',
- // trigger: ['blur', 'change'],
- // },
- custSource: {
- type: 'string',
- required: true,
- message: '请选择客户来源',
- trigger: ['blur', 'change'],
- },
- area: {
- type: 'string',
- required: true,
- message: '请选择所在地区',
- trigger: ['blur', 'change'],
- },
- },
- }
- },
- created() {
- const navData = uni.getMenuButtonBoundingClientRect()
- this.height = navData.height + 'px'
- this.paddingTop = navData.top + 'px'
- },
- onShow() {
- this.getOptions()
- },
- methods: {
- // 获取字典数据
- getOptions() {
- Promise.all([
- distrApi.getProvinceInfo(), //省市区
- // this.getDicts('cust_level'), //级别
- this.getDicts('cust_idy'), //行业
- this.getDicts('cust_source'), //来源
- ])
- .then(([province, industry, source]) => {
- this.areaColumns = province.data.list || []
- // this.levelColumns = [level.data.values] || []
- this.industryColumns = [industry.data.values] || []
- this.sourceColumns = [source.data.values] || []
- this.initAreaData()
- })
- .catch((err) => console.log(err))
- },
- // 行业选择
- pickIndustry(e) {
- this.addForm.industryId = e.value[0].key
- this.addForm.industry = e.value[0].value
- this.showIndustry = false
- },
- // 级别选择
- // pickLevel(e) {
- // this.addForm.levelId = e.value[0].key
- // this.addForm.level = e.value[0].value
- // this.showLevel = false
- // },
- // 来源选择
- pickSource(e) {
- this.addForm.custSourceId = e.value[0].key
- this.addForm.custSource = e.value[0].value
- this.showSource = false
- },
- // 初始化地区
- initAreaData() {
- let sheng = []
- let shi = []
- let qu = []
- this.areaColumns.forEach((item) => {
- sheng.push({
- distName: item.distName,
- id: item.id
- })
- // 设置初始化的数据
- if (item.distName == '北京市') {
- item.children.forEach((child) => {
- shi.push({
- distName: child.distName,
- id: child.id
- })
- if (child.distName == '北京市') {
- child.children.forEach((el) => {
- qu.push({
- distName: el.distName,
- id: el.id
- })
- })
- }
- })
- }
- })
- this.addressColumns.push(
- JSON.parse(JSON.stringify(sheng)),
- JSON.parse(JSON.stringify(shi)),
- JSON.parse(JSON.stringify(qu))
- )
- },
- // 选择地区的时候
- changeHandler(e) {
- const {
- columnIndex,
- value,
- values, // values为当前变化列的数组内容
- index,
- // 微信小程序无法将picker实例传出来,只能通过ref操作
- picker = this.$refs.areaPicker,
- } = e
- // 当第一列值发生变化时,变化第二列(后一列)对应的选项
- if (columnIndex === 0) {
- // picker为选择器this实例,变化第二列对应的选项
- this.areaColumns.forEach((item) => {
- if (value[0].distName == item.distName) {
- if (item.children) {
- let shi = []
- let flag = item.children[0].distName
- item.children.forEach((val, ol) => {
- shi.push({
- distName: val.distName,
- id: val.id
- })
- if (shi[0].distName == flag) {
- //设置默认开关(选择省份后设置默认城市)
- flag = ''
- let qu = []
- val.children.forEach((vol) => {
- qu.push({
- distName: vol.distName,
- id: vol.id
- })
- })
- picker.setColumnValues(2, qu)
- }
- })
- picker.setColumnValues(1, shi)
- } else {
- picker.setColumnValues(1, [])
- picker.setColumnValues(2, [])
- }
- }
- })
- }
- //当第二列变化时,第三列对应变化
- if (columnIndex === 1) {
- this.areaColumns.forEach((item) => {
- if (value[0].distName == item.distName) {
- let shi = []
- item.children.forEach((val, ol) => {
- shi.push({
- distName: val.distName,
- id: val.id
- })
- if (value[1].distName == val.distName) {
- let qu = []
- val.children.forEach((vol) => {
- qu.push({
- distName: vol.distName,
- id: vol.id
- })
- })
- picker.setColumnValues(2, qu)
- }
- })
- }
- })
- }
- },
- // 确认选中的数据
- localConfirm(e) {
- if (e.value[1]) {
- this.addForm.CustProvinceId = e.value[0].id
- this.addForm.CustProvince = e.value[0].distName
- this.addForm.CustCityId = e.value[1].id
- this.addForm.CustCity = e.value[1].distName
- this.addForm.CustRegionId = e.value[2].id
- this.addForm.CustRegion = e.value[2].distName
- this.addForm.area = e.value[0].distName + e.value[1].distName + e.value[2].distName
- }
- this.showArea = false
- },
- handleAdd() {
- this.$refs.addForm
- .validate()
- .then(async () => {
- let params = {
- custName: this.addForm.custName,
- custIndustry: this.addForm.industryId,
- custSource: this.addForm.custSourceId,
- CustProvinceId: this.addForm.CustProvinceId,
- CustProvince: this.addForm.CustProvince,
- CustCityId: this.addForm.CustCityId,
- CustCity: this.addForm.CustCity,
- CustRegionId: this.addForm.CustRegionId,
- CustRegion: this.addForm.CustRegion,
- remark: this.addForm.remark,
- }
- const [err, res] = await to(customerApi.createCustomer(params))
- if (err) return
- if (res && res.code == 200) {
- this.$refs.uToast.show({
- type: 'success',
- message: '创建成功',
- complete: () => {
- this.goBack()
- },
- })
- }
- })
- .catch((err) => {
- this.$refs.uNotify.show({
- top: this.height + this.paddingTop + 10,
- type: 'warning',
- message: err[0].message,
- duration: 1000 * 3,
- })
- })
- },
- goBack() {
- uni.navigateBack({
- //关闭当前页面,返回上一页面或多级页面。
- delta: 1,
- })
- },
- },
- }
- </script>
- <style>
- page {
- background: #f2f3f5;
- }
- </style>
- <style lang="scss" scoped>
- .home {
- padding-top: 188rpx;
- .nav {
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 284rpx;
- background: #3e7ef8;
- .title {
- position: relative;
- text-align: center;
- font-size: 32rpx;
- font-weight: bold;
- color: #ffffff;
- .back {
- position: absolute;
- top: 0;
- bottom: 0;
- margin: auto;
- left: 70rpx;
- display: flex;
- }
- }
- }
- .main {
- position: absolute;
- width: 100%;
- height: calc(100vh - 188rpx);
- background: #ffffff;
- box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
- border-radius: 31rpx 31rpx 0 0;
- padding: 0 32rpx;
- overflow: auto;
- padding-bottom: 64rpx;
- .form-label {
- font-size: 32rpx;
- font-weight: bold;
- color: #323232;
- padding-bottom: 18rpx;
- .label-tag {
- width: 15rpx;
- height: 15rpx;
- background: #ff4d4f;
- border-radius: 50%;
- margin-right: 10rpx;
- }
- }
- .save {
- width: 569rpx;
- height: 92rpx;
- background: #3e7ef8;
- border-radius: 31rpx;
- margin: 116rpx auto 0;
- font-size: 32rpx;
- color: #ffffff;
- text-align: center;
- line-height: 92rpx;
- }
- }
- }
- </style>
|