edit.vue 14 KB

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