add.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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">保存</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. height: '',
  157. paddingTop: '',
  158. showIndustry: false, //选择行业
  159. // showLevel: false, //选择级别
  160. showSource: false, //选择来源
  161. showArea: false, //选择地区
  162. industryColumns: [],
  163. // levelColumns: [],
  164. sourceColumns: [],
  165. areaLoading: false,
  166. areaColumns: [], //省份数据
  167. addressColumns: [], //数据数组
  168. addForm: {
  169. custName: '', //客户姓名
  170. industry: '', //行业
  171. industryId: null,
  172. // level: '', //级别
  173. // levelId: null,
  174. custSource: '', //来源
  175. custSourceId: null,
  176. area: '',
  177. CustProvinceId: null, //省
  178. CustProvince: '',
  179. CustCityId: null, //市
  180. CustCity: '',
  181. CustRegionId: null, //区、县
  182. CustRegion: '',
  183. remark: '', //备注
  184. },
  185. rules: {
  186. custName: {
  187. type: 'string',
  188. required: true,
  189. message: '请填写客户名称',
  190. trigger: ['blur'],
  191. },
  192. industry: {
  193. type: 'string',
  194. required: true,
  195. message: '请选择客户行业',
  196. trigger: ['blur', 'change'],
  197. },
  198. // level: {
  199. // type: 'string',
  200. // required: true,
  201. // message: '请选择客户级别',
  202. // trigger: ['blur', 'change'],
  203. // },
  204. custSource: {
  205. type: 'string',
  206. required: true,
  207. message: '请选择客户来源',
  208. trigger: ['blur', 'change'],
  209. },
  210. area: {
  211. type: 'string',
  212. required: true,
  213. message: '请选择所在地区',
  214. trigger: ['blur', 'change'],
  215. },
  216. },
  217. }
  218. },
  219. created() {
  220. const navData = uni.getMenuButtonBoundingClientRect()
  221. this.height = navData.height + 'px'
  222. this.paddingTop = navData.top + 'px'
  223. },
  224. onShow() {
  225. this.getOptions()
  226. },
  227. methods: {
  228. // 获取字典数据
  229. getOptions() {
  230. Promise.all([
  231. distrApi.getProvinceInfo(), //省市区
  232. // this.getDicts('cust_level'), //级别
  233. this.getDicts('cust_idy'), //行业
  234. this.getDicts('cust_source'), //来源
  235. ])
  236. .then(([province, industry, source]) => {
  237. this.areaColumns = province.data.list || []
  238. // this.levelColumns = [level.data.values] || []
  239. this.industryColumns = [industry.data.values] || []
  240. this.sourceColumns = [source.data.values] || []
  241. this.initAreaData()
  242. })
  243. .catch((err) => console.log(err))
  244. },
  245. // 行业选择
  246. pickIndustry(e) {
  247. this.addForm.industryId = e.value[0].key
  248. this.addForm.industry = e.value[0].value
  249. this.showIndustry = false
  250. },
  251. // 级别选择
  252. // pickLevel(e) {
  253. // this.addForm.levelId = e.value[0].key
  254. // this.addForm.level = e.value[0].value
  255. // this.showLevel = false
  256. // },
  257. // 来源选择
  258. pickSource(e) {
  259. this.addForm.custSourceId = e.value[0].key
  260. this.addForm.custSource = e.value[0].value
  261. this.showSource = false
  262. },
  263. // 初始化地区
  264. initAreaData() {
  265. let sheng = []
  266. let shi = []
  267. let qu = []
  268. this.areaColumns.forEach((item) => {
  269. sheng.push({
  270. distName: item.distName,
  271. id: item.id,
  272. })
  273. // 设置初始化的数据
  274. if (item.distName == '北京市') {
  275. item.children.forEach((child) => {
  276. shi.push({
  277. distName: child.distName,
  278. id: child.id,
  279. })
  280. if (child.distName == '北京市') {
  281. child.children.forEach((el) => {
  282. qu.push({
  283. distName: el.distName,
  284. id: el.id,
  285. })
  286. })
  287. }
  288. })
  289. }
  290. })
  291. this.addressColumns.push(
  292. JSON.parse(JSON.stringify(sheng)),
  293. JSON.parse(JSON.stringify(shi)),
  294. JSON.parse(JSON.stringify(qu))
  295. )
  296. },
  297. // 选择地区的时候
  298. changeHandler(e) {
  299. const {
  300. columnIndex,
  301. value,
  302. values, // values为当前变化列的数组内容
  303. index,
  304. // 微信小程序无法将picker实例传出来,只能通过ref操作
  305. picker = this.$refs.areaPicker,
  306. } = e
  307. // 当第一列值发生变化时,变化第二列(后一列)对应的选项
  308. if (columnIndex === 0) {
  309. // picker为选择器this实例,变化第二列对应的选项
  310. this.areaColumns.forEach((item) => {
  311. if (value[0].distName == item.distName) {
  312. if (item.children) {
  313. let shi = []
  314. let flag = item.children[0].distName
  315. item.children.forEach((val, ol) => {
  316. shi.push({
  317. distName: val.distName,
  318. id: val.id,
  319. })
  320. if (shi[0].distName == flag) {
  321. //设置默认开关(选择省份后设置默认城市)
  322. flag = ''
  323. let qu = []
  324. val.children.forEach((vol) => {
  325. qu.push({
  326. distName: vol.distName,
  327. id: vol.id,
  328. })
  329. })
  330. picker.setColumnValues(2, qu)
  331. }
  332. })
  333. picker.setColumnValues(1, shi)
  334. } else {
  335. picker.setColumnValues(1, [])
  336. picker.setColumnValues(2, [])
  337. }
  338. }
  339. })
  340. }
  341. //当第二列变化时,第三列对应变化
  342. if (columnIndex === 1) {
  343. this.areaColumns.forEach((item) => {
  344. if (value[0].distName == item.distName) {
  345. let shi = []
  346. item.children.forEach((val, ol) => {
  347. shi.push({
  348. distName: val.distName,
  349. id: val.id,
  350. })
  351. if (value[1].distName == val.distName) {
  352. let qu = []
  353. val.children.forEach((vol) => {
  354. qu.push({
  355. distName: vol.distName,
  356. id: vol.id,
  357. })
  358. })
  359. picker.setColumnValues(2, qu)
  360. }
  361. })
  362. }
  363. })
  364. }
  365. },
  366. // 确认选中的数据
  367. localConfirm(e) {
  368. if (e.value[1]) {
  369. this.addForm.CustProvinceId = e.value[0].id
  370. this.addForm.CustProvince = e.value[0].distName
  371. this.addForm.CustCityId = e.value[1].id
  372. this.addForm.CustCity = e.value[1].distName
  373. this.addForm.CustRegionId = e.value[2].id
  374. this.addForm.CustRegion = e.value[2].distName
  375. this.addForm.area = e.value[0].distName + e.value[1].distName + e.value[2].distName
  376. }
  377. this.showArea = false
  378. },
  379. handleAdd() {
  380. this.$refs.addForm
  381. .validate()
  382. .then(async () => {
  383. let params = {
  384. custName: this.addForm.custName,
  385. custIndustry: this.addForm.industryId,
  386. custSource: this.addForm.custSourceId,
  387. CustProvinceId: this.addForm.CustProvinceId,
  388. CustProvince: this.addForm.CustProvince,
  389. CustCityId: this.addForm.CustCityId,
  390. CustCity: this.addForm.CustCity,
  391. CustRegionId: this.addForm.CustRegionId,
  392. CustRegion: this.addForm.CustRegion,
  393. remark: this.addForm.remark,
  394. }
  395. const [err, res] = await to(customerApi.createCustomer(params))
  396. if (err) return
  397. if (res && res.code == 200) {
  398. this.$refs.uToast.show({
  399. type: 'success',
  400. message: '创建成功',
  401. complete: () => {
  402. this.goBack()
  403. },
  404. })
  405. }
  406. })
  407. .catch((err) => {
  408. this.$refs.uNotify.show({
  409. top: this.height + this.paddingTop + 10,
  410. type: 'warning',
  411. message: err[0].message,
  412. duration: 1000 * 3,
  413. })
  414. })
  415. },
  416. goBack() {
  417. uni.navigateBack({
  418. //关闭当前页面,返回上一页面或多级页面。
  419. delta: 1,
  420. })
  421. },
  422. },
  423. }
  424. </script>
  425. <style>
  426. page {
  427. background: #f2f3f5;
  428. }
  429. </style>
  430. <style lang="scss" scoped>
  431. .home {
  432. padding-top: 188rpx;
  433. .nav {
  434. position: absolute;
  435. left: 0;
  436. top: 0;
  437. width: 100%;
  438. height: 284rpx;
  439. background: #3e7ef8;
  440. .title {
  441. position: relative;
  442. text-align: center;
  443. font-size: 32rpx;
  444. font-weight: bold;
  445. color: #ffffff;
  446. .back {
  447. position: absolute;
  448. top: 0;
  449. bottom: 0;
  450. margin: auto;
  451. left: 70rpx;
  452. display: flex;
  453. }
  454. }
  455. }
  456. .main {
  457. position: absolute;
  458. width: 100%;
  459. height: calc(100vh - 188rpx);
  460. background: #ffffff;
  461. box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
  462. border-radius: 31rpx 31rpx 0 0;
  463. padding: 0 32rpx;
  464. overflow: auto;
  465. padding-bottom: 64rpx;
  466. .form-label {
  467. font-size: 32rpx;
  468. font-weight: bold;
  469. color: #323232;
  470. padding-bottom: 18rpx;
  471. .label-tag {
  472. width: 15rpx;
  473. height: 15rpx;
  474. background: #ff4d4f;
  475. border-radius: 50%;
  476. margin-right: 10rpx;
  477. }
  478. }
  479. .save {
  480. width: 569rpx;
  481. height: 92rpx;
  482. background: #3e7ef8;
  483. border-radius: 31rpx;
  484. margin: 116rpx auto 0;
  485. font-size: 32rpx;
  486. color: #ffffff;
  487. text-align: center;
  488. line-height: 92rpx;
  489. }
  490. }
  491. }
  492. </style>