add.vue 14 KB

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