basicInfoModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <a-modal
  3. centered
  4. class="purchaseOrder-basicInfo-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="新增采购单"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="purchaseOrder-basicInfo-form"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol" >
  19. <a-form-model-item label="供应商" prop="purchaseTargetSn">
  20. <a-radio-group
  21. name="radioGroup"
  22. v-model="form.purchaseTargetSn"
  23. @change="tragetTypeChange"
  24. v-if="purchaseTragetType.length"
  25. id="purchaseOrder-basicInfo-purchaseTargetSn" >
  26. <a-radio v-for="item in purchaseTragetType" :key="item.purchaseTargetSn" :value="item.purchaseTargetSn" class="radio-s">{{ item.purchaseTargetNameInfo }}</a-radio>
  27. </a-radio-group>
  28. <span v-else>没有可选择的供应商</span>
  29. </a-form-model-item>
  30. <a-form-model-item label="产品类型" prop="orderType">
  31. <v-select
  32. code="ORDER_TYPE"
  33. id="purchaseOrder-basicInfo-orderType"
  34. v-model="form.orderType"
  35. allowClear
  36. placeholder="请选择产品类型"
  37. :notIn="notShowIn"
  38. showType="radio"
  39. ></v-select>
  40. </a-form-model-item>
  41. <a-form-model-item label="支付方式" prop="settleStyleSn">
  42. <v-select
  43. code="SETTLE_STYLE"
  44. id="purchaseOrder-basicInfo-settleStyleSn"
  45. v-model="form.settleStyleSn"
  46. allowClear
  47. placeholder="请选择支付方式"
  48. ></v-select>
  49. </a-form-model-item>
  50. <a-form-model-item label="收货地址" prop="consigneeTel">
  51. {{ chooseAddr }}
  52. <a-button type="link" id="purchaseOrder-basicInfo-chooseAddr" @click="handleChoose">{{ addressVal }} >></a-button>
  53. </a-form-model-item>
  54. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  55. <a-button size="large" type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  56. <a-button size="large" @click="isShow=false" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
  57. </a-form-model-item>
  58. </a-form-model>
  59. </a-spin>
  60. <!-- 选择地址 -->
  61. <choose-address-modal :openModal="openAddrModal" @ok="handleOk" @verify="verifyFun" @close="openAddrModal=false" />
  62. </a-modal>
  63. </template>
  64. <script>
  65. import { commonMixin } from '@/utils/mixin'
  66. import { VSelect } from '@/components'
  67. import chooseAddressModal from '@/views/common/receivingAddress/chooseAddressModal.vue'
  68. // 接口
  69. import { shippingAddressQuery } from '@/api/shippingAddress'
  70. import { purchaseSave, purchaseTargetList } from '@/api/purchase'
  71. export default {
  72. name: 'BasicInfoModal',
  73. components: { VSelect, chooseAddressModal },
  74. mixins: [commonMixin],
  75. props: {
  76. openModal: { // 弹框显示状态
  77. type: Boolean,
  78. default: false
  79. }
  80. },
  81. data () {
  82. return {
  83. spinning: false,
  84. confirmLoading: false, // 保存按钮loading
  85. isShow: this.openModal, // 是否打开弹框
  86. formItemLayout: {
  87. labelCol: { span: 4 },
  88. wrapperCol: { span: 18 }
  89. },
  90. form: {
  91. purchaseTargetType: '', // 供应商
  92. shippingAddressProvinceName: '', // 省
  93. shippingAddressCityName: '', // 市
  94. shippingAddressCountyName: '', // 区
  95. shippingAddress: '', // 详细地址
  96. consigneeTel: '', // 联系电话
  97. consigneeName: '', // 联系人名称
  98. settleStyleSn: undefined, // 支付方式
  99. purchaseTargetSn: undefined, // 供应商
  100. purchaseTargetName: '', // 供应商名称
  101. orderType: undefined // 产品类型
  102. },
  103. rules: {
  104. purchaseTargetSn: [
  105. { required: true, message: '请选择供应商', trigger: 'change' }
  106. ],
  107. orderType: [{ required: true, message: '请选择产品类型', trigger: 'change' }],
  108. settleStyleSn: [
  109. { required: true, message: '请选择支付方式', trigger: 'change' }
  110. ],
  111. consigneeTel: [
  112. { required: true, message: '请选择收货地址(联系电话不能为空)', trigger: 'change' }
  113. ]
  114. },
  115. purchaseTragetType: [], // 采购方类型
  116. addressVal: '选择地址', // 选择地址/更换地址
  117. chooseAddr: '', // 当前已选地址信息
  118. addressId: undefined, // 地址id
  119. openAddrModal: false, // 选择地址弹框是否显示
  120. notShowIn: []// 产品类型不显示
  121. }
  122. },
  123. methods: {
  124. // 重置表单
  125. resetForm () {
  126. this.$refs.ruleForm.resetFields()
  127. this.chooseAddr = ''
  128. this.addressVal = '选择地址'
  129. this.form.shippingAddressProvinceName = ''// 省
  130. this.form.shippingAddressCityName = '' // 市
  131. this.form.shippingAddressCountyName = '' // 区
  132. this.form.shippingAddress = ''// 详细地址
  133. this.form.consigneeTel = '' // 联系电话
  134. this.form.consigneeName = ''
  135. this.form.purchaseTargetType = ''
  136. this.form.purchaseTargetSn = undefined
  137. this.form.purchaseTargetName = ''
  138. this.form.orderType = undefined
  139. },
  140. // 供应商change
  141. tragetTypeChange (e) {
  142. const val = e.target.value
  143. const ind = this.purchaseTragetType.findIndex(item => item.purchaseTargetSn == val)
  144. if (ind != -1) {
  145. this.form.purchaseTargetType = this.purchaseTragetType[ind].purchaseTargetType
  146. this.form.purchaseTargetName = this.purchaseTragetType[ind].purchaseTargetName
  147. }
  148. // 经销商向“上级”或“省仓”采购时,默认勾选“非轮胎产品”,不显示轮胎产品
  149. if (this.form.purchaseTargetType != 'SUPPLIER_SYS') {
  150. this.notShowIn = ['TIRE']
  151. this.form.orderType = 'OTHER'
  152. } else {
  153. this.notShowIn = []
  154. this.form.orderType = undefined
  155. }
  156. },
  157. // 保存
  158. handleSubmit (e) {
  159. e.preventDefault()
  160. const _this = this
  161. this.$refs.ruleForm.validate(valid => {
  162. if (valid) {
  163. if (_this.form.consigneeTel == '') {
  164. _this.$message.info('请选择收货地址')
  165. return false
  166. }
  167. _this.spinning = true
  168. purchaseSave(_this.form).then(res => {
  169. if (res.status == 200) {
  170. _this.isShow = false
  171. _this.$emit('ok', res.data)
  172. _this.spinning = false
  173. _this.$message.info(res.message)
  174. } else {
  175. _this.spinning = false
  176. }
  177. })
  178. } else {
  179. return false
  180. }
  181. })
  182. },
  183. // 选择地址
  184. handleChoose () {
  185. this.openAddrModal = true
  186. },
  187. // 地址保存
  188. handleOk (data) {
  189. this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '--') + ')' + ' ' + (data.address || '')
  190. this.addressVal = '更换地址'
  191. this.form.shippingAddressProvinceName = data.provinceName // 省
  192. this.form.shippingAddressCityName = data.cityName // 市
  193. this.form.shippingAddressCountyName = data.countyName // 区
  194. this.form.shippingAddress = data.addr// 详细地址
  195. this.form.consigneeTel = data.consigneeTel // 联系电话
  196. this.form.consigneeName = data.consigneeName
  197. this.openAddrModal = false
  198. },
  199. // 编辑信息
  200. setData (data) {
  201. this.form = JSON.parse(JSON.stringify(data))
  202. this.chooseAddr = data.consigneeName + '(' + (data.consigneeTel || '--') + ')' + ' ' + data.shippingAddressProvinceName + '-' + data.shippingAddressCityName + '-' + data.shippingAddressCountyName + ' ' + data.shippingAddress
  203. this.addressVal = '更换地址'
  204. },
  205. // 获取上级经销商列表
  206. getParentDealer () {
  207. const zb = this.$hasPermissions('B_SUPPLIER_ZB')
  208. const sj = this.$hasPermissions('B_SUPPLIER_SJ')
  209. let params = {}
  210. // 只能向上级采购
  211. if (sj) {
  212. params.purchaseTargetType = 'DEALER_UP'
  213. }
  214. // 只能向总部采购
  215. if (zb) {
  216. params.purchaseTargetType = 'SUPPLIER_SYS'
  217. }
  218. // 总部和上级都可以
  219. if (sj && zb) {
  220. params = {}
  221. }
  222. purchaseTargetList(params).then(res => {
  223. if (res.status == 200 && res.data[0]) {
  224. const purchaseList = res.data
  225. purchaseList.map(item => {
  226. if (item.purchaseTargetType === 'DEALER_SUPPLIER') {
  227. item.purchaseTargetNameInfo = item.purchaseTargetName + '(省仓)'
  228. } else {
  229. item.purchaseTargetNameInfo = item.purchaseTargetName
  230. }
  231. return item
  232. })
  233. this.purchaseTragetType = purchaseList
  234. } else {
  235. this.purchaseTragetType = []
  236. }
  237. })
  238. },
  239. // 获取默认地址
  240. getDefaultAddress () {
  241. shippingAddressQuery({ defaultFlag: 1 }).then(res => {
  242. if (res.status == 200) {
  243. if (res.data.length == 1) {
  244. res.data[0].address = ''
  245. if (res.data[0].provinceName) {
  246. res.data[0].address += res.data[0].provinceName + '-'
  247. }
  248. if (res.data[0].cityName) {
  249. res.data[0].address += res.data[0].cityName + '-'
  250. }
  251. if (res.data[0].countyName) {
  252. res.data[0].address += res.data[0].countyName + '-'
  253. }
  254. res.data[0].address += res.data[0].addr
  255. this.addressId = res.data[0].id || undefined
  256. this.handleOk(res.data[0])
  257. }
  258. }
  259. })
  260. },
  261. // 重置地址
  262. verifyFun (id) {
  263. if (id == this.addressId) {
  264. this.chooseAddr = ''
  265. this.addressVal = '选择地址'
  266. this.form.shippingAddressProvinceName = ''// 省
  267. this.form.shippingAddressCityName = '' // 市
  268. this.form.shippingAddressCountyName = '' // 区
  269. this.form.shippingAddress = ''// 详细地址
  270. this.form.consigneeTel = '' // 联系电话
  271. this.form.consigneeName = ''
  272. }
  273. }
  274. },
  275. watch: {
  276. // 父页面传过来的弹框状态
  277. openModal (newValue, oldValue) {
  278. this.isShow = newValue
  279. },
  280. // 重定义的弹框状态
  281. isShow (newValue, oldValue) {
  282. if (!newValue) {
  283. this.$emit('close')
  284. this.resetForm()
  285. } else {
  286. // 获取上级列表
  287. this.getParentDealer()
  288. // 获取默认地址
  289. this.getDefaultAddress()
  290. }
  291. }
  292. }
  293. }
  294. </script>
  295. <style lang="less">
  296. .purchaseOrder-basicInfo-modal{
  297. .ant-modal-body {
  298. padding: 40px 40px 24px;
  299. }
  300. .radio-s{
  301. margin-bottom: 8px;
  302. }
  303. .btn-cont {
  304. text-align: center;
  305. margin: 35px 0 10px;
  306. }
  307. }
  308. </style>