addStoreClass.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. import { storeClassifyLst, merClassifyAdd, merClassifyDetail, merClassifyUpdate } from "@/api/product";
  45. export default {
  46. components: {
  47. },
  48. data() {
  49. return {
  50. parentClassify: '',
  51. formData: {
  52. cate_name: '',
  53. pic: '',
  54. pid: '',
  55. is_show: 1,
  56. sort: 0
  57. },
  58. is_show: true,
  59. index: 0,
  60. mer_id: '',
  61. pid: '',
  62. classifyArr: [],
  63. }
  64. },
  65. onLoad(options) {
  66. this.mer_id = options.mer_id
  67. this.pid = options.pid
  68. this.getCateList()
  69. if(this.pid && this.mer_id) this.getCateDetail()
  70. },
  71. onShow() {
  72. },
  73. onReady() {
  74. },
  75. methods: {
  76. bindPickerChange: function(e) {
  77. let idx = e.target.value
  78. this.formData.pid = this.classifyArr[idx]['store_category_id']
  79. this.parentClassify = this.classifyArr[idx]['cate_name']
  80. },
  81. getCateList(){
  82. storeClassifyLst(this.mer_id)
  83. .then(res => {
  84. this.classifyArr = res.data
  85. this.classifyArr.unshift({cate_name: '顶级分类', store_category_id: 0, children: []})
  86. if(!this.pid){this.pid = 0;this.parentClassify = this.getStorCateName(0, this.classifyArr)}
  87. })
  88. .catch(res => {
  89. this.$util.Tips({
  90. title: res
  91. });
  92. });
  93. },
  94. //获取分类详情
  95. getCateDetail(){
  96. let that = this
  97. uni.showLoading({
  98. title: '加载中'
  99. });
  100. merClassifyDetail(that.mer_id,that.pid)
  101. .then(res => {
  102. uni.hideLoading();
  103. let data = res.data
  104. that.formData = data
  105. that.is_show = data.is_show == 1;
  106. that.parentClassify = that.getStorCateName(data.pid, that.classifyArr)
  107. })
  108. .catch(res => {
  109. that.$util.Tips({
  110. title: res
  111. });
  112. });
  113. },
  114. //获取店铺分类名称
  115. getStorCateName(id, arr) {
  116. for (let i = 0; i < arr.length; i++) {
  117. if (arr[i].store_category_id === id) {
  118. return arr[i]['cate_name']
  119. }
  120. }
  121. },
  122. handleChooseImage() {
  123. let that = this;
  124. that.$util.uploadImageOne('upload/image', function (res) {
  125. that.$set(that.formData,'pic',res.data.path);
  126. });
  127. },
  128. // 删除图片
  129. deleteImage(index) {
  130. this.formData.pic ="";
  131. },
  132. submit(){
  133. let that = this;
  134. that.formData.is_show = that.is_show ? 1 : 0
  135. that.formData.pid = that.formData.pid ? that.formData.pid : 0
  136. let value = that.formData
  137. if (!value.cate_name) return that.$util.Tips({
  138. title: '请输入分类名称'
  139. });
  140. that.pid ? merClassifyUpdate(that.mer_id,that.pid,that.formData).then(data => {
  141. if (data.status == 200) {
  142. that.$util.Tips({
  143. title: data.message
  144. });
  145. setTimeout(()=>{
  146. uni.redirectTo({
  147. url: "/pages/product/storeClassification/index?mer_id="+that.mer_id
  148. })
  149. },1000)
  150. }
  151. }).catch(res => {
  152. that.$util.Tips({
  153. title: res
  154. });
  155. }) :
  156. merClassifyAdd(that.mer_id,that.formData).then(data => {
  157. if (data.status == 200) {
  158. that.$util.Tips({
  159. title: data.message
  160. });
  161. setTimeout(()=>{
  162. uni.redirectTo({
  163. url: "/pages/product/storeClassification/index?mer_id="+that.mer_id
  164. })
  165. },1000)
  166. }
  167. }).catch(res => {
  168. that.$util.Tips({
  169. title: res
  170. });
  171. })
  172. }
  173. }
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. @import './scss/addStoreClass.scss';
  178. .uni-input-placeholder {
  179. color: #BBBBBB;
  180. }
  181. </style>