editModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <a-modal
  3. centered
  4. class="supplierInfoEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="800">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <!-- 表单 -->
  13. <div>
  14. <a-form-model
  15. id="supplierInfoEdit-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol"
  21. >
  22. <a-form-model-item label="供应商名称" prop="supplierName">
  23. <a-input
  24. id="supplierInfoEdit-supplierName"
  25. :maxLength="30"
  26. v-model.trim="form.supplierName"
  27. @change="filterEmpty"
  28. placeholder="请输入供应商名称(最多30个字符)"
  29. allowClear />
  30. </a-form-model-item>
  31. <a-form-model-item label="所在地区" required style="margin: 0;">
  32. <a-row :gutter="20">
  33. <!-- 所在地区 -->
  34. <a-col span="8">
  35. <a-form-model-item prop="provinceSn">
  36. <a-select id="supplierInfoEdit-provinceSn" allowClear @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
  37. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  38. </a-select>
  39. </a-form-model-item>
  40. </a-col>
  41. <a-col span="8">
  42. <a-form-model-item prop="citySn">
  43. <a-select id="supplierInfoEdit-citySn" allowClear @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
  44. <a-select-option v-for="item in addrCityList" :value="item.areaSn" :key="item.areaSn + 'b'">{{ item.name }}</a-select-option>
  45. </a-select>
  46. </a-form-model-item>
  47. </a-col>
  48. <a-col span="8">
  49. <a-form-model-item prop="countySn">
  50. <a-select id="supplierInfoEdit-countySn" allowClear @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
  51. <a-select-option v-for="item in addrDistrictList" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
  52. </a-select>
  53. </a-form-model-item>
  54. </a-col>
  55. </a-row>
  56. </a-form-model-item>
  57. <a-form-model-item label="详细地址" prop="supplierAddress">
  58. <a-input
  59. id="supplierInfoEdit-supplierAddress"
  60. :maxLength="60"
  61. v-model="form.supplierAddress"
  62. placeholder="请输入详细地址(最多60个字符)"
  63. allowClear />
  64. </a-form-model-item>
  65. <a-form-model-item label="联系人" prop="contactPerson">
  66. <a-input
  67. id="supplierInfoEdit-contactPerson"
  68. :maxLength="30"
  69. v-model="form.contactPerson"
  70. placeholder="请输入联系人(最多30个字符)"
  71. allowClear />
  72. </a-form-model-item>
  73. <a-form-model-item label="联系电话" prop="contactTel">
  74. <a-input
  75. id="supplierInfoEdit-contactTel"
  76. :maxLength="20"
  77. v-model="form.contactTel"
  78. placeholder="请输入联系电话(最多20个字符)"
  79. allowClear />
  80. </a-form-model-item>
  81. <a-form-model-item label="主营内容" prop="businessScope">
  82. <a-textarea
  83. id="supplierInfoEdit-businessScope"
  84. :maxLength="200"
  85. v-model="form.businessScope"
  86. placeholder="请输入主营内容(最多200个字符)"
  87. allowClear />
  88. </a-form-model-item>
  89. <a-form-model-item label="状态" prop="enabledFlag" v-if="isState">
  90. <a-radio-group
  91. name="radioGroup"
  92. v-model="form.enabledFlag"
  93. id="supplierInfoEdit-enabledFlag" >
  94. <a-radio :value="1">启用</a-radio>
  95. <a-radio :value="0">禁用</a-radio>
  96. </a-radio-group>
  97. </a-form-model-item>
  98. </a-form-model>
  99. <div class="btn-cont">
  100. <a-button type="primary" id="supplierInfoEdit-btn-submit" @click="handleSubmit">保存</a-button>
  101. <a-button id="supplierInfoEdit-btn-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
  102. </div>
  103. </div>
  104. </a-spin>
  105. </a-modal>
  106. </template>
  107. <script>
  108. import { getArea } from '@/api/data'
  109. import { supplierDetail, supplierSave } from '@/api/supplier'
  110. export default {
  111. name: 'SupplierInfoEditModal',
  112. props: {
  113. openModal: { // 弹框显示状态
  114. type: Boolean,
  115. default: false
  116. },
  117. itemId: {
  118. type: [Number, String],
  119. default: ''
  120. },
  121. isState: { // 是否显示状态
  122. type: Boolean,
  123. default: true
  124. }
  125. },
  126. computed: {
  127. modalTit () {
  128. return this.itemId ? '编辑' : '新增'
  129. }
  130. },
  131. data () {
  132. return {
  133. spinning: false,
  134. isShow: this.openModal, // 是否打开弹框
  135. formItemLayout: {
  136. labelCol: { span: 6 },
  137. wrapperCol: { span: 16 }
  138. },
  139. form: {
  140. supplierName: '', // 供应商名称
  141. provinceSn: undefined, // 省
  142. provinceName: '',
  143. citySn: undefined, // 市
  144. cityName: '',
  145. countySn: undefined, // 区
  146. countyName: '',
  147. supplierAddress: '', // 详细地址
  148. contactPerson: '', // 联系人
  149. contactTel: '', // 联系电话
  150. businessScope: '', // 主营内容
  151. enabledFlag: 1 // 启禁用
  152. },
  153. rules: {
  154. supplierName: [
  155. { required: true, message: '请输入供应商名称', trigger: 'blur' }
  156. ],
  157. provinceSn: [
  158. { required: true, message: '请选择省', trigger: 'change' }
  159. ],
  160. citySn: [
  161. { required: true, message: '请选择市', trigger: 'change' }
  162. ],
  163. countySn: [
  164. { required: true, message: '请选择区/县', trigger: 'change' }
  165. ],
  166. supplierAddress: [
  167. { required: true, message: '请输入详细地址', trigger: 'blur' }
  168. ],
  169. contactPerson: [
  170. { required: true, message: '请输入联系人', trigger: 'blur' }
  171. ],
  172. contactTel: [
  173. { required: true, message: '请输入联系人电话', trigger: 'blur' }
  174. ],
  175. enabledFlag: [
  176. { required: true, message: '请选择状态', trigger: 'change' }
  177. ]
  178. },
  179. addrProvinceList: [], // 省下拉
  180. addrCityList: [], // 市下拉
  181. addrDistrictList: [] // 区下拉
  182. }
  183. },
  184. methods: {
  185. filterEmpty () {
  186. let str = this.form.supplierName
  187. str = str.replace(/\ +/g, '')
  188. str = str.replace(/[ ]/g, '')
  189. str = str.replace(/[\r\n]/g, '')
  190. this.form.supplierName = str
  191. },
  192. // 获取供应商信息
  193. getDetail () {
  194. supplierDetail({ id: this.itemId }).then(res => {
  195. if (res.status == 200) {
  196. if (res.data.provinceSn) { this.getArea('city', res.data.provinceSn) }
  197. if (res.data.citySn) { this.getArea('district', res.data.citySn) }
  198. this.form = Object.assign(this.form, res.data)
  199. this.form.enabledFlag = Number(this.form.enabledFlag)
  200. }
  201. })
  202. },
  203. // 保存
  204. handleSubmit (e) {
  205. e.preventDefault()
  206. const _this = this
  207. this.$refs.ruleForm.validate(valid => {
  208. if (valid) {
  209. const form = _this.form
  210. form.id = this.itemId ? this.itemId : null
  211. _this.spinning = true
  212. supplierSave(form).then(res => {
  213. if (res.status == 200) {
  214. _this.$message.success(res.message)
  215. _this.$emit('ok')
  216. _this.isShow = false
  217. _this.spinning = false
  218. } else {
  219. _this.spinning = false
  220. }
  221. })
  222. } else {
  223. console.log('error submit!!')
  224. return false
  225. }
  226. })
  227. },
  228. // 获取城市列表
  229. getCityList (val) {
  230. this.addrCityList = []
  231. this.addrDistrictList = []
  232. this.form.citySn = undefined
  233. this.form.countySn = undefined
  234. if (val) {
  235. this.getArea('city', val)
  236. this.form.provinceName = this.addrProvinceList.find(item => item.areaSn == val).name
  237. } else {
  238. this.form.provinceName = ''
  239. }
  240. },
  241. // 获取区县列表
  242. getAreaList (val) {
  243. this.addrDistrictList = []
  244. this.form.countySn = undefined
  245. if (val) {
  246. this.getArea('district', val)
  247. this.form.cityName = this.addrCityList.find(item => item.areaSn == val).name
  248. } else {
  249. this.form.cityName = ''
  250. }
  251. },
  252. // 区县变更
  253. areaCharged (val) {
  254. if (val) {
  255. this.form.countyName = this.addrDistrictList.find(item => item.areaSn == val).name
  256. } else {
  257. this.form.countyName = ''
  258. }
  259. },
  260. // 省/市/区
  261. getArea (leve, sn) {
  262. let params
  263. if (leve == 'province') {
  264. params = { type: '2' }
  265. } else {
  266. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  267. }
  268. getArea(params).then(res => {
  269. if (res.status == 200) {
  270. if (leve == 'province') {
  271. this.addrProvinceList = res.data || []
  272. } else if (leve == 'city') {
  273. this.addrCityList = res.data || []
  274. } else if (leve == 'district') {
  275. this.addrDistrictList = res.data || []
  276. }
  277. } else {
  278. if (leve == 'province') {
  279. this.addrProvinceList = []
  280. } else if (leve == 'city') {
  281. this.addrCityList = []
  282. } else if (leve == 'district') {
  283. this.addrDistrictList = []
  284. }
  285. }
  286. })
  287. }
  288. },
  289. watch: {
  290. // 父页面传过来的弹框状态
  291. openModal (newValue, oldValue) {
  292. this.isShow = newValue
  293. },
  294. // 重定义的弹框状态
  295. isShow (newValue, oldValue) {
  296. if (!newValue) {
  297. this.$emit('close')
  298. this.$refs.ruleForm.resetFields()
  299. this.addrCityList = []
  300. this.addrDistrictList = []
  301. } else {
  302. this.getArea('province')
  303. }
  304. },
  305. itemId (newValue, oldValue) {
  306. if (this.isShow && newValue) { // 编辑
  307. this.getDetail()
  308. }
  309. }
  310. }
  311. }
  312. </script>
  313. <style lang="less">
  314. .supplierInfoEdit-modal{
  315. .ant-modal-body {
  316. padding: 40px 40px 24px;
  317. }
  318. .btn-cont {
  319. text-align: center;
  320. margin: 35px 0 10px;
  321. }
  322. }
  323. </style>