add.vue 15 KB

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