edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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="12">
  21. <a-form-model-item label="客户名称" prop="customerName" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  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="12">
  32. <a-form-model-item label="联系电话" prop="contactTel" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  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="12">
  37. <a-form-model-item label="联系手机" prop="contactMobile" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  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="12">
  42. <a-form-model-item label="联系人" prop="contactName" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  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="6">
  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="6">
  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="6">
  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-form-model-item label="是否为下级" prop="satelliteFlag">
  104. <span style="padding-left: 11px;">{{ form.satelliteFlag == 1 ? '是' : '否' }}</span>
  105. </a-form-model-item> -->
  106. <a-form-model-item label="客户关系" prop="relationTypeDictValue">
  107. <span style="padding-left: 11px;">{{ form.relationTypeDictValue }}</span>
  108. </a-form-model-item>
  109. </a-col>
  110. </a-row>
  111. <a-row :gutter="15">
  112. <a-col :span="8">
  113. <a-form-model-item label="价格类型" ref="priceType" prop="priceType">
  114. <v-select code="PRICE_TYPE" id="customerManagementEdit-priceType" v-model="form.priceType" allowClear placeholder="请选择价格类型" ></v-select>
  115. </a-form-model-item>
  116. </a-col>
  117. <a-col :span="8">
  118. <a-form-model-item label="收款方式" prop="settleStyleSn">
  119. <a-select id="customerManagementEdit-settleStyleSn" v-model="form.settleStyleSn" allowClear placeholder="请选择收款方式">
  120. <a-select-option v-for="item in settleStyleList" :value="item.settleStyleSn" :key="item.settleStyleSn">{{ item.name }}</a-select-option>
  121. </a-select>
  122. </a-form-model-item>
  123. </a-col>
  124. <a-col :span="8">
  125. <a-form-model-item label="客户类型" prop="customerTypeSn">
  126. <custType id="customerManagementEdit-customerTypeSn" v-model="form.customerTypeSn" allowClear placeholder="请选择客户类型"></custType>
  127. </a-form-model-item>
  128. </a-col>
  129. </a-row>
  130. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;margin-top: 30px;">
  131. <a-button type="primary" @click="handleSubmit" size="large" id="customerManagementEdit-btn-submit" style="padding: 0 60px;">保存</a-button>
  132. </a-form-model-item>
  133. </a-form-model>
  134. </a-card>
  135. </a-spin>
  136. </div>
  137. </template>
  138. <script>
  139. import { commonMixin } from '@/utils/mixin'
  140. import { STable, VSelect } from '@/components'
  141. import { getArea } from '@/api/data'
  142. import custType from '@/views/common/custType.js'
  143. import { custSave, custFindById, settleStyleFindAllList } from '@/api/customer'
  144. export default {
  145. name: 'CustomerManagementEdit',
  146. components: { STable, VSelect, custType },
  147. mixins: [commonMixin],
  148. props: {
  149. model: {
  150. type: String,
  151. default: 'page'
  152. }
  153. },
  154. data () {
  155. return {
  156. spinning: false,
  157. formItemLayout: {
  158. labelCol: { span: 9 },
  159. wrapperCol: { span: 14 }
  160. },
  161. form: {
  162. id: null,
  163. customerName: '', // 客户名称
  164. contactTel: '', // 联系电话
  165. contactMobile: '', // 联系手机
  166. contactName: '', // 联系人
  167. provinceSn: undefined, // 省
  168. provinceName: '',
  169. citySn: undefined, // 市
  170. cityName: '',
  171. countySn: undefined, // 区
  172. countyName: '',
  173. customerAddr: '', // 详细地址
  174. fax: '', // 客户传真
  175. dispatchType: '', // 配送方式
  176. satelliteFlag: 0, // 是否卫星仓客户
  177. relationTypeDictValue: undefined, // 客户关系
  178. customerTypeSn: undefined, // 客户类型
  179. priceType: '', // 价格类型
  180. settleStyleSn: undefined // 收款方式
  181. },
  182. rules: {
  183. customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  184. contactMobile: [{ required: false, pattern: /^\d{11}$/, message: '请输入正确的手机号', trigger: 'blur' }],
  185. provinceSn: [{ required: true, message: '请选择省', trigger: 'change' }],
  186. citySn: [{ required: true, message: '请选择市', trigger: 'change' }],
  187. countySn: [{ required: true, message: '请选择区/县', trigger: 'change' }],
  188. priceType: [{ required: true, message: '请选择价格类型', trigger: 'change' }],
  189. settleStyleSn: [{ required: true, message: '请选择收款方式', trigger: 'change' }]
  190. },
  191. addrProvinceList: [], // 省下拉
  192. addrCityList: [], // 市下拉
  193. addrDistrictList: [], // 区下拉
  194. settleStyleList: [] // 收款方式 下拉数据
  195. }
  196. },
  197. methods: {
  198. filterEmpty () {
  199. let str = this.form.customerName
  200. str = str.replace(/\ +/g, '')
  201. str = str.replace(/[ ]/g, '')
  202. str = str.replace(/[\r\n]/g, '')
  203. this.form.customerName = str
  204. },
  205. // 获取客户信息
  206. getDetail () {
  207. custFindById({ id: this.$route.params.id }).then(res => {
  208. if (res.status == 200) {
  209. if (res.data.provinceSn) { this.getArea('city', res.data.provinceSn) }
  210. if (res.data.citySn) { this.getArea('district', res.data.citySn) }
  211. res.data.satelliteFlag = res.data.dealerFlag
  212. this.form = Object.assign(this.form, res.data)
  213. } else {
  214. this.$refs.ruleForm.resetFields()
  215. }
  216. })
  217. },
  218. // 收款方式
  219. getSettleStyleList () {
  220. settleStyleFindAllList().then(res => {
  221. if (res.status == 200) {
  222. this.settleStyleList = res.data
  223. } else {
  224. this.settleStyleList = []
  225. }
  226. })
  227. },
  228. // 保存
  229. handleSubmit (e) {
  230. e.preventDefault()
  231. const _this = this
  232. this.$refs.ruleForm.validate(valid => {
  233. if (valid) {
  234. const form = JSON.stringify(_this.form)
  235. const formInfo = JSON.parse(form)
  236. delete formInfo.satelliteFlag
  237. formInfo.id = this.$route.params.id && this.model == 'page' ? this.$route.params.id : null
  238. _this.spinning = true
  239. custSave(formInfo).then(res => {
  240. if (res.status == 200) {
  241. _this.$message.success(res.message)
  242. if (_this.model == 'page') {
  243. setTimeout(() => {
  244. _this.handleBack()
  245. }, 600)
  246. } else {
  247. _this.$emit('ok', res.data)
  248. }
  249. _this.spinning = false
  250. } else {
  251. _this.spinning = false
  252. }
  253. })
  254. } else {
  255. console.log('error submit!!')
  256. return false
  257. }
  258. })
  259. },
  260. // 返回列表
  261. handleBack () {
  262. this.$router.push({ path: '/customerManagement/customerInfo/list' })
  263. },
  264. // 获取城市列表
  265. getCityList (val) {
  266. this.addrCityList = []
  267. this.addrDistrictList = []
  268. this.form.citySn = undefined
  269. this.form.countySn = undefined
  270. if (val) {
  271. this.getArea('city', val)
  272. this.form.provinceName = this.addrProvinceList.find(item => item.areaSn == val).name
  273. } else {
  274. this.form.provinceName = ''
  275. }
  276. },
  277. // 获取区县列表
  278. getAreaList (val) {
  279. this.addrDistrictList = []
  280. this.form.countySn = undefined
  281. if (val) {
  282. this.getArea('district', val)
  283. this.form.cityName = this.addrCityList.find(item => item.areaSn == val).name
  284. } else {
  285. this.form.cityName = ''
  286. }
  287. },
  288. // 区县变更
  289. areaCharged (val) {
  290. if (val) {
  291. this.form.countyName = this.addrDistrictList.find(item => item.areaSn == val).name
  292. } else {
  293. this.form.countyName = ''
  294. }
  295. },
  296. // 省/市/区
  297. getArea (leve, sn) {
  298. let params
  299. if (leve == 'province') {
  300. params = { type: '2' }
  301. } else {
  302. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  303. }
  304. getArea(params).then(res => {
  305. if (res.status == 200) {
  306. if (leve == 'province') {
  307. this.addrProvinceList = res.data || []
  308. } else if (leve == 'city') {
  309. this.addrCityList = res.data || []
  310. } else if (leve == 'district') {
  311. this.addrDistrictList = res.data || []
  312. }
  313. } else {
  314. if (leve == 'province') {
  315. this.addrProvinceList = []
  316. } else if (leve == 'city') {
  317. this.addrCityList = []
  318. } else if (leve == 'district') {
  319. this.addrDistrictList = []
  320. }
  321. }
  322. })
  323. },
  324. // 获取基础数据
  325. getBaseData () {
  326. this.getArea('province') // 省市区
  327. this.getSettleStyleList() // 收款方式
  328. this.$refs.ruleForm.resetFields()
  329. },
  330. initPage () {
  331. this.getBaseData()
  332. if (this.$route.params.id) {
  333. // 编辑页
  334. this.getDetail()
  335. }
  336. }
  337. },
  338. mounted () {
  339. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  340. this.initPage()
  341. }
  342. },
  343. activated () {
  344. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  345. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  346. this.initPage()
  347. }
  348. },
  349. beforeRouteEnter (to, from, next) {
  350. next(vm => {})
  351. }
  352. }
  353. </script>
  354. <style lang="less">
  355. .customerManagementEdit-wrap {
  356. height: 100%;
  357. >.ant-spin-nested-loading{
  358. height: calc(100% - 52px);
  359. overflow-y: auto;
  360. .ant-spin-container{
  361. height: 97%;
  362. }
  363. }
  364. .customerManagementEdit-back {
  365. margin-bottom: 10px;
  366. }
  367. .customerManagementEdit-table-page-wrapper{
  368. height: 100%;
  369. }
  370. }
  371. </style>