editModal.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <a-modal
  3. centered
  4. class="productUniversalEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <div>
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="productUniversalEdit-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol"
  20. >
  21. <a-form-model-item label="产品编码" prop="productSn">
  22. <productCodeList id="productUniversalEdit-productSn" ref="productCodeList" @change="productCodeChange" />
  23. </a-form-model-item>
  24. <a-form-model-item label="产品名称">
  25. {{ productName || '--' }}
  26. </a-form-model-item>
  27. <a-form-model-item label="通用产品编码" prop="productCommonSn">
  28. <productCodeList id="productUniversalEdit-productCommonSn" ref="productUniversalCodeList" @change="productUniversalCodeChange" />
  29. </a-form-model-item>
  30. <a-form-model-item label="通用产品名称">
  31. {{ productCommonName || '--' }}
  32. </a-form-model-item>
  33. </a-form-model>
  34. <div class="btn-cont">
  35. <a-button type="primary" id="productUniversalEdit-save" @click="handleSave">保存</a-button>
  36. <a-button id="productUniversalEdit-cancel" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
  37. </div>
  38. </a-spin>
  39. </div>
  40. </a-modal>
  41. </template>
  42. <script>
  43. // 组件
  44. import { VSelect } from '@/components'
  45. import productCodeList from '@/views/common/productCodeList.vue'
  46. // 接口
  47. import { productUniversalCodeSave, productUniversalCodeDetail } from '@/api/productUniversalCode'
  48. export default {
  49. name: 'ProductLevelEditModal',
  50. components: { VSelect, productCodeList },
  51. props: {
  52. openModal: { // 弹框显示状态
  53. type: Boolean,
  54. default: false
  55. },
  56. itemId: {// 通用产品id
  57. type: [Number, String],
  58. default: ''
  59. }
  60. },
  61. computed: {
  62. // 弹窗标题
  63. modalTit () {
  64. return (this.itemId ? '编辑' : '新增') + '通用产品'
  65. }
  66. },
  67. data () {
  68. return {
  69. spinning: false,
  70. isShow: this.openModal, // 是否打开弹框
  71. // 表单布局
  72. formItemLayout: {
  73. labelCol: { span: 4 },
  74. wrapperCol: { span: 16 }
  75. },
  76. form: {
  77. productCode: undefined, // 产品列表
  78. productSn: undefined, // 产品sn
  79. productCommonCode: undefined, // 通用产品编码
  80. productCommonSn: undefined// 通用产品sn
  81. },
  82. // 表单验证规则
  83. rules: {
  84. productSn: [
  85. { required: true, message: '请选择产品编码', trigger: 'change' }
  86. ],
  87. productCommonSn: [
  88. { required: true, message: '请选择通用产品编码', trigger: 'change' }
  89. ]
  90. },
  91. productName: '', // 产品名称
  92. productCommonName: ''// 通用产品名称
  93. }
  94. },
  95. methods: {
  96. // 产品编码 change
  97. productCodeChange (val) {
  98. this.form.productSn = val.key || undefined
  99. this.form.productCode = val.row && val.row.code ? val.row.code : undefined
  100. this.productName = val.row && val.row.name ? val.row.name : undefined
  101. },
  102. // 通用产品编码 change
  103. productUniversalCodeChange (val) {
  104. this.form.productCommonSn = val.key || undefined
  105. this.form.productCommonCode = val.row && val.row.code ? val.row.code : undefined
  106. this.productCommonName = val.row && val.row.name ? val.row.name : undefined
  107. },
  108. // 获取详情数据
  109. getDetail () {
  110. productUniversalCodeDetail({ id: this.itemId }).then(res => {
  111. if (res.status == 200) {
  112. this.form.productSn = res.data.productSn || undefined
  113. this.form.productCode = res.data.productCode || undefined
  114. this.form.productCommonSn = res.data.productCommonSn || undefined
  115. this.form.productCommonCode = res.data.productCommonCode || undefined
  116. this.productName = res.data.product.name || ''
  117. this.productCommonName = res.data.productCommont.name || ''
  118. this.$refs.productCodeList.setData({ key: this.form.productSn, label: this.form.productCode })
  119. this.$refs.productUniversalCodeList.setData({ key: this.form.productCommonSn, label: this.form.productCommonCode })
  120. }
  121. })
  122. },
  123. // 保存
  124. handleSave () {
  125. const _this = this
  126. this.$refs.ruleForm.validate(valid => {
  127. if (valid) {
  128. const params = JSON.parse(JSON.stringify(_this.form))
  129. params.id = _this.itemId ? this.itemId : undefined
  130. _this.spinning = true
  131. productUniversalCodeSave(params).then(res => {
  132. if (res.status == 200) {
  133. _this.$message.success(res.message)
  134. setTimeout(() => {
  135. _this.$emit('ok')
  136. _this.isShow = false
  137. _this.spinning = false
  138. }, 1000)
  139. } else {
  140. _this.spinning = false
  141. }
  142. })
  143. } else {
  144. console.log('error submit!!')
  145. return false
  146. }
  147. })
  148. }
  149. },
  150. watch: {
  151. // 父页面传过来的弹框状态
  152. openModal (newValue, oldValue) {
  153. this.isShow = newValue
  154. },
  155. // 重定义的弹框状态
  156. isShow (newValue, oldValue) {
  157. if (!newValue) {
  158. this.$emit('close')
  159. this.$refs.ruleForm.resetFields()
  160. this.productName = ''
  161. this.productCommonName = ''
  162. this.$refs.productCodeList.resetForm()
  163. this.$refs.productUniversalCodeList.resetForm()
  164. }
  165. },
  166. itemId (newValue, oldValue) {
  167. if (this.isShow && newValue) {
  168. this.getDetail()
  169. }
  170. }
  171. }
  172. }
  173. </script>
  174. <style lang="less">
  175. .productUniversalEdit-modal{
  176. .ant-modal-body {
  177. padding: 40px 40px 24px;
  178. }
  179. .btn-cont {
  180. text-align: center;
  181. margin: 35px 0 30px;
  182. }
  183. }
  184. </style>