basicInfoModal.vue 11 KB

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