edit.vue 12 KB

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