basicInfoModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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" v-if="systemFlag==1">
  31. <v-select
  32. code="ORDER_TYPE"
  33. id="purchaseOrder-basicInfo-orderType"
  34. v-model="form.orderType"
  35. allowClear
  36. placeholder="请选择订单类型"
  37. showType="radio"
  38. ></v-select>
  39. </a-form-model-item>
  40. <a-form-model-item label="支付方式" prop="settleStyleSn">
  41. <v-select
  42. code="OFFLINE_SETTLE_STYLE"
  43. id="purchaseOrder-basicInfo-settleStyleSn"
  44. v-model="form.settleStyleSn"
  45. allowClear
  46. placeholder="请选择支付方式"
  47. ></v-select>
  48. </a-form-model-item>
  49. <a-form-model-item label="收货地址" prop="consigneeTel">
  50. {{ chooseAddr }}
  51. <a-button type="link" id="purchaseOrder-basicInfo-chooseAddr" @click="handleChoose">{{ addressVal }} >></a-button>
  52. </a-form-model-item>
  53. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  54. <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  55. <a-button @click="isShow=false" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
  56. </a-form-model-item>
  57. </a-form-model>
  58. </a-spin>
  59. <!-- 选择地址 -->
  60. <choose-address-modal :openModal="openAddrModal" @ok="handleOk" @verify="verifyFun" @close="openAddrModal=false" />
  61. </a-modal>
  62. </template>
  63. <script>
  64. import { commonMixin } from '@/utils/mixin'
  65. import { VSelect } from '@/components'
  66. import chooseAddressModal from '@/views/common/receivingAddress/chooseAddressModal.vue'
  67. import { shippingAddressQuery } from '@/api/shippingAddress'
  68. import { purchaseSave, purchaseTargetList } from '@/api/purchase'
  69. import { getParamValue } from '@/api/data'
  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. systemFlag: null// 订单类型显示不显示
  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. if (this.systemFlag == 1) {
  148. this.form.orderType = 'OTHER'
  149. }
  150. },
  151. // 保存
  152. handleSubmit (e) {
  153. e.preventDefault()
  154. const _this = this
  155. this.$refs.ruleForm.validate(valid => {
  156. if (valid) {
  157. if (_this.form.consigneeTel == '') {
  158. _this.$message.info('请选择收货地址')
  159. return false
  160. }
  161. _this.spinning = true
  162. purchaseSave(_this.form).then(res => {
  163. if (res.status == 200) {
  164. _this.isShow = false
  165. _this.$emit('ok', res.data)
  166. _this.spinning = false
  167. _this.$message.info(res.message)
  168. } else {
  169. _this.spinning = false
  170. }
  171. })
  172. } else {
  173. return false
  174. }
  175. })
  176. },
  177. // 选择地址
  178. handleChoose () {
  179. this.openAddrModal = true
  180. },
  181. // 地址保存
  182. handleOk (data) {
  183. this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '--') + ')' + ' ' + (data.address || '')
  184. this.addressVal = '更换地址'
  185. this.form.shippingAddressProvinceName = data.provinceName // 省
  186. this.form.shippingAddressCityName = data.cityName // 市
  187. this.form.shippingAddressCountyName = data.countyName // 区
  188. this.form.shippingAddress = data.addr// 详细地址
  189. this.form.consigneeTel = data.consigneeTel // 联系电话
  190. this.form.consigneeName = data.consigneeName
  191. this.openAddrModal = false
  192. },
  193. // 编辑信息
  194. setData (data) {
  195. this.form = JSON.parse(JSON.stringify(data))
  196. this.chooseAddr = data.consigneeName + '(' + (data.consigneeTel || '--') + ')' + ' ' + data.shippingAddressProvinceName + '-' + data.shippingAddressCityName + '-' + data.shippingAddressCountyName + ' ' + data.shippingAddress
  197. this.addressVal = '更换地址'
  198. },
  199. // 获取供应商列表
  200. getParentDealer () {
  201. const zb = this.$hasPermissions('B_SUPPLIER_ZB')
  202. const sj = this.$hasPermissions('B_SUPPLIER_SJ')
  203. let params = {}
  204. // 只能向上级采购
  205. if (sj) {
  206. params.purchaseTargetType = 'DEALER_UP'
  207. }
  208. // 只能向总部采购
  209. if (zb) {
  210. params.purchaseTargetType = 'SUPPLIER_SYS'
  211. }
  212. // 总部和上级都可以
  213. if (sj && zb) {
  214. params = {}
  215. }
  216. purchaseTargetList(params).then(res => {
  217. if (res.status == 200 && res.data[0]) {
  218. const purchaseList = res.data
  219. purchaseList.map(item => {
  220. if (item.purchaseTargetType === 'DEALER_SUPPLIER') {
  221. item.purchaseTargetNameInfo = item.purchaseTargetName + '(省仓)'
  222. } else {
  223. item.purchaseTargetNameInfo = item.purchaseTargetName
  224. }
  225. return item
  226. })
  227. if (this.systemFlag == 1) {
  228. this.form.purchaseTargetSn = purchaseList[0].purchaseTargetSn
  229. this.form.purchaseTargetName = purchaseList[0].purchaseTargetName
  230. this.form.purchaseTargetType = purchaseList[0].purchaseTargetType
  231. this.form.orderType = 'OTHER'
  232. }
  233. this.purchaseTragetType = purchaseList
  234. } else {
  235. this.purchaseTragetType = []
  236. }
  237. })
  238. },
  239. // 获取系统参数 判断是否显示订单类型
  240. getSystemInfo () {
  241. getParamValue({ code: 'TIRE_OPEN' }).then(res => {
  242. if (res.status == 200) {
  243. this.systemFlag = res.data
  244. this.$nextTick(() => {
  245. this.getParentDealer()
  246. })
  247. }
  248. })
  249. },
  250. // 获取默认地址
  251. getDefaultAddress () {
  252. shippingAddressQuery({ defaultFlag: 1 }).then(res => {
  253. if (res.status == 200) {
  254. if (res.data.length == 1) {
  255. res.data[0].address = ''
  256. if (res.data[0].provinceName) {
  257. res.data[0].address += res.data[0].provinceName + '-'
  258. }
  259. if (res.data[0].cityName) {
  260. res.data[0].address += res.data[0].cityName + '-'
  261. }
  262. if (res.data[0].countyName) {
  263. res.data[0].address += res.data[0].countyName + '-'
  264. }
  265. res.data[0].address += res.data[0].addr
  266. this.addressId = res.data[0].id || undefined
  267. this.handleOk(res.data[0])
  268. }
  269. }
  270. })
  271. },
  272. // 重置地址信息
  273. verifyFun (id) {
  274. if (id == this.addressId) {
  275. this.chooseAddr = ''
  276. this.addressVal = '选择地址'
  277. this.form.shippingAddressProvinceName = ''// 省
  278. this.form.shippingAddressCityName = '' // 市
  279. this.form.shippingAddressCountyName = '' // 区
  280. this.form.shippingAddress = ''// 详细地址
  281. this.form.consigneeTel = '' // 联系电话
  282. this.form.consigneeName = ''
  283. }
  284. }
  285. },
  286. watch: {
  287. // 父页面传过来的弹框状态
  288. openModal (newValue, oldValue) {
  289. this.isShow = newValue
  290. },
  291. // 重定义的弹框状态
  292. isShow (newValue, oldValue) {
  293. if (!newValue) {
  294. this.$emit('close')
  295. this.resetForm()
  296. } else {
  297. this.getDefaultAddress()
  298. this.getSystemInfo()
  299. }
  300. }
  301. }
  302. }
  303. </script>
  304. <style lang="less">
  305. .purchaseOrder-basicInfo-modal{
  306. .ant-modal-body {
  307. padding: 40px 40px 24px;
  308. }
  309. .radio-s{
  310. margin-bottom: 8px;
  311. }
  312. .btn-cont {
  313. text-align: center;
  314. margin: 35px 0 10px;
  315. }
  316. }
  317. </style>