Explorar o código

始宁农业后台:产品管理-产品编辑

panyong %!s(int64=2) %!d(string=hai) anos
pai
achega
1bc2b82813

+ 0 - 4
htmldev/shiningManage/README.md

@@ -237,7 +237,3 @@ yarn build
 
 * 内容管理-VR看菜园
   * 缺列表、新增、编辑、删除接口
-
-* 农产品管理-农产品管理
-  * 编辑
-    - 缺编辑接口

+ 50 - 49
htmldev/shiningManage/src/views/productManage/products/details.vue

@@ -146,7 +146,7 @@
             placeholder="请选择单位">
             <el-option
               :label="item.name"
-              :value="item.value"
+              :value="item.name"
               v-for="item in arrProductUnit"
               :key="item.value"></el-option>
           </el-select>
@@ -191,7 +191,8 @@
             label="1">现售
           </el-radio>
           <el-date-picker
-            v-model="value1"
+            :disabled="form.product_sale_at === '0'"
+            v-model="product_sale_at"
             type="datetime"
             placeholder="选择预售日期时间">
           </el-date-picker>
@@ -209,24 +210,7 @@
             <el-option
               :label="item.name"
               :value="item.value"
-              v-for="item in []"
-              :key="item.value"></el-option>
-          </el-select>
-        </el-form-item>
-        <el-form-item
-          prop="product_is_recommend"
-          :rules="formRules.select"
-          label="是否推荐:">
-          <el-select
-            style="width: 100%;"
-            v-model="form.product_is_recommend"
-            filterable
-            clearable
-            placeholder="请选择是否推荐">
-            <el-option
-              :label="item.name"
-              :value="item.value"
-              v-for="item in arrProductIsRecommend"
+              v-for="item in arrProductStatus"
               :key="item.value"></el-option>
           </el-select>
         </el-form-item>
@@ -269,42 +253,43 @@ export default {
       default: function () {
         return []
       }
+    },
+    arrProductStatus: {
+      type: Array,
+      default: function () {
+        return []
+      }
     }
   },
   data() {
     return {
       dialog: !!this.value,
       form: {
-        'product_title': '测试商品', // 标题
+        'product_title': '', // 标题
         'product_desc': '', // 商品描述
         'product_img_url': [], // 商品主图
         'product_rotation_img_list': [], // 商品轮播图
         'product_detail_img_list': [], // 商品详情图
         'product_category_id': 1,
-        'product_category_name': '水果', // 分类名称
-        'product_brand_id': 1,
-        'product_brand_name': '大众', // 品牌名称
-        'product_spec': 'xl', // 规格
-        'product_unit': '个', // 单位
-        'product_all_price': 10000, // 批发价
-        'product_price': 9000, // 零售价
-        'product_count': 1000, // 库存
-        'product_sale_at': '0', // 发售时间(0代表非预售  时间戳代表预售时间)
-        'product_status': 0, // 商品状态(0未上架1已上架2审核中3审核未通过)
-        'product_is_recommend': 0 // 是否推荐(0否1是)
+        'product_category_name': '', // 分类名称
+        'product_brand_id': '',
+        'product_brand_name': '', // 品牌名称
+        'product_spec': '', // 规格
+        'product_unit': '', // 单位
+        'product_all_price': '', // 批发价
+        'product_price': '', // 零售价
+        'product_count': '', // 库存
+        'product_sale_at': '0', // 发售时间(0代表非预售  时间戳代表预售时间) todo 现售时间
+        'product_status': '0' // 商品状态 0下架 1上架
       },
       product_img_url: [],
       product_rotation_img_list: [],
       product_detail_img_list: [],
-      booLock: false,
-      radio: '1',
-      value1: ''
+      product_sale_at: '',
+      booLock: false
     }
   },
   computed: {
-    arrProductIsRecommend() {
-      return this.$store.state.common.arrProductIsRecommend
-    },
     arrCategoryList() {
       return this.$store.state.common.arrCategoryList
     },
@@ -349,11 +334,17 @@ export default {
       this.$refs.form.validate(async valid => {
         if (valid) {
           const formData = JSON.parse(JSON.stringify(this.form))
+          const productCategoryNameIndex = this.arrCategoryList.findIndex(item => item.value === formData.product_category_id)
+          const productBrandNamedIndex = this.arrBrandList.findIndex(item => item.value === formData.product_brand_id)
           const postData = {
             ...formData,
             product_img_url: formData.product_img_url[0],
-            product_rotation_img_list: JSON.stringify(formData.product_rotation_img_list),
-            product_detail_img_list: JSON.stringify(formData.product_detail_img_list)
+            product_rotation_img_list: formData.product_rotation_img_list,
+            product_detail_img_list: formData.product_detail_img_list,
+            product_category_name: productCategoryNameIndex > -1 ? this.arrCategoryList[productCategoryNameIndex].name : '',
+            product_brand_name: productBrandNamedIndex > -1 ? this.arrBrandList[productBrandNamedIndex].name : '',
+            product_all_price: yuan2Fen(formData.product_all_price),
+            product_price: yuan2Fen(formData.product_price)
           }
           this.booLock = true
           const data = await this.$fetch(url, postData)
@@ -382,28 +373,38 @@ export default {
           url: this.exData.product_img_url
         }
       ]
-      this.product_rotation_img_list = [
-        {
+      this.product_rotation_img_list = this.exData.product_rotation_img_list.map(item => {
+        return {
           name: '',
-          url: this.exData.product_rotation_img_list
+          url: item
         }
-      ]
-      this.product_detail_img_list = [
-        {
+      })
+      this.product_detail_img_list = this.exData.product_detail_img_list.map(item => {
+        return {
           name: '',
-          url: this.exData.product_detail_img_list
+          url: item
         }
-      ]
+      })
       for (const key in this.exData) {
         if (this.form.hasOwnProperty(key)) {
           let value = this.exData[key]
           if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
-            if (key === 'product_img_url' || key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
+            if (key === 'product_img_url') {
               value = [value]
             }
             if (key === 'product_all_price' || key === 'product_price') {
               value = fen2Yuan(value)
             }
+            if (key === 'product_status' || key === 'product_count') {
+              value = value + ''
+            }
+            if (key === 'product_sale_at') {
+              if (value === 0) {
+                value = value + ''
+              } else {
+                value = '1'
+              }
+            }
             this.$set(this.form, key, value)
           }
         }

+ 12 - 3
htmldev/shiningManage/src/views/productManage/products/index.vue

@@ -89,7 +89,6 @@
         <template slot-scope="scope">{{ scope.row.product_is_recommend === 1 ? '是' : '否' }}</template>
       </el-table-column>
       <el-table-column label="创建时间" prop="product_check_at" min-width="160"></el-table-column>
-      <!-- todo 缺编辑接口 -->
       <el-table-column label="操作" width="120">
         <template slot-scope="scope">
           <el-button type="text" @click="edit(scope.row)">操作</el-button>
@@ -112,6 +111,7 @@
       v-if="detailsDialog.show"
       v-model="detailsDialog.show"
       :exData="detailsDialog.exData"
+      :arrProductStatus="arrProductStatus"
       @success="init"></detail>
   </div>
 </template>
@@ -142,7 +142,16 @@ export default {
       return this.$store.state.common.arrProductSaleType
     },
     arrProductStatus() {
-      return this.$store.state.common.arrProductStatus
+      return [
+        {
+          name: '未上架',
+          value: '0'
+        },
+        {
+          name: '已上架',
+          value: '1'
+        }
+      ]
     },
     arrCategoryList() {
       return this.$store.state.common.arrCategoryList
@@ -172,7 +181,7 @@ export default {
       })
     },
     getProductStatusText(val) {
-      const index = this.arrProductStatus.findIndex(item => item.value === val)
+      const index = this.arrProductStatus.findIndex(item => item.value === val + '')
       if (index > -1) {
         return this.arrProductStatus[index].name
       }