editModal.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <a-modal
  3. centered
  4. class="productPricingEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="编辑价格"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <!-- 编辑价格 -->
  12. <div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <a-form-model
  15. id="productPricingEdit-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="成本价">
  23. <div v-if="detailData && detailData.supplierProductList" style="margin-top: 8px;">
  24. <p v-for="(item, index) in detailData.supplierProductList" :key="index" style="margin: 0;line-height: 1.5em;">{{ ((item.cost || item.cost==0) ? item.cost.toFixed(2) : '--') + ' 元 -- ' + (item.supplierName||'') + ';' }}</p>
  25. </div>
  26. <span v-else>--</span>
  27. </a-form-model-item>
  28. <a-form-model-item label="省级价" prop="afterProvincePrice">
  29. <a-input-number
  30. id="productPricingEdit-afterProvincePrice"
  31. v-model="form.afterProvincePrice"
  32. :precision="2"
  33. :min="0.01"
  34. :max="999999"
  35. placeholder="请输入省级价"
  36. ref="afterProvincePrice"
  37. @keydown.enter.native="nextFocus('afterProvincePrice', 'afterCityPrice', $event)"
  38. style="width: 100%;" />
  39. </a-form-model-item>
  40. <a-form-model-item label="市级价" prop="afterCityPrice">
  41. <a-input-number
  42. id="productPricingEdit-afterCityPrice"
  43. v-model="form.afterCityPrice"
  44. :precision="2"
  45. :min="0.01"
  46. :max="999999"
  47. placeholder="请输入市级价"
  48. ref="afterCityPrice"
  49. @keydown.enter.native="nextFocus('afterCityPrice', 'afterSpecialPrice', $event)"
  50. style="width: 100%;" />
  51. </a-form-model-item>
  52. <a-form-model-item label="特约价" prop="afterSpecialPrice">
  53. <a-input-number
  54. id="productPricingEdit-afterSpecialPrice"
  55. v-model="form.afterSpecialPrice"
  56. :precision="2"
  57. :min="0.01"
  58. :max="999999"
  59. placeholder="请输入特约价"
  60. ref="afterSpecialPrice"
  61. @keydown.enter.native="nextFocus('afterSpecialPrice', 'afterTerminalPrice', $event)"
  62. style="width: 100%;" />
  63. </a-form-model-item>
  64. <a-form-model-item label="终端价" prop="afterTerminalPrice">
  65. <a-input-number
  66. id="productPricingEdit-afterTerminalPrice"
  67. v-model="form.afterTerminalPrice"
  68. :precision="2"
  69. :min="0.01"
  70. :max="999999"
  71. placeholder="请输入终端价"
  72. ref="afterTerminalPrice"
  73. @keydown.enter.native="nextFocus('afterTerminalPrice', 'afterCarOwnersPrice', $event)"
  74. style="width: 100%;" />
  75. </a-form-model-item>
  76. <a-form-model-item label="车主价" prop="afterCarOwnersPrice">
  77. <a-input-number
  78. id="productPricingEdit-afterCarOwnersPrice"
  79. v-model="form.afterCarOwnersPrice"
  80. :precision="2"
  81. :min="0.01"
  82. :max="999999"
  83. placeholder="请输入车主价"
  84. ref="afterCarOwnersPrice"
  85. @keydown.enter.native="nextFocus('afterCarOwnersPrice', 'changeReason', $event, 'vSelect')"
  86. style="width: 100%;" />
  87. </a-form-model-item>
  88. <a-form-model-item label="变更原因" prop="changeReason">
  89. <v-select
  90. code="PRODUCT_PRICE_CHANGE_REASON"
  91. id="productPricingEdit-changeReason"
  92. v-model="form.changeReason"
  93. allowClear
  94. placeholder="请选择变更原因"
  95. ref="changeReason"
  96. @keydown.enter.native="nextFocus('changeReason', '', $event)"
  97. ></v-select>
  98. </a-form-model-item>
  99. </a-form-model>
  100. <div class="btn-cont">
  101. <a-button type="primary" id="productPricingEdit-save" @click="handleSave">保存</a-button>
  102. <a-button id="productPricingEdit-cancel" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
  103. </div>
  104. </a-spin>
  105. </div>
  106. </a-modal>
  107. </template>
  108. <script>
  109. import { VSelect } from '@/components'
  110. import { productPricingSnDetail, productPricingSave } from '@/api/product'
  111. export default {
  112. name: 'ProductPricingEditModal',
  113. components: { VSelect },
  114. props: {
  115. openModal: { // 弹框显示状态
  116. type: Boolean,
  117. default: false
  118. },
  119. itemSn: {
  120. type: [Number, String],
  121. default: ''
  122. }
  123. },
  124. data () {
  125. return {
  126. isShow: this.openModal, // 是否打开弹框
  127. spinning: false,
  128. formItemLayout: {
  129. labelCol: { span: 4 },
  130. wrapperCol: { span: 17 }
  131. },
  132. form: {
  133. afterProvincePrice: '',
  134. afterCityPrice: '',
  135. afterSpecialPrice: '',
  136. afterTerminalPrice: '',
  137. afterCarOwnersPrice: '',
  138. changeReason: undefined
  139. },
  140. rules: {
  141. changeReason: [
  142. { required: true, message: '请选择变更原因', trigger: 'change' }
  143. ],
  144. afterProvincePrice: [
  145. { required: true, message: '请输入省级价', trigger: 'blur' }
  146. ],
  147. afterCityPrice: [
  148. { required: true, message: '请输入市级价', trigger: 'blur' }
  149. ],
  150. afterSpecialPrice: [
  151. { required: true, message: '请输入特约价', trigger: 'blur' }
  152. ]
  153. },
  154. detailData: null // 数据详情
  155. }
  156. },
  157. methods: {
  158. // 获取详情
  159. getDetail () {
  160. productPricingSnDetail({ sn: this.itemSn }).then(res => {
  161. if (res.status == 200) {
  162. this.detailData = res.data
  163. this.form.afterProvincePrice = res.data.afterProvincePrice || ''
  164. this.form.afterCityPrice = res.data.afterCityPrice || ''
  165. this.form.afterSpecialPrice = res.data.afterSpecialPrice || ''
  166. this.form.afterTerminalPrice = res.data.afterTerminalPrice || ''
  167. this.form.afterCarOwnersPrice = res.data.afterCarOwnersPrice || ''
  168. this.form.changeReason = res.data.id && res.data.changeReason ? '价格修改' : '首次定价'
  169. } else {
  170. this.detailData = null
  171. this.$refs.ruleForm.resetFields()
  172. }
  173. })
  174. },
  175. // 保存
  176. handleSave () {
  177. const _this = this
  178. this.$refs.ruleForm.validate(valid => {
  179. if (valid) {
  180. const form = JSON.parse(JSON.stringify(_this.form))
  181. form.id = this.detailData.id || undefined
  182. form.productSn = _this.itemSn
  183. _this.spinning = true
  184. productPricingSave(form).then(res => {
  185. if (res.status == 200) {
  186. _this.$message.success(res.message)
  187. setTimeout(() => {
  188. _this.$emit('ok')
  189. _this.isShow = false
  190. _this.spinning = false
  191. }, 1000)
  192. } else {
  193. _this.spinning = false
  194. }
  195. })
  196. } else {
  197. console.log('error submit!!')
  198. return false
  199. }
  200. })
  201. },
  202. // 回车键快捷定位表单下一项
  203. nextFocus (nowRef, nextRef, event, isComponent) {
  204. const _this = this
  205. if (_this.$refs[nowRef]) {
  206. _this.$nextTick(() => {
  207. if (_this.$refs[nextRef]) {
  208. event.target.blur()
  209. if (isComponent == 'vSelect') {
  210. _this.$refs[nextRef].$children[0].focus()
  211. } else {
  212. _this.$refs[nextRef].focus()
  213. }
  214. }
  215. })
  216. }
  217. }
  218. },
  219. watch: {
  220. // 父页面传过来的弹框状态
  221. openModal (newValue, oldValue) {
  222. this.isShow = newValue
  223. },
  224. // 重定义的弹框状态
  225. isShow (newValue, oldValue) {
  226. if (!newValue) {
  227. this.$emit('close')
  228. this.costPrice = ''
  229. this.$refs.ruleForm.resetFields()
  230. } else {
  231. // 默认首项获取焦点
  232. const _this = this
  233. setTimeout(() => {
  234. if (_this.$refs['afterProvincePrice']) {
  235. _this.$refs['afterProvincePrice'].focus()
  236. }
  237. }, 300)
  238. }
  239. },
  240. itemSn (newValue, oldValue) {
  241. if (this.isShow && newValue) {
  242. this.getDetail()
  243. }
  244. }
  245. }
  246. }
  247. </script>
  248. <style lang="less">
  249. .productPricingEdit-modal{
  250. .ant-modal-body {
  251. padding: 40px 40px 24px;
  252. }
  253. .btn-cont {
  254. text-align: center;
  255. margin: 35px 0 30px;
  256. }
  257. }
  258. </style>