add.vue 14 KB

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