GoodsClassForm.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false">
  3. <view class="div container">
  4. <view class="div common-header-wrap">
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar :title="getTitle" class="common-header" left-icon="back" @clickLeft="goBack">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="div main-content">
  14. <flex-line class="field-line" :show-border="true"><text class="span field-name">分类名称</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="class_info.storegc_name" /></view></flex-line>
  15. <view class="div" @click="showPopup('parentVisible')">
  16. <flex-line :is-link="true" :show-border="true"><text class="span line-name">上级分类</text><text class="span" slot="right">{{parent_name}}</text></flex-line>
  17. </view>
  18. <flex-line class="field-line" :show-border="true"><text class="span field-name">排序</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="class_info.storegc_sort" /></view></flex-line>
  19. <flex-line :show-border="true"><text class="span line-name">显示</text><view class="div" slot="right"><switch @change="switchChange" :checked="!!state"></switch></view></flex-line>
  20. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">保存</view></view>
  21. </view>
  22. <uni-popup background-color="#fff" ref="parentVisible" type="right" >
  23. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  24. <view class="div common-header-wrap">
  25. <view :style="'height:'+navHeight+'px'"></view>
  26. <view class="common-header-holder"></view>
  27. <view class="common-header-fixed">
  28. <title-header />
  29. <uni-nav-bar title="上级分类" class="common-header" left-icon="back" @clickLeft="hidePopup('parentVisible')">
  30. </uni-nav-bar>
  31. </view>
  32. </view>
  33. <view class="div common-popup-content">
  34. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  35. <radio-group @change="radioChange" class='radio-wrapper'>
  36. <view class='radio-item' v-for="(item, index) in class_options" :key="index">
  37. <radio :value="item.value" :checked="parent_id==item.value" />
  38. <text>{{item.label}}</text>
  39. </view>
  40. </radio-group>
  41. </scroll-view>
  42. </view>
  43. </view>
  44. </uni-popup>
  45. </view>
  46. </seller-base>
  47. </template>
  48. <script>
  49. import {getFontSize} from '@/util/common'
  50. import TitleHeader from '../../TitleHeader'
  51. import SellerBase from '../SellerBase'
  52. import { getCommonData, getGoodsClassInfo, editGoodsClass } from '../../../api/sellerGoodsClass'
  53. import flexLine from '../../flexLine'
  54. export default {
  55. components:{
  56. TitleHeader,
  57. SellerBase,
  58. flexLine,
  59. },
  60. computed:{
  61. fontSize(){
  62. return getFontSize()
  63. },
  64. isAddMode () {
  65. let mode = this.action
  66. // add: 添加地址,edit: 编辑地址
  67. if (mode === 'add') {
  68. return true
  69. } else {
  70. return false
  71. }
  72. },
  73. getTitle () {
  74. if (this.isAddMode) {
  75. return '新增分类'
  76. } else {
  77. return '修改分类'
  78. }
  79. }
  80. },
  81. data(){
  82. return {
  83. navHeight: 0,
  84. screenWidth:0,
  85. parent_name: '无',
  86. action:'',
  87. state: true,
  88. class_info: {
  89. storegc_id: 0,
  90. storegc_sort: 255
  91. },
  92. parent_id: '0',
  93. class_options: [{
  94. label: '无',
  95. value: '0'
  96. }],
  97. parent_list: {
  98. '0': '无'
  99. }
  100. }
  101. },
  102. onLoad: function (option) {
  103. this.action = option.action
  104. getCommonData().then(res => {
  105. let temp = res.result.goods_class
  106. for (var i in temp) {
  107. this.parent_list[temp[i].storegc_id + ''] = temp[i].storegc_name
  108. this.class_options.push({
  109. label: temp[i].storegc_name,
  110. value: temp[i].storegc_id + ''
  111. })
  112. }
  113. }).catch(function (error) {
  114. uni.showToast({icon:'none',title: error.message})
  115. })
  116. if (!this.isAddMode) {
  117. getGoodsClassInfo(option.storegc_id).then(res => {
  118. this.class_info = res.result.class_info
  119. this.parent_id = res.result.class_info.storegc_parent_id + ''
  120. if (this.class_info.storegc_state) {
  121. this.state = true
  122. } else {
  123. this.state = false
  124. }
  125. }).catch(function (error) {
  126. uni.showToast({icon:'none',title: error.message})
  127. })
  128. }
  129. },
  130. watch: {
  131. parent_id: function (parent_id) {
  132. this.parent_name = this.parent_list[parent_id]
  133. this.hidePopup('parentVisible')
  134. }
  135. },
  136. mounted(){
  137. // #ifdef MP-WEIXIN
  138. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  139. // #endif
  140. this.screenWidth=uni.getSystemInfoSync().screenWidth
  141. },
  142. methods:{
  143. switchChange(e){
  144. this.state=e.detail.value
  145. },
  146. radioChange(e){
  147. this.parent_id=e.detail.value
  148. },
  149. showPopup(id){
  150. this.$refs[id].open()
  151. },
  152. hidePopup(id){
  153. this.$refs[id].close()
  154. },
  155. goBack () {
  156. uni.navigateBack({delta:1})
  157. },
  158. submit () {
  159. if (!this.class_info.storegc_name) {
  160. uni.showToast({icon:'none',title: '请填写分类名称'})
  161. return
  162. }
  163. if (this.state) {
  164. this.class_info.storegc_state = 1
  165. } else {
  166. this.class_info.storegc_state = 0
  167. }
  168. this.class_info.storegc_parent_id = this.parent_id
  169. editGoodsClass(this.class_info).then(
  170. (response) => {
  171. uni.navigateBack({delta:1})
  172. }, (error) => {
  173. uni.showToast({icon:'none',title: error.message})
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .main-content{background: #fff;padding:0 $pageSpace}
  181. .right-arrow{transform: rotate(-90deg);color:#ddd;font-size:$fontSize;display: inline-block;}
  182. .input-wrap{position: relative;
  183. .i{position: absolute;right:0;top:0;line-height: 2.4rem;display: block;width:2rem;text-align: center;font-size:$h1}
  184. }
  185. .radio-wrapper{
  186. display: block;
  187. padding: 0 $pageSpace;
  188. .radio-item{
  189. padding: .5rem 0;
  190. border-bottom: 1px dashed #f5f5f5;
  191. }
  192. }
  193. </style>