addbond.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div>
  3. <a-modal
  4. centered
  5. wrapClassName="addbond-modal"
  6. :footer="null"
  7. :maskClosable="false"
  8. :title="titleText"
  9. v-model="isshow"
  10. @cancle="isshow=false"
  11. :width="650">
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="addbond-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol"
  20. >
  21. <a-row :gutter="24">
  22. <a-col :span="20">
  23. <a-form-model-item label="货架名称" prop="shelfSn" >
  24. <shelfList ref="shelfList" @change="shelfChange" v-if="!nowData" id="addbond-shelfName"></shelfList>
  25. <span v-if="nowData">{{ form.shelfName||'--' }}</span>
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :span="20" v-if="form.shelfSn||nowData">
  29. <a-form-model-item label="配件经销商" prop="dealerSn" >
  30. <span>{{ dealerName||'' }}</span>
  31. </a-form-model-item>
  32. </a-col>
  33. <a-col :span="20" v-if="form.shelfSn||nowData">
  34. <a-form-model-item label="汽车修理厂" prop="storeSn">
  35. <span>{{ storeName ||'' }}</span>
  36. </a-form-model-item>
  37. </a-col>
  38. </a-row>
  39. <a-row :gutter="24">
  40. <a-col :span="20">
  41. <a-form-model-item label="保证金缴纳金额" prop="bondAmount" >
  42. <a-input-number
  43. id="addbond-bondAmount"
  44. v-model="form.bondAmount"
  45. :precision="2"
  46. :min="0.01"
  47. :max="999999"
  48. placeholder="请输入正数(最多允许两位小数)"
  49. style="width: 100%;display: inline-block;" />
  50. </a-form-model-item>
  51. </a-col>
  52. <a-col :span="2"> <span style="display: inline-block; padding-top: 10px;">元</span></a-col>
  53. </a-row>
  54. <a-form-model-item :label-col="{span: 0}" :wrapper-col="{span: 24}" style="text-align: center;">
  55. <a-button type="primary" @click="handleSubmit()" :style="{ marginRight: '8px' }" id="addbond-handleSubmit">保存</a-button>
  56. <a-button :style="{ marginLeft: '8px' }" @click="isshow=false" id="addbond-close">取消</a-button>
  57. </a-form-model-item>
  58. </a-form-model>
  59. </a-spin>
  60. </a-modal>
  61. </div>
  62. </template>
  63. <script>
  64. import { STable, VSelect, Upload } from '@/components'
  65. import { shelfDetail } from '@/api/shelf.js'
  66. import { bondRecordDetail, saveBondRecord } from '@/api/boundRecord.js'
  67. import dealerList from '@/views/common/dealerList.vue'
  68. import storeList from '@/views/common/storeList.vue'
  69. import shelfList from '@/views/common/shelfList.vue'
  70. export default {
  71. name: 'Addbond',
  72. components: { STable, VSelect, Upload, dealerList, storeList, shelfList },
  73. props: {
  74. visible: {
  75. type: Boolean,
  76. default: false
  77. },
  78. nowData: {
  79. type: Object,
  80. default: function () {
  81. return null
  82. }
  83. }
  84. },
  85. data () {
  86. return {
  87. spinning: false,
  88. titleText: '新增保证金',
  89. isshow: this.visible,
  90. roleList: [],
  91. pageInfo: null,
  92. formItemLayout: {
  93. labelCol: { span: 10 },
  94. wrapperCol: { span: 14 }
  95. },
  96. dealerName: '',
  97. shelfName: '',
  98. storeName: '',
  99. form: {
  100. dealerSn: undefined, // 经销商sn
  101. bondAmount: '', // 保证金金额
  102. storeSn: undefined, // 汽车修理厂sn
  103. shelfSn: '' // 货架名称
  104. },
  105. rules: {
  106. shelfSn: [ { required: true, message: '请选择货架名称', trigger: 'change' } ],
  107. dealerSn: [ { required: true, message: '请选择配件经销商', trigger: 'change' } ],
  108. storeSn: [ { required: true, message: '请选择汽车修理厂', trigger: 'change' } ],
  109. bondAmount: [ { required: true, message: '请输入保证金金额', trigger: 'blur' } ]
  110. }
  111. }
  112. },
  113. methods: {
  114. // 过滤空格
  115. filterEmpty () {
  116. let str = this.form.name
  117. str = str.replace(/\ +/g, '')
  118. str = str.replace(/[ ]/g, '')
  119. str = str.replace(/[\r\n]/g, '')
  120. this.form.name = str
  121. },
  122. // 货架名称 change
  123. shelfChange (obj) {
  124. this.spinning = true
  125. this.form.shelfSn = obj.key || undefined
  126. if (this.form.shelfSn) {
  127. setTimeout(() => {
  128. this.getShelfDetail(this.form.shelfSn)
  129. }, 300)
  130. }
  131. },
  132. // 经销商 change
  133. dealerChange (obj) {
  134. this.form.dealerSn = obj.key || undefined
  135. },
  136. // 汽车修理厂 change
  137. storeChange (obj) {
  138. this.form.storeSn = obj.key || undefined
  139. },
  140. // 查询货架详情
  141. getShelfDetail (val) {
  142. this.spinning = true
  143. shelfDetail({ shelfSn: val }).then(res => {
  144. if (res.status == 200) {
  145. this.dealerName = res.data.dealerName
  146. this.shelfName = res.data.shelfName
  147. this.storeName = res.data.storeName
  148. this.form = Object.assign({}, res.data)
  149. console.log(this.dealerName, this.storeName, this.form, 'this.form ')
  150. } else {
  151. this.form = { }
  152. }
  153. this.spinning = false
  154. })
  155. },
  156. // 保证金详情
  157. getBoundDetail () {
  158. this.spinning = true
  159. bondRecordDetail({ bondRecordSn: this.nowData ? this.nowData.bondRecordSn : '' }).then(res => {
  160. if (res.status == 200) {
  161. this.dealerName = res.data.dealerName
  162. this.shelfName = res.data.shelfName
  163. this.storeName = res.data.storeName
  164. this.form.bondAmount = res.data.bondAmount
  165. this.form = Object.assign({}, res.data)
  166. } else {
  167. }
  168. this.spinning = false
  169. })
  170. },
  171. // 保存提交
  172. handleSubmit () {
  173. const _this = this
  174. this.$refs.ruleForm.validate(valid => {
  175. if (valid) {
  176. const params = JSON.parse(JSON.stringify(_this.form))
  177. params.id = _this.nowData && _this.nowData.id ? _this.nowData.id : null
  178. _this.spinning = true
  179. saveBondRecord(params).then(res => {
  180. if (res.status == 200) {
  181. _this.$message.success(res.message)
  182. _this.$emit('refresh')
  183. setTimeout(function () {
  184. _this.isshow = false
  185. _this.spinning = false
  186. }, 300)
  187. } else {
  188. _this.spinning = false
  189. }
  190. })
  191. } else {
  192. console.log('error submit!!')
  193. return false
  194. }
  195. })
  196. }
  197. },
  198. watch: {
  199. visible (newValue, oldValue) {
  200. this.isshow = newValue
  201. },
  202. isshow (newValue, oldValue) {
  203. if (!newValue) {
  204. this.form = {
  205. dealerSn: undefined, // 经销商sn
  206. bondAmount: '', // 保证金金额
  207. storeSn: undefined, // 汽车修理厂sn
  208. shelfSn: '' // 货架名称
  209. }
  210. this.dealerName = ''
  211. this.shelfName = ''
  212. this.storeName =
  213. this.$emit('close')
  214. this.$refs.ruleForm.resetFields()
  215. this.titleText = '新增保证金'
  216. }
  217. },
  218. nowData: {
  219. handler (newValue, oldValue) {
  220. if (this.isshow && newValue) {
  221. if (this.nowData.id) { // 编辑
  222. this.titleText = '编辑保证金'
  223. this.getBoundDetail()
  224. } else {
  225. this.titleText = '新增保证金'
  226. }
  227. }
  228. },
  229. deep: true
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="less">
  235. .addGoodsShelve-modal{
  236. .ant-select-disabled .ant-select-selection{
  237. background-color: none !important;
  238. }
  239. }
  240. </style>