edit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div class="customerManagementEdit-wrap">
  3. <a-page-header :ghost="false" @back="handleBack" class="customerManagementEdit-back">
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="customerManagementEdit-back-btn" href="javascript:;" @click="handleBack">返回列表</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 id="customerManagementEdit-customerName" :maxLength="30" v-model="form.customerName" placeholder="请输入客户名称(最多30个字符)" allowClear />
  22. </a-form-model-item>
  23. </a-col>
  24. <a-col :span="8">
  25. <a-form-model-item label="联系电话" prop="contactTel">
  26. <a-input id="customerManagementEdit-contactTel" :maxLength="20" v-model="form.contactTel" placeholder="请输入联系电话(最多20个字符)" allowClear />
  27. </a-form-model-item>
  28. </a-col>
  29. <a-col :span="8">
  30. <a-form-model-item label="联系人" prop="contactName">
  31. <a-input id="customerManagementEdit-contactName" :maxLength="30" v-model="form.contactName" placeholder="请输入联系人(最多30个字符)" allowClear />
  32. </a-form-model-item>
  33. </a-col>
  34. </a-row>
  35. <a-row :gutter="15">
  36. <a-col :span="16">
  37. <a-form-model-item label="客户地址" required style="margin: 0;" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
  38. <a-row :gutter="15">
  39. <!-- 客户地址 -->
  40. <a-col span="8">
  41. <a-form-model-item prop="provinceSn">
  42. <a-select id="customerManagementEdit-provinceSn" @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
  43. <a-select-option v-for="item in addrProvinceList" :value="item.id" :key="item.id + 'a'">{{ item.name }}</a-select-option>
  44. </a-select>
  45. </a-form-model-item>
  46. </a-col>
  47. <a-col span="8">
  48. <a-form-model-item prop="citySn">
  49. <a-select id="customerManagementEdit-citySn" @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
  50. <a-select-option v-for="item in addrCityList" :value="item.id" :key="item.id + 'b'">{{ 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="countySn">
  56. <a-select id="customerManagementEdit-countySn" @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
  57. <a-select-option v-for="item in addrAreaList" :value="item.id" :key="item.id + 'c'">{{ item.name }}</a-select-option>
  58. </a-select>
  59. </a-form-model-item>
  60. </a-col>
  61. </a-row>
  62. </a-form-model-item>
  63. </a-col>
  64. <a-col :span="8">
  65. <a-form-model-item label="详细地址" prop="customerAddr">
  66. <a-input id="customerManagementEdit-customerAddr" :maxLength="60" v-model="form.customerAddr" placeholder="请输入详细地址(最多60个字符)" allowClear />
  67. </a-form-model-item>
  68. </a-col>
  69. </a-row>
  70. <a-row :gutter="15">
  71. <a-col :span="8">
  72. <a-form-model-item label="客户传真" prop="fax">
  73. <a-input id="customerManagementEdit-fax" :maxLength="30" v-model="form.fax" placeholder="请输入客户传真(最多30个字符)" allowClear />
  74. </a-form-model-item>
  75. </a-col>
  76. <a-col :span="8">
  77. <a-form-model-item label="配送方式" prop="dispatchType">
  78. <v-select
  79. code="DISPATCH_FASHION"
  80. id="customerManagementEdit-dispatchType"
  81. v-model="form.dispatchType"
  82. allowClear
  83. placeholder="请选择配送方式"
  84. ></v-select>
  85. </a-form-model-item>
  86. </a-col>
  87. <a-col :span="8">
  88. <a-form-model-item label="是否卫星仓客户" prop="satelliteFlag">
  89. <v-select
  90. code="DISPATCH_FASHION"
  91. id="customerManagementEdit-satelliteFlag"
  92. v-model="form.satelliteFlag"
  93. allowClear
  94. placeholder="请选择"
  95. ></v-select>
  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="payType">
  107. <v-select code="PAY_FASHION" id="customerManagementEdit-payType" v-model="form.payType" allowClear placeholder="请选择支付方式" />
  108. </a-form-model-item>
  109. </a-col>
  110. <a-col :span="8">
  111. <a-form-model-item label="收款方式" prop="settleStyleSn">
  112. <v-select code="RECEIPT_PAYMENT" id="customerManagementEdit-settleStyleSn" v-model="form.settleStyleSn" allowClear placeholder="请选择收款方式"></v-select>
  113. </a-form-model-item>
  114. </a-col>
  115. </a-row>
  116. <a-row :gutter="15">
  117. <a-col :span="8">
  118. <a-form-model-item label="客户类型" prop="custType">
  119. <a-select id="customerManagementEdit-custType" v-model="form.customerTypeSn" allowClear placeholder="请选择客户类型">
  120. <a-select-option v-for="item in custTypeList" :value="item.id" :key="item.id">{{ item.name }}</a-select-option>
  121. </a-select>
  122. </a-form-model-item>
  123. </a-col>
  124. </a-row>
  125. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  126. <a-button type="primary" @click="handleSubmit" id="customerManagementEdit-btn-submit" style="padding: 0 60px;">保存</a-button>
  127. </a-form-model-item>
  128. </a-form-model>
  129. </a-card>
  130. </div>
  131. </template>
  132. <script>
  133. import { STable, VSelect } from '@/components'
  134. import { getArea } from '@/api/data'
  135. import { custSave, custFindById } from '@/api/customer'
  136. import { custTypeFindAll } from '@/api/custType'
  137. export default {
  138. name: 'CustomerManagementEdit',
  139. components: { STable, VSelect },
  140. data () {
  141. return {
  142. formItemLayout: {
  143. labelCol: { span: 8 },
  144. wrapperCol: { span: 16 }
  145. },
  146. form: {
  147. customerName: '', // 客户名称
  148. contactTel: '', // 联系电话
  149. contactName: '', // 联系人
  150. provinceSn: undefined, // 省
  151. province: '',
  152. citySn: undefined, // 市
  153. city: '',
  154. countySn: undefined, // 区
  155. area: '',
  156. customerAddr: '', // 详细地址
  157. fax: '', // 客户传真
  158. dispatchType: '', // 配送方式
  159. satelliteFlag: undefined, // 是否卫星仓客户
  160. customerTypeSn: undefined, // 客户类型
  161. priceType: '', // 价格类型
  162. payType: '', // 支付方式
  163. settleStyleSn: '' // 收款方式
  164. },
  165. rules: {
  166. customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  167. contactTel: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
  168. provinceSn: [{ required: true, message: '请选择省', trigger: 'change' }],
  169. citySn: [{ required: true, message: '请选择市', trigger: 'change' }],
  170. countySn: [{ required: true, message: '请选择区/县', trigger: 'change' }],
  171. customerTypeSn: [{ required: true, message: '请选择客户类型', trigger: 'change' }],
  172. priceType: [{ required: true, message: '请选择价格类型', trigger: 'change' }],
  173. payType: [{ required: true, message: '请选择支付方式', trigger: 'change' }],
  174. settleStyleSn: [{ required: true, message: '请选择收款方式', trigger: 'change' }]
  175. },
  176. addrProvinceList: [], // 省下拉
  177. addrCityList: [], // 市下拉
  178. addrAreaList: [], // 区下拉
  179. custTypeList: [] // 客户类型 下拉数据
  180. }
  181. },
  182. methods: {
  183. // 获取客户信息
  184. getDetail () {
  185. custFindById({ id: this.$route.params.id }).then(res => {
  186. if (res.status == 200) {
  187. // this.detailsData = res.data
  188. } else {
  189. this.$refs.ruleForm.resetFields()
  190. }
  191. })
  192. },
  193. // 客户类型
  194. getCustTypeList () {
  195. custTypeFindAll({}).then(res => {
  196. if (res.status == 200) {
  197. this.custTypeList = res.data
  198. }
  199. })
  200. },
  201. // 保存
  202. handleSubmit (e) {
  203. e.preventDefault()
  204. const _this = this
  205. this.$refs.ruleForm.validate(valid => {
  206. if (valid) {
  207. const form = _this.form
  208. form.id = this.$route.params.id ? this.$route.params.id : null
  209. const areas = [ form.provinceSn, form.citySn, form.countySn ]
  210. form.areas = areas.join(',')
  211. delete form.provinceSn
  212. delete form.citySn
  213. console.log(form, '-----提交信息')
  214. custSave(form).then(res => {
  215. if (res.status == 200) {
  216. _this.$message.success(res.message)
  217. setTimeout(() => {
  218. _this.$router.push({ path: '/customerManagement/customerInfo/list' })
  219. }, 1000)
  220. }
  221. })
  222. } else {
  223. console.log('error submit!!')
  224. return false
  225. }
  226. })
  227. },
  228. // 返回列表
  229. handleBack () {
  230. this.$router.push({ path: '/customerManagement/customerInfo/list' })
  231. },
  232. // 获取城市列表
  233. getCityList (val) {
  234. this.addrCityList = []
  235. this.addrDistrictList = []
  236. this.form.cityCode = undefined
  237. this.form.districtCode = undefined
  238. this.form.address = ''
  239. this.getArea('city', val)
  240. },
  241. // 获取区县列表
  242. getAreaList (val) {
  243. this.addrDistrictList = []
  244. this.form.districtCode = undefined
  245. this.form.address = ''
  246. this.getArea('district', val)
  247. },
  248. // 区县变更
  249. areaCharged (val) {
  250. this.form.address = ''
  251. },
  252. // 省/市/区
  253. getArea (type, sn) {
  254. let params
  255. if (type == 'province') {
  256. params = { level: '1' }
  257. } else {
  258. params = { psn: sn }
  259. }
  260. getArea(params).then(res => {
  261. if (res.status == 200) {
  262. if (type == 'province') {
  263. this.addrProvinceList = res.data || []
  264. } else if (type == 'city') {
  265. this.addrCityList = res.data || []
  266. } else if (type == 'district') {
  267. this.addrDistrictList = res.data || []
  268. }
  269. } else {
  270. if (type == 'province') {
  271. this.addrProvinceList = []
  272. } else if (type == 'city') {
  273. this.addrCityList = []
  274. } else if (type == 'district') {
  275. this.addrDistrictList = []
  276. }
  277. }
  278. })
  279. }
  280. },
  281. beforeRouteEnter (to, from, next) {
  282. next(vm => {
  283. vm.getArea('province') // 省市区
  284. // vm.getCustTypeList() // 客户类型
  285. vm.$refs.ruleForm.resetFields()
  286. if (vm.$route.params.id) {
  287. // 编辑页
  288. vm.getDetail()
  289. }
  290. })
  291. }
  292. }
  293. </script>
  294. <style lang="less">
  295. .customerManagementEdit-wrap {
  296. .customerManagementEdit-back {
  297. margin-bottom: 15px;
  298. }
  299. }
  300. </style>