edit.vue 13 KB

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