edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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" v-show="!form.relationType||form.relationType==='customer'">
  32. <a-form-model-item label="关联经销商" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  33. <dealerList id="customerManagementEdit-putPersonName" ref="dealerList" @change="dealerChange"></dealerList>
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :span="12" v-show="form.relationType&&form.relationType!='customer'">
  37. <a-form-model-item label="关联经销商" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  38. <dealerList :disabled="true" id="customerManagementEdit-putPersonName" ref="dealerList1" @change="dealerChange"></dealerList>
  39. </a-form-model-item>
  40. </a-col>
  41. <a-col :span="12">
  42. <a-form-model-item label="联系电话" prop="contactTel" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  43. <a-input id="customerManagementEdit-contactTel" :maxLength="15" v-model.trim="form.contactTel" placeholder="请输入联系电话(最多15个字符)" allowClear />
  44. </a-form-model-item>
  45. </a-col>
  46. <a-col :span="12">
  47. <a-form-model-item label="联系手机" prop="contactMobile" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  48. <a-input id="customerManagementEdit-contactMobile" :maxLength="11" v-model.trim="form.contactMobile" placeholder="请输入联系手机(最多11个字符)" allowClear />
  49. </a-form-model-item>
  50. </a-col>
  51. <a-col :span="12">
  52. <a-form-model-item label="联系人" prop="contactName" :labelCol="{ span: 6}" :wrapperCol="{ span: 16 }">
  53. <a-input id="customerManagementEdit-contactName" :maxLength="30" v-model.trim="form.contactName" placeholder="请输入联系人(最多30个字符)" allowClear />
  54. </a-form-model-item>
  55. </a-col>
  56. </a-row>
  57. <a-row :gutter="15">
  58. <a-col :span="24">
  59. <a-form-model-item label="客户地址" prop="countySn" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
  60. <AreaList changeOnSelect ref="areaList" v-model="areaVal" @change="areaChange"></AreaList>
  61. </a-form-model-item>
  62. </a-col>
  63. <a-col :span="24">
  64. <a-form-model-item label="详细地址" prop="customerAddr" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
  65. <a-input id="customerManagementEdit-customerAddr" :maxLength="60" v-model.trim="form.customerAddr" placeholder="请输入详细地址(最多60个字符)" allowClear />
  66. </a-form-model-item>
  67. </a-col>
  68. </a-row>
  69. <a-row :gutter="15">
  70. <a-col :span="8">
  71. <a-form-model-item label="客户传真" prop="fax">
  72. <a-input id="customerManagementEdit-fax" :maxLength="30" v-model.trim="form.fax" placeholder="请输入客户传真(最多30个字符)" allowClear />
  73. </a-form-model-item>
  74. </a-col>
  75. <a-col :span="8">
  76. <a-form-model-item label="配送方式" prop="dispatchType">
  77. <v-select
  78. code="DISPATCH_TYPE"
  79. id="customerManagementEdit-dispatchType"
  80. v-model="form.dispatchType"
  81. allowClear
  82. placeholder="请选择配送方式"
  83. ></v-select>
  84. </a-form-model-item>
  85. </a-col>
  86. <a-col :span="8" v-if="form.relationTypeDictValue">
  87. <a-form-model-item label="客户关系" prop="relationTypeDictValue">
  88. <span style="padding-left: 11px;">{{ form.relationTypeDictValue || '--' }}</span>
  89. </a-form-model-item>
  90. </a-col>
  91. </a-row>
  92. <a-row :gutter="15">
  93. <a-col :span="8">
  94. <a-form-model-item label="价格类型" ref="priceType" prop="priceType">
  95. <v-select code="PRICE_TYPE" id="customerManagementEdit-priceType" v-model="form.priceType" allowClear placeholder="请选择价格类型" ></v-select>
  96. </a-form-model-item>
  97. </a-col>
  98. <a-col :span="8">
  99. <a-form-model-item label="收款方式" prop="settleStyleSn">
  100. <a-select id="customerManagementEdit-settleStyleSn" v-model="form.settleStyleSn" allowClear placeholder="请选择收款方式">
  101. <a-select-option v-for="item in settleStyleList" :value="item.settleStyleSn" :key="item.settleStyleSn">{{ item.name }}</a-select-option>
  102. </a-select>
  103. </a-form-model-item>
  104. </a-col>
  105. <a-col :span="8">
  106. <a-form-model-item label="客户类型" prop="customerTypeSn">
  107. <custType id="customerManagementEdit-customerTypeSn" v-model="form.customerTypeSn" allowClear placeholder="请选择客户类型"></custType>
  108. </a-form-model-item>
  109. </a-col>
  110. </a-row>
  111. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;margin-top: 30px;">
  112. <a-button type="primary" @click="handleSubmit" size="large" id="customerManagementEdit-btn-submit" style="padding: 0 60px;">保存</a-button>
  113. </a-form-model-item>
  114. </a-form-model>
  115. </a-card>
  116. </a-spin>
  117. </div>
  118. </template>
  119. <script>
  120. import { commonMixin } from '@/utils/mixin'
  121. import { STable, VSelect } from '@/components'
  122. import custType from '@/views/common/custType.js'
  123. import AreaList from '@/views/common/areaList.js'
  124. import dealerList from '@/views/common/dealerList'
  125. import { custSave, custFindById, settleStyleFindAllList } from '@/api/customer'
  126. export default {
  127. name: 'CustomerManagementEdit',
  128. components: { STable, VSelect, custType, AreaList, dealerList },
  129. mixins: [commonMixin],
  130. props: {
  131. model: {
  132. type: String,
  133. default: 'page'
  134. }
  135. },
  136. data () {
  137. return {
  138. spinning: false,
  139. formItemLayout: {
  140. labelCol: { span: 9 },
  141. wrapperCol: { span: 14 }
  142. },
  143. form: {
  144. id: null,
  145. customerName: '', // 客户名称
  146. contactTel: '', // 联系电话
  147. contactMobile: '', // 联系手机
  148. contactName: '', // 联系人
  149. provinceSn: undefined, // 省
  150. provinceName: '',
  151. citySn: undefined, // 市
  152. cityName: '',
  153. countySn: undefined, // 区
  154. countyName: '',
  155. customerAddr: '', // 详细地址
  156. fax: '', // 客户传真
  157. dispatchType: '', // 配送方式
  158. satelliteFlag: 0, // 是否卫星仓客户
  159. relationTypeDictValue: undefined, // 客户关系
  160. customerTypeSn: undefined, // 客户类型
  161. priceType: '', // 价格类型
  162. settleStyleSn: undefined, // 收款方式
  163. dealerSn: undefined // 关联经销商
  164. },
  165. dealerName: undefined, // 关联经销商名称
  166. areaVal: [],
  167. rules: {
  168. customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  169. contactMobile: [{ required: false, pattern: /^\d{11}$/, message: '请输入正确的手机号', trigger: 'blur' }],
  170. countySn: [{ required: true, message: '请选择客户地址', trigger: 'change' }],
  171. priceType: [{ required: true, message: '请选择价格类型', trigger: 'change' }],
  172. settleStyleSn: [{ required: true, message: '请选择收款方式', trigger: 'change' }]
  173. },
  174. addrProvinceList: [], // 省下拉
  175. addrCityList: [], // 市下拉
  176. addrDistrictList: [], // 区下拉
  177. settleStyleList: [] // 收款方式 下拉数据
  178. }
  179. },
  180. methods: {
  181. dealerChange (v, row) {
  182. if (row && row.dealerSn) {
  183. this.form.dealerSn = row.dealerSn
  184. this.dealerName = undefined
  185. } else {
  186. this.dealerName = v
  187. this.form.dealerSn = undefined
  188. }
  189. },
  190. filterEmpty () {
  191. let str = this.form.customerName
  192. str = str.replace(/\ +/g, '')
  193. str = str.replace(/[ ]/g, '')
  194. str = str.replace(/[\r\n]/g, '')
  195. this.form.customerName = str
  196. },
  197. areaChange (val, opts) {
  198. console.log(opts)
  199. this.form.provinceSn = val[0] ? val[0] : undefined
  200. this.form.provinceName = opts[0] ? opts[0].name : ''
  201. this.form.citySn = val[1] ? val[1] : undefined
  202. this.form.cityName = opts[1] ? opts[1].name : ''
  203. this.form.countySn = val[2] ? val[2] : undefined
  204. this.form.countyName = opts[2] ? opts[2].name : ''
  205. },
  206. // 获取客户信息
  207. getDetail () {
  208. const _this = this
  209. custFindById({ id: this.$route.params.id }).then(res => {
  210. if (res.status == 200) {
  211. res.data.satelliteFlag = res.data.dealerFlag
  212. if (res.data.dealer && Object.keys(res.data.dealer).length > 0) {
  213. if (res.data.relationType === 'customer') {
  214. _this.$refs.dealerList.setData({ key: res.data.dealer.dealerSn, label: res.data.dealer.dealerName, row: res.data.dealer })
  215. } else {
  216. _this.$refs.dealerList1.setData({ key: res.data.dealer.dealerSn, label: res.data.dealer.dealerName, row: res.data.dealer })
  217. }
  218. }
  219. _this.form = Object.assign(this.form, res.data)
  220. _this.areaVal = [res.data.provinceSn, res.data.citySn, res.data.countySn]
  221. } else {
  222. _this.$refs.ruleForm.resetFields()
  223. }
  224. })
  225. },
  226. // 收款方式
  227. getSettleStyleList () {
  228. settleStyleFindAllList().then(res => {
  229. if (res.status == 200) {
  230. this.settleStyleList = res.data
  231. } else {
  232. this.settleStyleList = []
  233. }
  234. })
  235. },
  236. // 保存
  237. handleSubmit (e) {
  238. e.preventDefault()
  239. const _this = this
  240. this.$refs.ruleForm.validate(valid => {
  241. if (valid) {
  242. const form = JSON.stringify(_this.form)
  243. const formInfo = JSON.parse(form)
  244. delete formInfo.satelliteFlag
  245. formInfo.id = this.$route.params.id && this.model == 'page' ? this.$route.params.id : null
  246. _this.spinning = true
  247. custSave(formInfo).then(res => {
  248. if (res.status == 200) {
  249. _this.$message.success(res.message)
  250. if (_this.model == 'page') {
  251. setTimeout(() => {
  252. _this.handleBack()
  253. }, 600)
  254. } else {
  255. _this.$emit('ok', res.data)
  256. }
  257. _this.spinning = false
  258. } else {
  259. _this.spinning = false
  260. }
  261. })
  262. } else {
  263. console.log('error submit!!')
  264. return false
  265. }
  266. })
  267. },
  268. // 返回列表
  269. handleBack () {
  270. this.$router.push({ name: 'customerInfo' })
  271. },
  272. // 获取基础数据
  273. getBaseData () {
  274. this.getSettleStyleList() // 收款方式
  275. this.$refs.ruleForm.resetFields()
  276. },
  277. initPage () {
  278. this.getBaseData()
  279. if (this.$route.params.id) {
  280. // 编辑页
  281. this.getDetail()
  282. }
  283. }
  284. },
  285. mounted () {
  286. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  287. this.initPage()
  288. }
  289. },
  290. activated () {
  291. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  292. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  293. this.initPage()
  294. }
  295. },
  296. beforeRouteEnter (to, from, next) {
  297. next(vm => {})
  298. }
  299. }
  300. </script>
  301. <style lang="less">
  302. .customerManagementEdit-wrap {
  303. height: 100%;
  304. >.ant-spin-nested-loading{
  305. height: calc(100% - 52px);
  306. overflow-y: auto;
  307. .ant-spin-container{
  308. height: 97%;
  309. }
  310. }
  311. .customerManagementEdit-back {
  312. margin-bottom: 10px;
  313. }
  314. .customerManagementEdit-table-page-wrapper{
  315. height: 100%;
  316. }
  317. }
  318. </style>