detail.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div v-loading="isLoading" class="addProduct">
  3. <el-form ref="addFormRef" label-width="120px" class="addForm" :model="formData" :rules="rules">
  4. <el-form-item label="设备名称:" prop="productName">
  5. <span>{{ formData.productName }}</span>
  6. </el-form-item>
  7. <el-form-item label="设备SN码:" prop="snCode">
  8. <span>{{ formData.snCode }}</span>
  9. </el-form-item>
  10. <el-form-item v-if="shopType === 2" label="所属品牌:" prop="brandId">
  11. <el-select v-model="formData.brandId" placeholder="请选择品牌" style="width: 100%" filterable disabled>
  12. <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="设备图片:" prop="productImage">
  16. <el-image :src="formData.productImage" fit="cover" class="thumbnail" />
  17. </el-form-item>
  18. <el-form-item label="授权牌:" prop="certificateImage">
  19. <el-image :src="formData.certificateImage" fit="cover" class="thumbnail" />
  20. </el-form-item>
  21. <el-form-item label="相关参数:">
  22. <div v-for="(item, index) in paramList" :key="index" class="form-group paramsItem">
  23. <el-input v-model="item.paramName" class="param-title" placeholder="参数名称" maxlength="10" />
  24. <el-input v-model="item.paramContent" class="param-info" placeholder="请输入参数信息" maxlength="50" />
  25. </div>
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. </template>
  30. <script>
  31. import { saveProduct, getProductById } from '@/api/product'
  32. import { fetchBrandList } from '@/api/brand'
  33. import { mapGetters } from 'vuex'
  34. export default {
  35. data() {
  36. return {
  37. isLoading: false,
  38. paramsCount: 4,
  39. formData: {
  40. authUserId: '',
  41. authId: '', // 授权id
  42. certificateImage: '', // 授权牌照
  43. createBy: '', // 创建人id
  44. // 设备参数列表
  45. paramList: [],
  46. productId: '', // 授权设备id
  47. productImage: '', // 设备图片
  48. productName: '', // 设备名称
  49. snCode: '', // 设备SN码
  50. brandId: ''
  51. },
  52. paramList: [],
  53. brandList: [],
  54. rules: {
  55. certificateImage: [{ required: true, message: '授权牌照不能为空' }],
  56. paramList: [{ required: true, message: '参数不能为空' }],
  57. productImage: [{ required: true, message: '设备图片不能为空' }],
  58. snCode: [{ required: true, message: 'SN码不能为空' }],
  59. productName: [
  60. { required: true, message: '设备名称不能为空' },
  61. { max: 50, message: '字数在50字符以内' }
  62. ]
  63. },
  64. fileList1: [],
  65. fileList2: []
  66. }
  67. },
  68. computed: {
  69. ...mapGetters(['authUserId', 'proxyInfo', 'shopType', 'brandId'])
  70. },
  71. created() {
  72. this.formData.productId = parseInt(this.$route.query.id)
  73. this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
  74. this.initFormData()
  75. if (this.shopType === 2) {
  76. this.getBrandList()
  77. }
  78. // 如果供应商类型为品牌方,则自动设置品牌id
  79. if (this.shopType === 1) {
  80. this.formData.brandId = this.proxyInfo?.brandId || this.brandId || ''
  81. }
  82. },
  83. methods: {
  84. // 初始化表单数据
  85. initFormData() {
  86. this.isLoading = true
  87. getProductById({ productId: this.formData.productId }).then(res => {
  88. console.log(res)
  89. // const { authId, certificateImage, paramList, productId, productImage, productName, snCode, status } = res.data
  90. for (const key in res.data) {
  91. if (Object.hasOwnProperty.call(res.data, key)) {
  92. if (key !== 'paramList') {
  93. this.formData[key] = res.data[key]
  94. }
  95. }
  96. }
  97. // 初始化参数
  98. this.paramList = res.data.paramList
  99. this.isLoading = false
  100. })
  101. },
  102. // 获取品牌信息
  103. getBrandList() {
  104. fetchBrandList({ type: 3, authUserId: this.formData.authUserId }).then(res => {
  105. console.log(res)
  106. this.brandList = res.data
  107. })
  108. },
  109. // 保存表单数据
  110. save() {
  111. this.isLoading = true
  112. this.formData.createBy = this.proxyInfo?.authUserId || this.authUserId
  113. this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
  114. saveProduct(this.formData)
  115. .then(res => {
  116. if (res.code !== 0) return
  117. const h = this.$createElement
  118. this.$notify.success({
  119. title: '修改设备',
  120. message: h('i', { style: 'color: #333' }, `已修改设备:"${this.formData.productName}"`),
  121. duration: 2000
  122. })
  123. this.$store.dispatch('tagsView/delView', this.$route)
  124. this.$router.back()
  125. })
  126. .finally(() => {
  127. this.isLoading = false
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .addProduct {
  135. margin-bottom: 80px;
  136. .form-group {
  137. margin-bottom: 2%;
  138. .param-title {
  139. width: 30%;
  140. }
  141. .param-info {
  142. width: 68%;
  143. margin-left: 2%;
  144. }
  145. }
  146. }
  147. .addForm {
  148. width: 500px;
  149. margin: 0 auto;
  150. margin-top: 80px;
  151. }
  152. .submit-btn {
  153. text-align: center;
  154. .el-button {
  155. width: 140px;
  156. }
  157. }
  158. .paramsItem {
  159. position: relative;
  160. .closed {
  161. position: absolute;
  162. top: 50%;
  163. transform: translateY(-50%);
  164. right: -20px;
  165. cursor: pointer;
  166. color: #ddd;
  167. &:hover {
  168. color: #333;
  169. }
  170. }
  171. }
  172. .hiddenInput {
  173. height: 0;
  174. display: none;
  175. }
  176. .thumbnail{
  177. width:160px;
  178. height:160px;
  179. }
  180. </style>