edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="customerManagementEdit-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" v-if="model=='page'" class="customerManagementEdit-back">
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="customerManagementEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. </template>
  8. </a-page-header>
  9. <a-spin :spinning="spinning" tip="Loading...">
  10. <a-card size="small" :bordered="false" class="customerManagementEdit-table-page-wrapper">
  11. <a-form-model
  12. id="customerManagementEdit-form"
  13. ref="ruleForm"
  14. :model="form"
  15. :rules="rules"
  16. :label-col="formItemLayout.labelCol"
  17. :wrapper-col="formItemLayout.wrapperCol"
  18. >
  19. <a-row :gutter="15">
  20. <a-col :span="8">
  21. <a-form-model-item label="客户名称" prop="customerName">
  22. <a-input
  23. id="customerManagementEdit-customerName"
  24. :maxLength="30"
  25. v-model.trim="form.customerName"
  26. @change="filterEmpty"
  27. placeholder="请输入客户名称(最多30个字符)"
  28. allowClear />
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :span="8">
  32. <a-form-model-item label="联系电话" prop="contactTel">
  33. <a-input id="customerManagementEdit-contactTel" :maxLength="15" v-model.trim="form.contactTel" placeholder="请输入联系电话(最多15个字符)" allowClear />
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :span="8">
  37. <a-form-model-item label="联系手机" prop="contactMobile">
  38. <a-input id="customerManagementEdit-contactMobile" :maxLength="11" v-model.trim="form.contactMobile" placeholder="请输入联系手机(最多11个字符)" allowClear />
  39. </a-form-model-item>
  40. </a-col>
  41. <a-col :span="8">
  42. <a-form-model-item label="联系人" prop="contactName">
  43. <a-input id="customerManagementEdit-contactName" :maxLength="30" v-model.trim="form.contactName" placeholder="请输入联系人(最多30个字符)" allowClear />
  44. </a-form-model-item>
  45. </a-col>
  46. </a-row>
  47. <a-row :gutter="15">
  48. <a-col :span="24">
  49. <a-form-model-item label="客户地址" required style="margin: 0;" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
  50. <a-row :gutter="15">
  51. <!-- 客户地址 -->
  52. <a-col span="8">
  53. <a-form-model-item prop="provinceSn">
  54. <a-select id="customerManagementEdit-provinceSn" allowClear @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
  55. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  56. </a-select>
  57. </a-form-model-item>
  58. </a-col>
  59. <a-col span="8">
  60. <a-form-model-item prop="citySn">
  61. <a-select id="customerManagementEdit-citySn" allowClear @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
  62. <a-select-option v-for="item in addrCityList" :value="item.areaSn" :key="item.areaSn + 'b'">{{ item.name }}</a-select-option>
  63. </a-select>
  64. </a-form-model-item>
  65. </a-col>
  66. <a-col span="8">
  67. <a-form-model-item prop="countySn">
  68. <a-select id="customerManagementEdit-countySn" allowClear @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
  69. <a-select-option v-for="item in addrDistrictList" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
  70. </a-select>
  71. </a-form-model-item>
  72. </a-col>
  73. </a-row>
  74. </a-form-model-item>
  75. </a-col>
  76. <a-col :span="24">
  77. <a-form-model-item label="详细地址" prop="customerAddr" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
  78. <a-input id="customerManagementEdit-customerAddr" :maxLength="60" v-model.trim="form.customerAddr" placeholder="请输入详细地址(最多60个字符)" allowClear />
  79. </a-form-model-item>
  80. </a-col>
  81. </a-row>
  82. <a-row :gutter="15">
  83. <a-col :span="8">
  84. <a-form-model-item label="客户传真" prop="fax">
  85. <a-input id="customerManagementEdit-fax" :maxLength="30" v-model.trim="form.fax" placeholder="请输入客户传真(最多30个字符)" allowClear />
  86. </a-form-model-item>
  87. </a-col>
  88. <a-col :span="8">
  89. <a-form-model-item label="配送方式" prop="dispatchType">
  90. <v-select
  91. code="DISPATCH_TYPE"
  92. id="customerManagementEdit-dispatchType"
  93. v-model="form.dispatchType"
  94. allowClear
  95. placeholder="请选择配送方式"
  96. ></v-select>
  97. </a-form-model-item>
  98. </a-col>
  99. <a-col :span="8">
  100. <a-form-model-item label="是否卫星仓客户" prop="satelliteFlag">
  101. <span style="padding-left: 11px;">{{ form.satelliteFlag == 1 ? '是' : '否' }}</span>
  102. </a-form-model-item>
  103. </a-col>
  104. </a-row>
  105. <a-row :gutter="15">
  106. <a-col :span="8">
  107. <a-form-model-item label="价格类型" ref="priceType" prop="priceType">
  108. <v-select code="PRICE_TYPE" id="customerManagementEdit-priceType" v-model="form.priceType" allowClear placeholder="请选择价格类型" ></v-select>
  109. </a-form-model-item>
  110. </a-col>
  111. <a-col :span="8">
  112. <a-form-model-item label="收款方式" prop="settleStyleSn">
  113. <a-select id="customerManagementEdit-settleStyleSn" v-model="form.settleStyleSn" allowClear placeholder="请选择收款方式">
  114. <a-select-option v-for="item in settleStyleList" :value="item.settleStyleSn" :key="item.settleStyleSn">{{ item.name }}</a-select-option>
  115. </a-select>
  116. </a-form-model-item>
  117. </a-col>
  118. <a-col :span="8">
  119. <a-form-model-item label="客户类型" prop="customerTypeSn">
  120. <a-select id="customerManagementEdit-customerTypeSn" v-model="form.customerTypeSn" allowClear placeholder="请选择客户类型">
  121. <a-select-option v-for="item in custTypeList" :value="item.customerTypeSn" :key="item.customerTypeSn">{{ item.name }}</a-select-option>
  122. </a-select>
  123. </a-form-model-item>
  124. </a-col>
  125. </a-row>
  126. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  127. <a-button type="primary" @click="handleSubmit" size="large" id="customerManagementEdit-btn-submit" style="padding: 0 60px;">保存</a-button>
  128. </a-form-model-item>
  129. </a-form-model>
  130. </a-card>
  131. </a-spin>
  132. </div>
  133. </template>
  134. <script>
  135. import { STable, VSelect } from '@/components'
  136. import { getArea } from '@/api/data'
  137. import { custSave, custFindById, settleStyleFindAllList } from '@/api/customer'
  138. import { custTypeFindAllList } from '@/api/custType'
  139. export default {
  140. name: 'CustomerManagementEdit',
  141. components: { STable, VSelect },
  142. props: {
  143. model: {
  144. type: String,
  145. default: 'page'
  146. }
  147. },
  148. data () {
  149. return {
  150. spinning: false,
  151. formItemLayout: {
  152. labelCol: { span: 9 },
  153. wrapperCol: { span: 14 }
  154. },
  155. form: {
  156. id: null,
  157. customerName: '', // 客户名称
  158. contactTel: '', // 联系电话
  159. contactMobile: '', // 联系手机
  160. contactName: '', // 联系人
  161. provinceSn: undefined, // 省
  162. provinceName: '',
  163. citySn: undefined, // 市
  164. cityName: '',
  165. countySn: undefined, // 区
  166. countyName: '',
  167. customerAddr: '', // 详细地址
  168. fax: '', // 客户传真
  169. dispatchType: '', // 配送方式
  170. satelliteFlag: 0, // 是否卫星仓客户
  171. customerTypeSn: undefined, // 客户类型
  172. priceType: '', // 价格类型
  173. settleStyleSn: undefined // 收款方式
  174. },
  175. rules: {
  176. customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  177. contactMobile: [{ required: false, pattern: /^\d{11}$/, message: '请输入正确的手机号', trigger: 'blur' }],
  178. provinceSn: [{ required: true, message: '请选择省', trigger: 'change' }],
  179. citySn: [{ required: true, message: '请选择市', trigger: 'change' }],
  180. countySn: [{ required: true, message: '请选择区/县', trigger: 'change' }],
  181. priceType: [{ required: true, message: '请选择价格类型', trigger: 'change' }],
  182. settleStyleSn: [{ required: true, message: '请选择收款方式', trigger: 'change' }]
  183. },
  184. addrProvinceList: [], // 省下拉
  185. addrCityList: [], // 市下拉
  186. addrDistrictList: [], // 区下拉
  187. custTypeList: [], // 客户类型 下拉数据
  188. settleStyleList: [] // 收款方式 下拉数据
  189. }
  190. },
  191. methods: {
  192. filterEmpty () {
  193. let str = this.form.customerName
  194. str = str.replace(/\ +/g, '')
  195. str = str.replace(/[ ]/g, '')
  196. str = str.replace(/[\r\n]/g, '')
  197. this.form.customerName = str
  198. },
  199. // 获取客户信息
  200. getDetail () {
  201. custFindById({ id: this.$route.params.id }).then(res => {
  202. if (res.status == 200) {
  203. if (res.data.provinceSn) { this.getArea('city', res.data.provinceSn) }
  204. if (res.data.citySn) { this.getArea('district', res.data.citySn) }
  205. this.form = Object.assign(this.form, res.data)
  206. } else {
  207. this.$refs.ruleForm.resetFields()
  208. }
  209. })
  210. },
  211. // 客户类型
  212. getCustTypeList () {
  213. custTypeFindAllList().then(res => {
  214. if (res.status == 200) {
  215. this.custTypeList = res.data
  216. } else {
  217. this.custTypeList = []
  218. }
  219. })
  220. },
  221. // 收款方式
  222. getSettleStyleList () {
  223. settleStyleFindAllList().then(res => {
  224. if (res.status == 200) {
  225. this.settleStyleList = res.data
  226. } else {
  227. this.settleStyleList = []
  228. }
  229. })
  230. },
  231. // 保存
  232. handleSubmit (e) {
  233. e.preventDefault()
  234. const _this = this
  235. this.$refs.ruleForm.validate(valid => {
  236. if (valid) {
  237. const form = _this.form
  238. form.id = this.$route.params.id && this.model == 'page' ? this.$route.params.id : null
  239. _this.spinning = true
  240. custSave(form).then(res => {
  241. if (res.status == 200) {
  242. _this.$message.success(res.message)
  243. if (_this.model == 'page') {
  244. setTimeout(() => {
  245. _this.handleBack()
  246. }, 600)
  247. } else {
  248. _this.$emit('ok', res.data)
  249. }
  250. _this.spinning = false
  251. } else {
  252. _this.spinning = false
  253. }
  254. })
  255. } else {
  256. console.log('error submit!!')
  257. return false
  258. }
  259. })
  260. },
  261. // 返回列表
  262. handleBack () {
  263. this.$router.push({ path: '/customerManagement/customerInfo/list', query: { closeLastOldTab: true } })
  264. },
  265. // 获取城市列表
  266. getCityList (val) {
  267. this.addrCityList = []
  268. this.addrDistrictList = []
  269. this.form.citySn = undefined
  270. this.form.countySn = undefined
  271. if (val) {
  272. this.getArea('city', val)
  273. this.form.provinceName = this.addrProvinceList.find(item => item.areaSn == val).name
  274. } else {
  275. this.form.provinceName = ''
  276. }
  277. },
  278. // 获取区县列表
  279. getAreaList (val) {
  280. this.addrDistrictList = []
  281. this.form.countySn = undefined
  282. if (val) {
  283. this.getArea('district', val)
  284. this.form.cityName = this.addrCityList.find(item => item.areaSn == val).name
  285. } else {
  286. this.form.cityName = ''
  287. }
  288. },
  289. // 区县变更
  290. areaCharged (val) {
  291. if (val) {
  292. this.form.countyName = this.addrDistrictList.find(item => item.areaSn == val).name
  293. } else {
  294. this.form.countyName = ''
  295. }
  296. },
  297. // 省/市/区
  298. getArea (leve, sn) {
  299. let params
  300. if (leve == 'province') {
  301. params = { type: '2' }
  302. } else {
  303. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  304. }
  305. getArea(params).then(res => {
  306. if (res.status == 200) {
  307. if (leve == 'province') {
  308. this.addrProvinceList = res.data || []
  309. } else if (leve == 'city') {
  310. this.addrCityList = res.data || []
  311. } else if (leve == 'district') {
  312. this.addrDistrictList = res.data || []
  313. }
  314. } else {
  315. if (leve == 'province') {
  316. this.addrProvinceList = []
  317. } else if (leve == 'city') {
  318. this.addrCityList = []
  319. } else if (leve == 'district') {
  320. this.addrDistrictList = []
  321. }
  322. }
  323. })
  324. },
  325. // 获取基础数据
  326. getBaseData () {
  327. this.getArea('province') // 省市区
  328. this.getCustTypeList() // 客户类型
  329. this.getSettleStyleList() // 收款方式
  330. this.$refs.ruleForm.resetFields()
  331. },
  332. initPage () {
  333. this.getBaseData()
  334. if (this.$route.params.id) {
  335. // 编辑页
  336. this.getDetail()
  337. }
  338. }
  339. },
  340. mounted () {
  341. this.initPage()
  342. },
  343. beforeRouteEnter (to, from, next) {
  344. next(vm => {
  345. vm.initPage()
  346. })
  347. }
  348. }
  349. </script>
  350. <style lang="less">
  351. .customerManagementEdit-wrap {
  352. height: 100%;
  353. >.ant-spin-nested-loading{
  354. height: 100%;
  355. .ant-spin-container{
  356. height: 90%;
  357. }
  358. }
  359. .customerManagementEdit-back {
  360. margin-bottom: 10px;
  361. }
  362. .customerManagementEdit-table-page-wrapper{
  363. height: 100%;
  364. }
  365. }
  366. </style>