price-edit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" width="1000px">
  3. <el-form ref="dataForm" :model="formData" :rules="rules" size="mini" label-width="120px">
  4. <el-form-item label="商品名称:">
  5. <div class="text" v-text="product.productName" />
  6. </el-form-item>
  7. <el-form-item label="商品图片:">
  8. <el-popover
  9. placement="top-start"
  10. title=""
  11. width="120"
  12. trigger="hover"
  13. >
  14. <img :src="product.mainImage" alt="" style="width:100px;height:100px;">
  15. <img slot="reference" :src="product.mainImage" alt="" style="width:50px;height:50px;">
  16. </el-popover>
  17. </el-form-item>
  18. <el-form-item label="供应商名称:">
  19. <div class="text" v-text="product.shopName" />
  20. </el-form-item>
  21. <el-form-item label="商品状态:" prop="validFlag">
  22. <el-select v-model="formData.validFlag" placeholder="请选择" disabled="true" @change="handleChange($event)">
  23. <el-option label="已上架" :value="2" />
  24. <el-option label="已下架" :value="3" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="商品规格:" prop="skus">
  28. <el-table row-key="title" :data="formData.skus" border height="250">
  29. <el-table-column label="商品规格" prop="title" align="center">
  30. <template slot-scope="{row}">
  31. <span>{{ row.unit }}</span>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="起订量" prop="name" align="center">
  35. <template slot-scope="{row}">
  36. <span>{{ row.minBuyNumber }}</span>
  37. </template>
  38. <!-- <template slot-scope="{row}">
  39. <el-input v-model="row.minBuyNumber" disabled="true" @input="e => (row.name= checkedInput(e))" />
  40. </template> -->
  41. </el-table-column>
  42. <el-table-column label="成本价" prop="name" align="center">
  43. <template slot-scope="{row}">
  44. <span> ¥{{ row.costPrice | toThousandFloatFilter }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="售价" prop="name" align="center">
  48. <template slot-scope="{row}">
  49. <span> ¥{{ row.price | toThousandFloatFilter }}</span>
  50. </template>
  51. <!-- <template slot-scope="{row}">
  52. <el-input v-model="row.price" disabled="true" @input="e => (row.price= checkedInput(e))">
  53. <template slot="prepend">¥</template>
  54. </el-input>
  55. </template> -->
  56. </el-table-column>
  57. </el-table>
  58. </el-form-item>
  59. </el-form>
  60. <div slot="footer" class="dialog-footer">
  61. <el-button @click="dialogFormVisible = false"> 关闭 </el-button>
  62. <el-button v-if="isDetail" type="primary" @click="handleSave"> 保存 </el-button>
  63. </div>
  64. </el-dialog>
  65. </template>
  66. <script>
  67. import { saveGoods } from '@/api/goods'
  68. export default {
  69. props: {
  70. dialogTitle: {
  71. type: String,
  72. default: '编辑'
  73. },
  74. isVisible: {
  75. type: Boolean,
  76. default: false
  77. },
  78. product: {
  79. type: Object,
  80. default: () => {}
  81. },
  82. classify: {
  83. type: Array,
  84. default: () => []
  85. },
  86. isDetail: {
  87. type: Boolean,
  88. default: () => true
  89. }
  90. },
  91. data: function() {
  92. return {
  93. postData: null,
  94. formData: {
  95. skus: [],
  96. validFlag: ''
  97. },
  98. rules: {
  99. classifyID: [{ required: true, message: '*必填', trigger: 'change' }],
  100. ladderPriceFlag: [{ required: true, message: '*必填', trigger: 'change' }],
  101. retailPrice: [{ validator: this.checkSinglePrice, type: 'float', trigger: 'blur' }],
  102. minBuyNumber: [{ validator: this.checkSingleNumber, type: 'number', trigger: 'blur' }]
  103. }
  104. }
  105. },
  106. computed: {
  107. dialogFormVisible: {
  108. get() {
  109. return this.isVisible
  110. },
  111. set(val) {
  112. this.$emit('update:isVisible', val)
  113. }
  114. }
  115. },
  116. watch: {
  117. product: function(val) {
  118. this.postData = JSON.parse(JSON.stringify(val))
  119. this.formData.skus = this.postData.skus
  120. this.formData.validFlag = this.postData.validFlag
  121. }
  122. },
  123. methods: {
  124. handleChange(value) {
  125. console.log('value', value)
  126. },
  127. handleSave() {
  128. // 保存商品
  129. this.$refs['dataForm'].validate((valid) => {
  130. if (valid) {
  131. this.saveGoods()
  132. }
  133. })
  134. },
  135. async saveGoods() {
  136. try {
  137. await saveGoods(this.formData)
  138. this.$message.success('操作成功')
  139. this.$parent.getList()
  140. this.dialogFormVisible = false
  141. } catch (error) {
  142. console.log('error', error)
  143. }
  144. },
  145. checkedInput(event) {
  146. const pattern = /[^0-9.]/g
  147. return event.replace(pattern, '')
  148. }
  149. }
  150. }
  151. </script>
  152. <style scoped>
  153. .group label{
  154. white-space: nowrap;
  155. font-weight: normal;
  156. }
  157. .text{
  158. line-height: 20px;
  159. padding: 4px 0 0;
  160. }
  161. .line{
  162. display: flex;
  163. }
  164. .single{
  165. width:280px;
  166. }
  167. .multiple{
  168. display: flex;
  169. padding-left: 120px;
  170. justify-content: left;
  171. align-items: flex-end;
  172. }
  173. .group{
  174. white-space: nowrap;
  175. font-weight: normal;
  176. }
  177. .group button{
  178. padding:0 15px;
  179. }
  180. </style>