edit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 id="customerManagementEdit-area" 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" v-if="form.relationTypeDictValue">
  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" :id="item.settleStyleSn" :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. // 过滤空格
  175. filterEmpty () {
  176. let str = this.form.customerName
  177. str = str.replace(/\ +/g, '')
  178. str = str.replace(/[ ]/g, '')
  179. str = str.replace(/[\r\n]/g, '')
  180. this.form.customerName = str
  181. },
  182. // 选择地区
  183. areaChange (val, opts) {
  184. this.form.provinceSn = val[0] ? val[0] : undefined
  185. this.form.provinceName = opts[0] ? opts[0].name : ''
  186. this.form.citySn = val[1] ? val[1] : undefined
  187. this.form.cityName = opts[1] ? opts[1].name : ''
  188. this.form.countySn = val[2] ? val[2] : undefined
  189. this.form.countyName = opts[2] ? opts[2].name : ''
  190. },
  191. // 获取客户信息
  192. getDetail () {
  193. custFindById({ id: this.$route.params.id }).then(res => {
  194. if (res.status == 200) {
  195. res.data.satelliteFlag = res.data.dealerFlag
  196. this.form = Object.assign(this.form, res.data)
  197. this.areaVal = [res.data.provinceSn, res.data.citySn, res.data.countySn]
  198. } else {
  199. this.$refs.ruleForm.resetFields()
  200. }
  201. })
  202. },
  203. // 收款方式
  204. getSettleStyleList () {
  205. settleStyleFindAllList().then(res => {
  206. if (res.status == 200) {
  207. this.settleStyleList = res.data
  208. } else {
  209. this.settleStyleList = []
  210. }
  211. })
  212. },
  213. // 保存
  214. handleSubmit (e) {
  215. e.preventDefault()
  216. const _this = this
  217. this.$refs.ruleForm.validate(valid => {
  218. if (valid) {
  219. const form = JSON.stringify(_this.form)
  220. const formInfo = JSON.parse(form)
  221. delete formInfo.satelliteFlag
  222. formInfo.id = this.$route.params.id && this.model == 'page' ? this.$route.params.id : null
  223. _this.spinning = true
  224. custSave(formInfo).then(res => {
  225. if (res.status == 200) {
  226. _this.$message.success(res.message)
  227. if (_this.model == 'page') {
  228. setTimeout(() => {
  229. _this.handleBack()
  230. }, 600)
  231. } else {
  232. _this.$emit('ok', res.data)
  233. }
  234. _this.spinning = false
  235. } else {
  236. _this.spinning = false
  237. }
  238. })
  239. } else {
  240. return false
  241. }
  242. })
  243. },
  244. // 返回列表
  245. handleBack () {
  246. this.$router.push({ path: '/customerManagement/customerInfo/list' })
  247. },
  248. // 获取基础数据
  249. getBaseData () {
  250. this.getSettleStyleList() // 收款方式
  251. this.$refs.ruleForm.resetFields()
  252. },
  253. // 初始化页面
  254. initPage () {
  255. this.getBaseData()
  256. if (this.$route.params.id) {
  257. // 编辑页
  258. this.getDetail()
  259. }
  260. }
  261. },
  262. mounted () {
  263. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  264. this.initPage()
  265. }
  266. },
  267. activated () {
  268. // 如果是新页签打开或者进入新的子页(例:存在列表第2条数据编辑页页签时再打开第4条数据的编辑页),则重置当前页面
  269. if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
  270. this.initPage()
  271. }
  272. },
  273. beforeRouteEnter (to, from, next) {
  274. next(vm => {})
  275. }
  276. }
  277. </script>
  278. <style lang="less">
  279. .customerManagementEdit-wrap {
  280. height: 100%;
  281. >.ant-spin-nested-loading{
  282. height: calc(100% - 52px);
  283. overflow-y: auto;
  284. .ant-spin-container{
  285. height: 97%;
  286. }
  287. }
  288. .customerManagementEdit-back {
  289. margin-bottom: 10px;
  290. }
  291. .customerManagementEdit-table-page-wrapper{
  292. height: 100%;
  293. }
  294. }
  295. </style>