add.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. if(Array.isArray(this.form.cover)){
  148. this.form.cover = this.form.cover[0]
  149. }
  150. let form = JSON.parse(JSON.stringify(this.form))
  151. addWork({...form}).then(res => {
  152. if(res.code == 1){
  153. this.pageTo({url: '/admin/work/addResult',type:2})
  154. }
  155. })
  156. },
  157. formSubmit(e) {
  158. let rules = [
  159. {
  160. name: "name",
  161. rule: ["required"],
  162. msg: ["请填写名称"]
  163. },
  164. {
  165. name: "catId",
  166. rule: ["required"],
  167. msg: ["请选择分类"]
  168. },
  169. {
  170. name: "num",
  171. rule: ["required"],
  172. msg: ["请填写数量"]
  173. }
  174. ];
  175. let formData = e.detail.value;
  176. let checkRes = form.validation(formData, rules);
  177. if (!checkRes) {
  178. this.confirmFn()
  179. } else {
  180. this.$msg(checkRes);
  181. }
  182. }
  183. }
  184. };
  185. </script>
  186. <style lang="scss" scoped>
  187. .app-content {
  188. min-height: calc(100vh - 100upx);
  189. padding-bottom: 150upx;
  190. }
  191. .module-com {
  192. margin-bottom: 20upx;
  193. background-color: #fff;
  194. color: $fontColor2;
  195. .module-tit {
  196. padding: 20upx 30upx;
  197. font-size: 28upx;
  198. }
  199. .module-det {
  200. padding: 0 30upx;
  201. }
  202. }
  203. .category-wrap {
  204. align-items: flex-start;
  205. padding-bottom: 0 !important;
  206. .tui-input {
  207. @include disFlex(center, flex-start);
  208. flex-wrap: wrap;
  209. .admin-button-com {
  210. margin-right: 20upx;
  211. margin-bottom: 20upx;
  212. position: relative;
  213. z-index: 9999;
  214. }
  215. }
  216. }
  217. .summary-wrap {
  218. .goods-summary {
  219. height: 400upx;
  220. }
  221. }
  222. .app-footer {
  223. justify-content: space-evenly;
  224. z-index: 9999;
  225. .admin-button-com {
  226. width: 46%;
  227. }
  228. }
  229. </style>