add.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-01-12 11:57:48
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-01-30 16:43:05
  6. * @Description: file content
  7. * @FilePath: \crm\pages\customer\add.vue
  8. -->
  9. <template>
  10. <view class="home">
  11. <view class="nav">
  12. <view :style="{ paddingTop }">
  13. <view class="title" :style="[{ height }, { lineHeight: height }]">
  14. <view class="back" @click="goBack()">
  15. <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
  16. </view>
  17. <text>新增客户</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="main">
  22. <u-form :model="addForm" :rules="rules" ref="addForm" label-width="0">
  23. <u-form-item prop="custName" borderBottom customStyle="padding:40rpx 0 30rpx">
  24. <view class="form-label flex_l">
  25. <view class="label-tag"></view>
  26. 客户名称
  27. </view>
  28. <u-input
  29. placeholder="输入客户名称"
  30. v-model="addForm.custName"
  31. border="none"
  32. suffixIcon="account"
  33. suffixIconStyle="color:#CDCDCD"
  34. clearable
  35. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  36. </u-form-item>
  37. <u-form-item prop="industry" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showIndustry = true">
  38. <view class="form-label flex_l">
  39. <view class="label-tag"></view>
  40. 客户行业
  41. </view>
  42. <u-input
  43. :readonly="true"
  44. placeholder="请选择客户行业"
  45. v-model="addForm.industry"
  46. border="none"
  47. suffixIcon="arrow-down"
  48. suffixIconStyle="color:#CDCDCD"
  49. clearable
  50. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  51. </u-form-item>
  52. <!-- <u-form-item prop="level" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showLevel = true">
  53. <view class="form-label flex_l">
  54. <view class="label-tag"></view>
  55. 客户级别
  56. </view>
  57. <u-input
  58. :readonly="true"
  59. placeholder="请选择客户级别"
  60. v-model="addForm.level"
  61. border="none"
  62. suffixIcon="arrow-down"
  63. suffixIconStyle="color:#CDCDCD"
  64. clearable
  65. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  66. </u-form-item> -->
  67. <u-form-item prop="custSource" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showSource = true">
  68. <view class="form-label flex_l">
  69. <view class="label-tag"></view>
  70. 客户来源
  71. </view>
  72. <u-input
  73. :readonly="true"
  74. placeholder="请选择客户来源"
  75. v-model="addForm.custSource"
  76. border="none"
  77. suffixIcon="arrow-down"
  78. suffixIconStyle="color:#CDCDCD"
  79. clearable
  80. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  81. </u-form-item>
  82. <u-form-item prop="area" borderBottom customStyle="padding:40rpx 0 30rpx" @click="showArea = true">
  83. <view class="form-label flex_l">
  84. <view class="label-tag"></view>
  85. 所在地区
  86. </view>
  87. <u-input
  88. :readonly="true"
  89. placeholder="请选择所在地区"
  90. v-model="addForm.area"
  91. border="none"
  92. suffixIcon="arrow-down"
  93. suffixIconStyle="color:#CDCDCD"
  94. clearable
  95. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  96. </u-form-item>
  97. <u-form-item borderBottom customStyle="padding:40rpx 0 30rpx">
  98. <view class="form-label flex_l">备注</view>
  99. <u-input
  100. placeholder="输入备注"
  101. v-model="addForm.remark"
  102. border="none"
  103. clearable
  104. customStyle="padding: 0 30rpx 0 12rpx"></u-input>
  105. </u-form-item>
  106. </u-form>
  107. <view class="save" @click="handleAdd" :class="!flag ? 'disabledBtn' : ''">保存</view>
  108. </view>
  109. <!-- 选择客户行业 -->
  110. <u-picker
  111. :show="showIndustry"
  112. :columns="industryColumns"
  113. keyName="value"
  114. @cancel="showIndustry = false"
  115. @confirm="pickIndustry"></u-picker>
  116. <!-- 选择客户级别 -->
  117. <!-- <u-picker
  118. :show="showLevel"
  119. :columns="levelColumns"
  120. keyName="value"
  121. @cancel="showLevel = false"
  122. @confirm="pickLevel"></u-picker> -->
  123. <!-- 选择客户来源 -->
  124. <u-picker
  125. :show="showSource"
  126. :columns="sourceColumns"
  127. keyName="value"
  128. @cancel="showSource = false"
  129. @confirm="pickSource"></u-picker>
  130. <!-- 选择地区 -->
  131. <u-picker
  132. :show="showArea"
  133. @cancel="showArea = false"
  134. @close="showArea = false"
  135. :columns="addressColumns"
  136. @confirm="localConfirm"
  137. title="请选择所在地"
  138. keyName="distName"
  139. itemHeight="80"
  140. closeOnClickOverlay
  141. ref="areaPicker"
  142. @change="changeHandler"
  143. immediateChange></u-picker>
  144. <u-notify ref="uNotify"></u-notify>
  145. <u-toast ref="uToast"></u-toast>
  146. </view>
  147. </template>
  148. <script>
  149. import distrApi from '../../api/base/distr'
  150. import customerApi from '../../api/customer'
  151. import to from 'await-to-js'
  152. export default {
  153. name: 'omsIndex',
  154. data() {
  155. return {
  156. flag: true,
  157. height: '',
  158. paddingTop: '',
  159. showIndustry: false, //选择行业
  160. // showLevel: false, //选择级别
  161. showSource: false, //选择来源
  162. showArea: false, //选择地区
  163. industryColumns: [],
  164. // levelColumns: [],
  165. sourceColumns: [],
  166. areaLoading: false,
  167. areaColumns: [], //省份数据
  168. addressColumns: [], //数据数组
  169. addForm: {
  170. custName: '', //客户姓名
  171. industry: '', //行业
  172. industryId: null,
  173. // level: '', //级别
  174. // levelId: null,
  175. custSource: '', //来源
  176. custSourceId: null,
  177. area: '',
  178. CustProvinceId: null, //省
  179. CustProvince: '',
  180. CustCityId: null, //市
  181. CustCity: '',
  182. CustRegionId: null, //区、县
  183. CustRegion: '',
  184. remark: '', //备注
  185. },
  186. rules: {
  187. custName: {
  188. type: 'string',
  189. required: true,
  190. message: '请填写客户名称',
  191. trigger: ['blur'],
  192. },
  193. industry: {
  194. type: 'string',
  195. required: true,
  196. message: '请选择客户行业',
  197. trigger: ['blur', 'change'],
  198. },
  199. // level: {
  200. // type: 'string',
  201. // required: true,
  202. // message: '请选择客户级别',
  203. // trigger: ['blur', 'change'],
  204. // },
  205. custSource: {
  206. type: 'string',
  207. required: true,
  208. message: '请选择客户来源',
  209. trigger: ['blur', 'change'],
  210. },
  211. area: {
  212. type: 'string',
  213. required: true,
  214. message: '请选择所在地区',
  215. trigger: ['blur', 'change'],
  216. },
  217. },
  218. }
  219. },
  220. created() {
  221. const navData = uni.getMenuButtonBoundingClientRect()
  222. this.height = navData.height + 'px'
  223. this.paddingTop = navData.top + 'px'
  224. },
  225. onShow() {
  226. this.getOptions()
  227. },
  228. methods: {
  229. // 获取字典数据
  230. getOptions() {
  231. Promise.all([
  232. distrApi.getProvinceInfo(), //省市区
  233. // this.getDicts('cust_level'), //级别
  234. this.getDicts('cust_idy'), //行业
  235. this.getDicts('cust_source'), //来源
  236. ])
  237. .then(([province, industry, source]) => {
  238. this.areaColumns = province.data.list || []
  239. // this.levelColumns = [level.data.values] || []
  240. this.industryColumns = [industry.data.values] || []
  241. this.sourceColumns = [source.data.values] || []
  242. this.initAreaData()
  243. })
  244. .catch((err) => console.log(err))
  245. },
  246. // 行业选择
  247. pickIndustry(e) {
  248. this.addForm.industryId = e.value[0].key
  249. this.addForm.industry = e.value[0].value
  250. this.showIndustry = false
  251. },
  252. // 级别选择
  253. // pickLevel(e) {
  254. // this.addForm.levelId = e.value[0].key
  255. // this.addForm.level = e.value[0].value
  256. // this.showLevel = false
  257. // },
  258. // 来源选择
  259. pickSource(e) {
  260. this.addForm.custSourceId = e.value[0].key
  261. this.addForm.custSource = e.value[0].value
  262. this.showSource = false
  263. },
  264. // 初始化地区
  265. initAreaData() {
  266. let sheng = []
  267. let shi = []
  268. let qu = []
  269. this.areaColumns.forEach((item) => {
  270. sheng.push({
  271. distName: item.distName,
  272. id: item.id,
  273. })
  274. // 设置初始化的数据
  275. if (item.distName == '北京市') {
  276. item.children.forEach((child) => {
  277. shi.push({
  278. distName: child.distName,
  279. id: child.id,
  280. })
  281. if (child.distName == '北京市') {
  282. child.children.forEach((el) => {
  283. qu.push({
  284. distName: el.distName,
  285. id: el.id,
  286. })
  287. })
  288. }
  289. })
  290. }
  291. })
  292. this.addressColumns.push(
  293. JSON.parse(JSON.stringify(sheng)),
  294. JSON.parse(JSON.stringify(shi)),
  295. JSON.parse(JSON.stringify(qu))
  296. )
  297. },
  298. // 选择地区的时候
  299. changeHandler(e) {
  300. const {
  301. columnIndex,
  302. value,
  303. values, // values为当前变化列的数组内容
  304. index,
  305. // 微信小程序无法将picker实例传出来,只能通过ref操作
  306. picker = this.$refs.areaPicker,
  307. } = e
  308. // 当第一列值发生变化时,变化第二列(后一列)对应的选项
  309. if (columnIndex === 0) {
  310. // picker为选择器this实例,变化第二列对应的选项
  311. this.areaColumns.forEach((item) => {
  312. if (value[0].distName == item.distName) {
  313. if (item.children) {
  314. let shi = []
  315. let flag = item.children[0].distName
  316. item.children.forEach((val, ol) => {
  317. shi.push({
  318. distName: val.distName,
  319. id: val.id,
  320. })
  321. if (shi[0].distName == flag) {
  322. //设置默认开关(选择省份后设置默认城市)
  323. flag = ''
  324. let qu = []
  325. val.children.forEach((vol) => {
  326. qu.push({
  327. distName: vol.distName,
  328. id: vol.id,
  329. })
  330. })
  331. picker.setColumnValues(2, qu)
  332. }
  333. })
  334. picker.setColumnValues(1, shi)
  335. } else {
  336. picker.setColumnValues(1, [])
  337. picker.setColumnValues(2, [])
  338. }
  339. }
  340. })
  341. }
  342. //当第二列变化时,第三列对应变化
  343. if (columnIndex === 1) {
  344. this.areaColumns.forEach((item) => {
  345. if (value[0].distName == item.distName) {
  346. let shi = []
  347. item.children.forEach((val, ol) => {
  348. shi.push({
  349. distName: val.distName,
  350. id: val.id,
  351. })
  352. if (value[1].distName == val.distName) {
  353. let qu = []
  354. val.children.forEach((vol) => {
  355. qu.push({
  356. distName: vol.distName,
  357. id: vol.id,
  358. })
  359. })
  360. picker.setColumnValues(2, qu)
  361. }
  362. })
  363. }
  364. })
  365. }
  366. },
  367. // 确认选中的数据
  368. localConfirm(e) {
  369. if (e.value[1]) {
  370. this.addForm.CustProvinceId = e.value[0].id
  371. this.addForm.CustProvince = e.value[0].distName
  372. this.addForm.CustCityId = e.value[1].id
  373. this.addForm.CustCity = e.value[1].distName
  374. this.addForm.CustRegionId = e.value[2].id
  375. this.addForm.CustRegion = e.value[2].distName
  376. this.addForm.area = e.value[0].distName + e.value[1].distName + e.value[2].distName
  377. }
  378. this.showArea = false
  379. },
  380. handleAdd() {
  381. if (!this.flag) return
  382. this.$refs.addForm
  383. .validate()
  384. .then(async () => {
  385. let params = {
  386. custName: this.addForm.custName,
  387. custIndustry: this.addForm.industryId,
  388. custSource: this.addForm.custSourceId,
  389. CustProvinceId: this.addForm.CustProvinceId,
  390. CustProvince: this.addForm.CustProvince,
  391. CustCityId: this.addForm.CustCityId,
  392. CustCity: this.addForm.CustCity,
  393. CustRegionId: this.addForm.CustRegionId,
  394. CustRegion: this.addForm.CustRegion,
  395. remark: this.addForm.remark,
  396. }
  397. this.flag = false
  398. const [err, res] = await to(customerApi.createCustomer(params))
  399. this.flag = true
  400. if (err) return
  401. if (res && res.code == 200) {
  402. this.$refs.uToast.show({
  403. type: 'success',
  404. message: '创建成功',
  405. complete: () => {
  406. this.goBack()
  407. },
  408. })
  409. }
  410. })
  411. .catch((err) => {
  412. this.$refs.uNotify.show({
  413. top: this.height + this.paddingTop + 10,
  414. type: 'warning',
  415. message: err[0].message,
  416. duration: 1000 * 3,
  417. })
  418. })
  419. },
  420. goBack() {
  421. uni.navigateBack({
  422. //关闭当前页面,返回上一页面或多级页面。
  423. delta: 1,
  424. })
  425. },
  426. },
  427. }
  428. </script>
  429. <style>
  430. page {
  431. background: #f2f3f5;
  432. }
  433. </style>
  434. <style lang="scss" scoped>
  435. .home {
  436. padding-top: 188rpx;
  437. .nav {
  438. position: absolute;
  439. left: 0;
  440. top: 0;
  441. width: 100%;
  442. height: 284rpx;
  443. background: #3e7ef8;
  444. .title {
  445. position: relative;
  446. text-align: center;
  447. font-size: 32rpx;
  448. font-weight: bold;
  449. color: #ffffff;
  450. .back {
  451. position: absolute;
  452. top: 0;
  453. bottom: 0;
  454. margin: auto;
  455. left: 70rpx;
  456. display: flex;
  457. }
  458. }
  459. }
  460. .main {
  461. position: absolute;
  462. width: 100%;
  463. height: calc(100vh - 188rpx);
  464. background: #ffffff;
  465. box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
  466. border-radius: 31rpx 31rpx 0 0;
  467. padding: 0 32rpx;
  468. overflow: auto;
  469. padding-bottom: 64rpx;
  470. .form-label {
  471. font-size: 32rpx;
  472. font-weight: bold;
  473. color: #323232;
  474. padding-bottom: 18rpx;
  475. .label-tag {
  476. width: 15rpx;
  477. height: 15rpx;
  478. background: #ff4d4f;
  479. border-radius: 50%;
  480. margin-right: 10rpx;
  481. }
  482. }
  483. .save {
  484. width: 569rpx;
  485. height: 92rpx;
  486. background: #3e7ef8;
  487. border-radius: 31rpx;
  488. margin: 116rpx auto 0;
  489. font-size: 32rpx;
  490. color: #ffffff;
  491. text-align: center;
  492. line-height: 92rpx;
  493. }
  494. }
  495. }
  496. </style>