addStoreClass.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="container">
  3. <view class="input_content">
  4. <view class="input_content_textarea">
  5. <textarea v-model="formData.cate_name" placeholder="请输入分类" placeholder-class="placeholderStyle" maxlength="12"/>
  6. <view><text v-if="formData.cate_name">{{formData.cate_name.length}}</text><text v-else>0</text>/12</view>
  7. </view>
  8. <view class="input_content_photo">
  9. <view v-if="formData.pic" class="input_content_photo_adPh">
  10. <image class="photos" :src="formData.pic"></image>
  11. <view class="input_content_photo_adPh_jiao" @click="deleteImage"><image src="../static/images/close.png" mode=""></image></view>
  12. </view>
  13. <view v-else class="input_content_photo_adPh" @click="handleChooseImage">
  14. <view><image src="../static/images/creamer.png" mode="widthFix"></image></view>
  15. <view>添加图片</view>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="list_content">
  20. <view class="list_item">
  21. <text class="list_item_title">上级分类</text>
  22. <picker @change="bindPickerChange" :range="classifyArr" range-key="cate_name">
  23. <input placeholder="请选择上级分类" type="text" disabled readonly v-model="parentClassify">
  24. <view class='iconfont icon-jiantou'></view>
  25. </picker>
  26. </view>
  27. <view class="list_item">
  28. <view class="list_item_title">是否显示</view>
  29. <view class="input_class">
  30. <view class="input_class_con">
  31. <switch :checked="is_show" @change="is_show = !is_show" color="#E93323" style="transform:scale(0.8)" />
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="handle">
  37. <view class="handle_button" @click="submit">
  38. 确定
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. // +----------------------------------------------------------------------
  45. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  46. // +----------------------------------------------------------------------
  47. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  48. // +----------------------------------------------------------------------
  49. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  50. // +----------------------------------------------------------------------
  51. // | Author: CRMEB Team <admin@crmeb.com>
  52. // +----------------------------------------------------------------------
  53. import { storeClassifyLst, merClassifyAdd, merClassifyDetail, merClassifyUpdate } from "@/api/product";
  54. export default {
  55. components: {
  56. },
  57. data() {
  58. return {
  59. parentClassify: '',
  60. formData: {
  61. cate_name: '',
  62. pic: '',
  63. pid: '',
  64. is_show: 1,
  65. sort: 0
  66. },
  67. is_show: true,
  68. index: 0,
  69. mer_id: '',
  70. pid: '',
  71. classifyArr: [],
  72. }
  73. },
  74. onLoad(options) {
  75. this.mer_id = options.mer_id
  76. this.pid = options.pid
  77. this.getCateList()
  78. if(this.pid && this.mer_id) this.getCateDetail()
  79. },
  80. onShow() {
  81. },
  82. onReady() {
  83. },
  84. methods: {
  85. bindPickerChange: function(e) {
  86. let idx = e.target.value
  87. this.formData.pid = this.classifyArr[idx]['store_category_id']
  88. this.parentClassify = this.classifyArr[idx]['cate_name']
  89. },
  90. getCateList(){
  91. storeClassifyLst(this.mer_id)
  92. .then(res => {
  93. this.classifyArr = res.data
  94. this.classifyArr.unshift({cate_name: '顶级分类', store_category_id: 0, children: []})
  95. if(!this.pid){this.pid = 0;this.parentClassify = this.getStorCateName(0, this.classifyArr)}
  96. })
  97. .catch(res => {
  98. this.$util.Tips({
  99. title: res
  100. });
  101. });
  102. },
  103. //获取分类详情
  104. getCateDetail(){
  105. let that = this
  106. uni.showLoading({
  107. title: '加载中'
  108. });
  109. merClassifyDetail(that.mer_id,that.pid)
  110. .then(res => {
  111. uni.hideLoading();
  112. let data = res.data
  113. that.formData = data
  114. that.is_show = data.is_show == 1;
  115. that.parentClassify = that.getStorCateName(data.pid, that.classifyArr)
  116. })
  117. .catch(res => {
  118. that.$util.Tips({
  119. title: res
  120. });
  121. });
  122. },
  123. //获取店铺分类名称
  124. getStorCateName(id, arr) {
  125. for (let i = 0; i < arr.length; i++) {
  126. if (arr[i].store_category_id === id) {
  127. return arr[i]['cate_name']
  128. }
  129. }
  130. },
  131. handleChooseImage() {
  132. let that = this;
  133. that.$util.uploadImageOne('upload/image', function (res) {
  134. that.$set(that.formData,'pic',res.data.path);
  135. });
  136. },
  137. // 删除图片
  138. deleteImage(index) {
  139. this.formData.pic ="";
  140. },
  141. submit(){
  142. let that = this;
  143. that.formData.is_show = that.is_show ? 1 : 0
  144. that.formData.pid = that.formData.pid ? that.formData.pid : 0
  145. let value = that.formData
  146. if (!value.cate_name) return that.$util.Tips({
  147. title: '请输入分类名称'
  148. });
  149. that.pid ? merClassifyUpdate(that.mer_id,that.pid,that.formData).then(data => {
  150. if (data.status == 200) {
  151. that.$util.Tips({
  152. title: data.message
  153. });
  154. setTimeout(()=>{
  155. uni.redirectTo({
  156. url: "/pages/product/storeClassification/index?mer_id="+that.mer_id
  157. })
  158. },1000)
  159. }
  160. }).catch(res => {
  161. that.$util.Tips({
  162. title: res
  163. });
  164. }) :
  165. merClassifyAdd(that.mer_id,that.formData).then(data => {
  166. if (data.status == 200) {
  167. that.$util.Tips({
  168. title: data.message
  169. });
  170. setTimeout(()=>{
  171. uni.redirectTo({
  172. url: "/pages/product/storeClassification/index?mer_id="+that.mer_id
  173. })
  174. },1000)
  175. }
  176. }).catch(res => {
  177. that.$util.Tips({
  178. title: res
  179. });
  180. })
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. @import './scss/addStoreClass.scss';
  187. .uni-input-placeholder {
  188. color: #BBBBBB;
  189. }
  190. </style>