add.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="app-content">
  3. <form @submit="formSubmit">
  4. <view class="module-com input-line-wrap">
  5. <tui-list-cell class="line-cell" :hover="false">
  6. <view class="tui-title">名称</view>
  7. <input v-model="form.name" placeholder-class="phcolor" class="tui-input" name="name" @focus="form.name=''" placeholder="请填写名称" maxlength="50" type="text" />
  8. <button class="admin-button-com big blue" style="width:190upx;" @click="selectMake()">选商品</button>
  9. </tui-list-cell>
  10. <tui-list-cell class="line-cell" :hover="false">
  11. <view class="tui-title">数量</view>
  12. <input v-model="form.num" placeholder-class="phcolor" class="tui-input" name="num" @focus="form.num=''" placeholder="请填写数量" maxlength="50" type="number" />
  13. </tui-list-cell>
  14. <tui-list-cell class="line-cell" :arrow="true">
  15. <view class="tui-title">分类</view>
  16. <picker mode="selector" :value="form.catId" :range="plantClassData" range-key="categoryName" @change="changePlantClassFn" class="tui-input" >
  17. <input v-model="form.catId" name="catId" type="text" hidden />
  18. <view v-if="form.catId" style="height:45upx;" >{{ categorySelectedData.categoryName }}</view>
  19. <view class="tui-placeholder" style="height:45upx;" v-else>请选择</view>
  20. </picker>
  21. </tui-list-cell>
  22. <tui-list-cell class="line-cell" :arrow="true">
  23. <view class="tui-title">主花支数</view>
  24. <input v-model="form.flowerNum" placeholder-class="phcolor" class="tui-input" name="flowerNum" @focus="form.flowerNum=''" placeholder="请填写主花支数" maxlength="50" type="number" />
  25. </tui-list-cell>
  26. </view>
  27. <view class="module-com input-line-wrap goods-wrap">
  28. <view class="module-tit">
  29. <span>图片</span>
  30. <span class="app-color-3">(建议比例 1:1)</span>
  31. </view>
  32. <view class="module-det">
  33. <htz-image-upload :max="1" :compress="true" v-model="currentImgData" :headers="headers"
  34. @uploadSuccess="imgUploadSuccess" @imgDelete="imgDeleteFn" :action="getLoginInfo.imgUploadApi">
  35. </htz-image-upload>
  36. </view>
  37. </view>
  38. <view class="module-com input-line-wrap">
  39. <tui-list-cell class="line-cell" :hover="false" :arrow="false">
  40. <view class="tui-title">备注</view>
  41. <textarea style="height: 100upx" v-model="form.remark" placeholder="这里写备注..." />
  42. </tui-list-cell>
  43. </view>
  44. <view class="app-footer">
  45. <button class="admin-button-com big default" @click="goBack()">取消</button>
  46. <button class="admin-button-com big blue" formType="submit">确认</button>
  47. </view>
  48. </form>
  49. </view>
  50. </template>
  51. <script>
  52. import TuiListCell from "@/components/plugin/list-cell";
  53. const form = require("@/utils/formValidation.js");
  54. import { getClass } from "@/api/category";
  55. import { addWork } from "@/api/work/index";
  56. import { mapGetters } from "vuex"
  57. //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
  58. import htzImageUpload from './components/htz-image-upload/htz-image-upload.vue'
  59. export default {
  60. name: "add",
  61. components: {
  62. TuiListCell,
  63. htzImageUpload
  64. },
  65. data() {
  66. return {
  67. currentImgData: [],
  68. form: {
  69. name:"花束",
  70. catId:'',
  71. cover:[],
  72. num:'',
  73. remark:'',
  74. flowerNum:''
  75. },
  76. flowerNumList:[{num:6,name:6},{num:9,name:9},{num:11,name:11},{num:19,name:19},{num:33,name:33},{num:52,name:52},{num:66,name:66},{num:99,name:99}],
  77. categorySelectedData:{},
  78. plantClassData:[],
  79. headers:{token:''},
  80. flowerIndex:0,
  81. flowerNumName:''
  82. };
  83. },
  84. computed:{
  85. ...mapGetters(["getLoginInfo","getDictionariesInfo"]),
  86. },
  87. onLoad() {
  88. const token = uni.getStorageSync('token')
  89. this.headers.token = token
  90. },
  91. watch:{
  92. },
  93. methods: {
  94. selectMake(){
  95. this.$util.pageTo({ url: "/admin/goods/flower", type: 2 })
  96. },
  97. flowerNumChange(e){
  98. let index = e.detail.value
  99. this.form.flowerNum = this.flowerNumList[index].num
  100. this.flowerNumName = this.flowerNumList[index].name
  101. },
  102. statusChange(e){
  103. this.form.status = e.detail.value ? 1 : 2;
  104. },
  105. delStatusChange(e){
  106. this.form.delStatus = e.detail.value ? 0 : 1;
  107. },
  108. goBack(){
  109. uni.navigateBack({delta:1})
  110. },
  111. changePlantClassFn(e) {
  112. this.categorySelectedData = this.plantClassData[e.detail.value];
  113. this.form.catId = this.categorySelectedData.id;
  114. },
  115. imgUploadSuccess(res) {
  116. var imgReturn = JSON.parse(res.data)
  117. if(imgReturn.code == 1){
  118. this.currentImgData.push(imgReturn.data.smallUrl)
  119. this.form.cover.push(imgReturn.data.shortUrl)
  120. }
  121. },
  122. imgDeleteFn(res){
  123. const index = res.index
  124. this.form.cover.splice(index,1)
  125. },
  126. init() {
  127. this.getPlantCategory()
  128. },
  129. async getPlantCategory() {
  130. await getClass({flower:1}).then(res => {
  131. if (this.$util.isEmpty(res.data)){
  132. return false;
  133. }
  134. this.plantClassData = res.data;
  135. if(this.plantClassData && this.plantClassData[0] && this.plantClassData[0].id){
  136. this.form.catId = this.plantClassData[0].id||''
  137. let categoryName = this.plantClassData[0].categoryName||''
  138. this.categorySelectedData = {categoryName}
  139. }
  140. });
  141. },
  142. confirmFn() {
  143. if (this.$util.isEmpty(this.form.cover)) {
  144. this.$msg("请上传图片")
  145. return false
  146. }
  147. this.form.cover = this.form.cover[0]
  148. let form = JSON.parse(JSON.stringify(this.form))
  149. addWork({...form}).then(res => {
  150. if(res.code == 1){
  151. this.pageTo({url: '/admin/work/addResult',type:2})
  152. }
  153. })
  154. },
  155. formSubmit(e) {
  156. let rules = [
  157. {
  158. name: "name",
  159. rule: ["required"],
  160. msg: ["请填写名称"]
  161. },
  162. {
  163. name: "catId",
  164. rule: ["required"],
  165. msg: ["请选择分类"]
  166. },
  167. {
  168. name: "num",
  169. rule: ["required"],
  170. msg: ["请填写数量"]
  171. }
  172. ];
  173. let formData = e.detail.value;
  174. let checkRes = form.validation(formData, rules);
  175. if (!checkRes) {
  176. this.confirmFn()
  177. } else {
  178. this.$msg(checkRes);
  179. }
  180. }
  181. }
  182. };
  183. </script>
  184. <style lang="scss" scoped>
  185. .app-content {
  186. min-height: calc(100vh - 100upx);
  187. padding-bottom: 150upx;
  188. }
  189. .module-com {
  190. margin-bottom: 20upx;
  191. background-color: #fff;
  192. color: $fontColor2;
  193. .module-tit {
  194. padding: 20upx 30upx;
  195. font-size: 28upx;
  196. }
  197. .module-det {
  198. padding: 0 30upx;
  199. }
  200. }
  201. .category-wrap {
  202. align-items: flex-start;
  203. padding-bottom: 0 !important;
  204. .tui-input {
  205. @include disFlex(center, flex-start);
  206. flex-wrap: wrap;
  207. .admin-button-com {
  208. margin-right: 20upx;
  209. margin-bottom: 20upx;
  210. position: relative;
  211. z-index: 9999;
  212. }
  213. }
  214. }
  215. .summary-wrap {
  216. .goods-summary {
  217. height: 400upx;
  218. }
  219. }
  220. .app-footer {
  221. justify-content: space-evenly;
  222. z-index: 9999;
  223. .admin-button-com {
  224. width: 46%;
  225. }
  226. }
  227. </style>