add.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. <template>
  2. <div class="app-content">
  3. <!-- 花材基本信息 -->
  4. <form @submit="formSubmit">
  5. <div class="module-com input-line-wrap">
  6. <tui-list-cell class="line-cell" :hover="false">
  7. <div class="tui-title">名称</div>
  8. <input v-model="form.name" placeholder-class="phcolor" class="tui-input" name="name" placeholder="请填写名称" @input="fillName($event)" maxlength="50" type="text" />
  9. </tui-list-cell>
  10. <tui-list-cell class="line-cell" :hover="false">
  11. <div class="tui-title">初始名称</div>
  12. <view style="color:#CCCCCC;width:450upx;height:45upx;" @click.stop="notModify">
  13. {{form.name}}
  14. </view>
  15. </tui-list-cell>
  16. <tui-list-cell class="line-cell" :hover="false">
  17. <div class="tui-title">拼音缩写</div>
  18. <input v-model="form.py" placeholder-class="phcolor" class="tui-input" name="py" placeholder="请填写拼音首字母缩写" maxlength="50" type="text" />
  19. </tui-list-cell>
  20. <tui-list-cell class="line-cell" :hover="false">
  21. <view class="tui-title">价格</view>
  22. <input v-model="form.hjPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;" placeholder-class="phcolor"
  23. class="tui-input" name="hjPrice" @focus="form.hjPrice=''" placeholder="大客价" type="digit" />
  24. <input v-model="form.price" style="width:130upx;border:1upx solid #3385FF;text-align:center;height:50upx;color:#3385FF;margin-left:30upx;" placeholder-class="phcolor"
  25. class="tui-input" name="price" @focus="form.price=''" placeholder="批发价" type="digit" @input="priceLinkage()" />
  26. <input v-model="form.skPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;margin-left:30upx;" placeholder-class="phcolor"
  27. class="tui-input" name="skPrice" @focus="form.skPrice=''" placeholder="零售价" type="digit" />
  28. </tui-list-cell>
  29. <tui-list-cell class="line-cell" :hover="false">
  30. <view class="tui-title">特价</view>
  31. <input v-model="form.hjDiscountPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;" placeholder-class="phcolor"
  32. class="tui-input" name="hjDiscountPrice" @focus="form.hjDiscountPrice=''" placeholder="会员特价" type="digit" />
  33. <input v-model="form.discountPrice" style="width:130upx;border:1upx solid #3385FF;margin-left:30upx;color:#3385FF;text-align:center;height:50upx;" placeholder-class="phcolor" @input="tjLinkage()"
  34. class="tui-input" name="discountPrice" @focus="form.discountPrice=''" placeholder="无特价填0" maxlength="50" type="digit" />
  35. <input v-model="form.skDiscountPrice" style="width:130upx;border:1upx solid #CCCCCC;text-align:center;height:50upx;margin-left:30upx;" placeholder-class="phcolor"
  36. class="tui-input" name="skDiscountPrice" @focus="form.skDiscountPrice=''" placeholder="零售特价" type="digit" />
  37. </tui-list-cell>
  38. <tui-list-cell class="line-cell" :hover="false">
  39. <view class="tui-title">成本</view>
  40. <input v-model="form.cost" style="width:340upx;" placeholder-class="phcolor" @focus="form.cost=''" class="tui-input" name="cost" placeholder="请输入" type="digit"/>
  41. </tui-list-cell>
  42. <tui-list-cell class="line-cell" :hover="false">
  43. <view class="tui-title" style="color:#3385FF;font-weight:bold;">库存</view>
  44. <input v-model="form.stock" style="color:#3385FF;width:300upx;font-weight:bold;" placeholder-class="phcolor" @focus="form.stock=''" @input="changeStock($event)" class="tui-input" name="stock" placeholder="请输入" type="digit"/>
  45. </tui-list-cell>
  46. <tui-list-cell class="line-cell" :hover="false">
  47. <view class="tui-title">库存不足</view>
  48. <view>
  49. <button class="admin-button-com middle" :class="form.virtualStock == 0 ? 'blue' : 'default'" @click="virtualStockChange(0)">关闭自动补充</button>
  50. <button class="admin-button-com middle" :class="form.virtualStock == 1 ? 'blue' : 'default'" @click="virtualStockChange(1)" style="margin-left:38upx;">开启自动补充</button>
  51. </view>
  52. </tui-list-cell>
  53. <tui-list-cell class="line-cell" :hover="false" :arrow="true">
  54. <div class="tui-title">分类</div>
  55. <input v-model="form.classId" name="classId" type="text" hidden />
  56. <view style="color:#CCCCCC;width:450upx;height:45upx;" @click.stop="changeClass()" v-if="form.classId == 0">
  57. 请选择分类
  58. </view>
  59. <view @click.stop="changeClass()" style="width:450upx;height:45upx;" v-else>
  60. {{form.className}}
  61. </view>
  62. </tui-list-cell>
  63. <tui-list-cell class="line-cell" :arrow="true">
  64. <div class="tui-title">大单位</div>
  65. <picker mode="selector" :value="form.bigUnitId" :range="unitData" range-key="name" @change="changeBigUnitFn" class="tui-input" >
  66. <input v-model="form.bigUnitId" name="bigUnitId" type="text" hidden />
  67. <div v-if="form.bigUnitId">{{ bigUnitSelectedData.name }}</div>
  68. <div class="tui-placeholder" style="height:45upx;" v-else>请选择</div>
  69. </picker>
  70. </tui-list-cell>
  71. <tui-list-cell class="line-cell" :arrow="true">
  72. <div class="tui-title">小单位</div>
  73. <picker mode="selector" :value="form.smallUnitId" :range="unitData" range-key="name" @change="changeSmallUnitFn" class="tui-input" >
  74. <input v-model="form.smallUnitId" name="smallUnitId" type="text" hidden />
  75. <div v-if="form.smallUnitId">{{ smallUnitSelectedData.name }}</div>
  76. <div class="tui-placeholder" v-else>请选择</div>
  77. </picker>
  78. </tui-list-cell>
  79. <tui-list-cell class="line-cell" :hover="false">
  80. <view class="tui-title">包装类型</view>
  81. <view>
  82. <button class="admin-button-com middle" :class="form.ratioType == 0 ? 'blue' : 'default'" @click="ratioTypeChange(0)">固定支数</button>
  83. <button class="admin-button-com middle" :class="form.ratioType == 1 ? 'blue' : 'default'" @click="ratioTypeChange(1)" style="margin-left:40upx;">没有固定</button>
  84. </view>
  85. </tui-list-cell>
  86. <tui-list-cell class="line-cell" :hover="false" v-if="form.ratioType == 0">
  87. <div class="tui-title">几支装</div>
  88. <input v-model="form.ratio" placeholder-class="phcolor" class="tui-input" name="ratio" placeholder="20支装请填20" maxlength="50" type="number" />
  89. </tui-list-cell>
  90. <tui-list-cell class="line-cell" :hover="false">
  91. <div class="tui-title">每扎重量</div>
  92. <input v-model="form.weight" placeholder-class="phcolor" class="tui-input" name="weight" placeholder="公斤" maxlength="50" type="digit" />
  93. <view class="weight-reminder-icon" @click="showWeightPopup">
  94. <text style="color: #999; font-size: 32upx; font-weight: bold;">?</text>
  95. </view>
  96. </tui-list-cell>
  97. <tui-list-cell class="line-cell" :hover="false">
  98. <div class="tui-title">库存预警</div>
  99. <input v-model="form.stockWarning" placeholder-class="phcolor" class="tui-input" name="stockWarning" placeholder="请填写" maxlength="50" type="number" />
  100. </tui-list-cell>
  101. </div>
  102. <div class="module-com input-line-wrap goods-wrap">
  103. <div class="module-tit">
  104. <span>花材图片(最多5张)</span>
  105. <span class="app-color-3"></span>
  106. </div>
  107. <view class="module-det">
  108. <htz-image-upload :max="5" :compress="true" v-model="currentImgData" :headers="headers"
  109. @uploadSuccess="imgUploadSuccess"
  110. @imgDelete="imgDeleteFn"
  111. :action="getLoginInfo.imgUploadApi">
  112. </htz-image-upload>
  113. </view>
  114. <tui-list-cell class="line-cell category-wrap" :hover="false">
  115. <view class="tui-title">封面</view>
  116. <view class="tui-input">
  117. <block v-if="coverImgData.length > 0">
  118. <button class="admin-button-com" :class="[(form.cover == item) ? '' : 'default']"
  119. v-for="(item, index) in coverImgData" :key="index"
  120. @click="selCoverFn(index)" >第{{ index + 1 }}张</button>
  121. </block>
  122. <view v-else class="no-img-tip">请先上传图片</view>
  123. <view v-if="coverImgData.length > 0" class="use-img">选择上面的图片作为封面</view>
  124. </view>
  125. </tui-list-cell>
  126. </div>
  127. <view class="module-com input-line-wrap">
  128. <tui-list-cell class="line-cell" :hover="false">
  129. <view class="tui-title">大客加价</view>
  130. <input v-model="form.hjAddPrice" placeholder-class="phcolor" class="tui-input" name="hjAddPrice" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
  131. </tui-list-cell>
  132. <tui-list-cell class="line-cell" :hover="false">
  133. <div class="tui-title">批发加价</div>
  134. <input v-model="form.addPrice" placeholder-class="phcolor" class="tui-input" name="addPrice" @focus="form.addPrice=''" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
  135. </tui-list-cell>
  136. <tui-list-cell class="line-cell" :hover="false">
  137. <view class="tui-title">零售加价</view>
  138. <input v-model="form.skMore" placeholder-class="phcolor" class="tui-input" name="skMore" @focus="form.skMore=''" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
  139. </tui-list-cell>
  140. <tui-list-cell class="line-cell" :hover="false">
  141. <view class="tui-title">顺序值</view>
  142. <input v-model="form.inTurn" placeholder-class="phcolor" class="tui-input" name="inTurn" @focus="form.inTurn=''" placeholder="请填写数字" type="number" />
  143. </tui-list-cell>
  144. </view>
  145. <view class="app-footer">
  146. <button class="admin-button-com big default" @click="goBack()">取消</button>
  147. <button v-if="option.ptItemId" class="admin-button-com big blue" formType="submit" @click="status = 1">添加</button>
  148. <button v-else class="admin-button-com big blue" formType="submit" @click="status = 1">确认</button>
  149. </view>
  150. </form>
  151. <uni-popup ref="classRef" background-color="#fff" type="center" :animation="false" class="class-popup-style">
  152. <view style="margin-left:30upx;margin-top:19upx;font-size:27upx;font-weight:bold;">请选择分类:</view>
  153. <view style="display:flex;padding:20upx;height:auto;justify-content: space-between;align-items:center;flex-wrap:wrap;max-height:80vh;overflow:auto;">
  154. <view v-for="(item, index) in itemClassData" :key="index" @tap.stop="setThisClass(item)" style="margin-bottom:20upx;margin-left:3upx;">
  155. <image :src="item.cover" style="width:120upx;height:120upx;border-radius:10upx;"></image>
  156. <view style="margin-top:5upx;overflow: hidden;white-space: nowrap;width:120upx;text-align:center;">{{item.name}}</view>
  157. </view>
  158. </view>
  159. </uni-popup>
  160. <uni-popup ref="weightRef" background-color="#fff" type="center" :animation="false" class="weight-popup-style">
  161. <view class="weight-popup-container">
  162. <view class="weight-popup-title">花材重量参考</view>
  163. <view class="weight-popup-content">
  164. <view class="weight-item" v-for="(item, index) in weightReferenceData" :key="index">
  165. <text class="weight-name">{{ item.name }}</text>
  166. <text class="weight-value">{{ item.weight }}</text>
  167. </view>
  168. </view>
  169. <view class="weight-popup-note">以上含纸箱平摊下来的重量,供参考</view>
  170. <view class="weight-popup-footer">
  171. <button class="admin-button-com big blue" @click="closeWeightPopup">确定</button>
  172. </view>
  173. </view>
  174. </uni-popup>
  175. </div>
  176. </template>
  177. <script>
  178. import TuiListCell from "@/components/plugin/list-cell";
  179. const form = require("@/utils/formValidation.js");
  180. import { getAllItemClass } from "@/api/item-class";
  181. import { getAllUnit } from "@/api/unit";
  182. import { addProduct,updateProduct,getProductDetail,py } from "@/api/product";
  183. import { getPtItemDetail } from "@/api/pt-item";
  184. import { mapGetters } from "vuex"
  185. //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
  186. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
  187. export default {
  188. name: "item-detail",
  189. components: {
  190. TuiListCell,
  191. htzImageUpload
  192. },
  193. data() {
  194. return {
  195. status: 1,
  196. currentImgData: [],
  197. form: {
  198. id:0,
  199. name:"",
  200. py:"",
  201. stock:0,
  202. ratio:'',
  203. bigUnitId:1,
  204. smallUnitId:2,
  205. classId:'',
  206. className:'',
  207. price:'',
  208. skPrice:'',
  209. hjPrice:'',
  210. skMore:6,
  211. addPrice:3,
  212. hjAddPrice:2,
  213. hjDiscountPrice:0,
  214. discountPrice:0,
  215. skDiscountPrice:0,
  216. cost:0,
  217. weight:1.5,
  218. cover: "", // 将cover字段的类型从数组改成字符串
  219. images: [], // 新增images字段来保存图片列表
  220. stockWarning:5,
  221. status:2,
  222. itemId:0,
  223. smallRatio:1,
  224. virtualStock:0,
  225. ratioType:0,
  226. inTurn:100,
  227. cpInfo:[]
  228. },
  229. itemClassSelectedData:{},
  230. itemClassData:[],
  231. unitData:[],
  232. smallUnitSelectedData:{},
  233. bigUnitSelectedData:{},
  234. hasRequest:0,
  235. productData:{id:0},
  236. headers:{token:''},
  237. backCpInfo:{cpId:0,cpName:'',needUpdate:0},
  238. weightReferenceData:[
  239. {name: '单头玫瑰', weight: '1.2公斤'},
  240. {name: '多头玫瑰', weight: '1.2公斤'},
  241. {name: '百合', weight: '2.7公斤'},
  242. {name: '康乃馨', weight: '1公斤'},
  243. {name: '向日葵', weight: '2.7公斤或3公斤'},
  244. {name: '其他', weight: '0.5公斤或1公斤'}
  245. ]
  246. };
  247. },
  248. computed:{
  249. ...mapGetters(["getLoginInfo","getDictionariesInfo"]),
  250. // 根据上传的图片数量动态生成封面选项
  251. coverImgData() {
  252. if (this.form.images.length === 0) {
  253. return [];
  254. }
  255. return this.form.images;
  256. }
  257. },
  258. onShow(){
  259. let that = this
  260. if(this.backCpInfo.needUpdate == 1){
  261. let needAdd = 1;
  262. if (!this.$util.isEmpty(this.form.cpInfo)) {
  263. that.form.cpInfo.forEach((item) => {
  264. if(item.cpId == that.backCpInfo.cpId){
  265. needAdd = 0
  266. }
  267. })
  268. }
  269. if(needAdd == 1){
  270. that.form.cpInfo.push({cpId:that.backCpInfo.cpId,cpName:that.backCpInfo.cpName})
  271. that.backCpInfo.needUpdate = 0
  272. that.$forceUpdate()
  273. }
  274. }
  275. },
  276. onLoad(option) {
  277. if(option.id){
  278. this.form.id = this.option.id
  279. }
  280. const token = uni.getStorageSync('token')
  281. this.headers.token = token
  282. },
  283. methods: {
  284. selCoverFn(index) {
  285. this.form.cover = this.form.images[index];
  286. },
  287. showWeightPopup(){
  288. this.$refs.weightRef.open('center')
  289. },
  290. closeWeightPopup(){
  291. this.$refs.weightRef.close()
  292. },
  293. delOneCp(info,index){
  294. let that = this
  295. that.$util.confirmModal({content:'确认删除'+info.cpName+'?'},() => {
  296. that.form.cpInfo.splice(index,1)
  297. that.$forceUpdate()
  298. })
  299. },
  300. changeClass(){
  301. this.$refs.classRef.open('center')
  302. },
  303. setThisClass(info){
  304. this.$refs.classRef.close()
  305. this.form.classId = info.id ? info.id : 0
  306. this.form.className = info.name ? info.name : ''
  307. this.$forceUpdate()
  308. },
  309. tjLinkage(){
  310. if(this.form.discountPrice && Number(this.form.discountPrice)>0){
  311. let skMore = this.form.skMore ? Number(this.form.skMore) : 0
  312. let hjAddPrice = this.form.hjAddPrice ? Number(this.form.hjAddPrice) : 0
  313. let addPrice = this.form.addPrice ? Number(this.form.addPrice) : 0
  314. let skAddNum = Number(skMore) - Number(addPrice)
  315. skAddNum = skAddNum.toFixed(2)
  316. let skAmount = Number(skAddNum) + Number(this.form.discountPrice)
  317. if(skAmount>0){
  318. skAmount = skAmount.toFixed(2)
  319. skAmount = parseFloat(skAmount)
  320. this.form.skDiscountPrice = skAmount
  321. }else{
  322. this.form.skDiscountPrice = 0.01
  323. }
  324. let hjSubNum = Number(addPrice) - Number(hjAddPrice)
  325. hjSubNum = hjSubNum.toFixed(2)
  326. let hjAmount = Number(this.form.discountPrice) - Number(hjSubNum)
  327. if(hjAmount > 0){
  328. hjAmount = hjAmount.toFixed(2)
  329. hjAmount = parseFloat(hjAmount)
  330. this.form.hjDiscountPrice = hjAmount
  331. }else{
  332. this.form.hjDiscountPrice = 0.01
  333. }
  334. }else{
  335. this.form.skDiscountPrice = 0
  336. this.form.hjDiscountPrice = 0
  337. }
  338. },
  339. priceLinkage(){
  340. if(this.form.price && Number(this.form.price)>0){
  341. let skMore = this.form.skMore ? Number(this.form.skMore) : 0
  342. let hjAddPrice = this.form.hjAddPrice ? Number(this.form.hjAddPrice) : 0
  343. let addPrice = this.form.addPrice ? Number(this.form.addPrice) : 0
  344. let skAddNum = Number(skMore) - Number(addPrice)
  345. skAddNum = skAddNum.toFixed(2)
  346. let skAmount = Number(skAddNum) + Number(this.form.price)
  347. if(skAmount>0){
  348. skAmount = skAmount.toFixed(2)
  349. skAmount = parseFloat(skAmount)
  350. this.form.skPrice = skAmount
  351. }else{
  352. this.form.skPrice = ''
  353. }
  354. let hjSubNum = Number(addPrice) - Number(hjAddPrice)
  355. hjSubNum = hjSubNum.toFixed(2)
  356. let hjAmount = Number(this.form.price) - Number(hjSubNum)
  357. if(hjAmount > 0){
  358. hjAmount = hjAmount.toFixed(2)
  359. hjAmount = parseFloat(hjAmount)
  360. this.form.hjPrice = hjAmount
  361. }else{
  362. this.form.hjPrice = ''
  363. }
  364. }else{
  365. this.form.skPrice = ''
  366. this.form.hjPrice = ''
  367. this.form.discountPrice = 0
  368. this.form.skDiscountPrice = 0
  369. this.form.hjDiscountPrice = 0
  370. }
  371. },
  372. notModify(){
  373. this.$msg('不可修改')
  374. },
  375. goStockDetail(item){
  376. this.$util.pageTo({url: "/pagesStorehouse/stockWarn/detailed?id="+item.id+'&name='+item.name})
  377. },
  378. statusChange(e){
  379. this.form.status = e.detail.value ? 1 : 2;
  380. },
  381. ratioTypeChange(value){
  382. this.form.ratioType = value;
  383. },
  384. virtualStockChange(value){
  385. this.form.virtualStock = value
  386. },
  387. //如果库存被修改则花材状态变化
  388. changeStock(event){
  389. let num = Number(event.target.value)
  390. if(num > 0){
  391. this.form.status = 1
  392. }else{
  393. this.form.status = 2
  394. }
  395. },
  396. //获取拼音首字母 shish 20210707
  397. fillName(event){
  398. let val = event.target.value
  399. py({
  400. name:val
  401. }).then(res => {
  402. if(res.data.py){
  403. this.form.py = res.data.py
  404. }
  405. });
  406. },
  407. goBack(){
  408. uni.navigateBack({
  409. delta: 1
  410. });
  411. },
  412. changeBigUnitFn(e){
  413. this.bigUnitSelectedData = this.unitData[e.detail.value];
  414. this.form.bigUnitId = this.bigUnitSelectedData.id;
  415. },
  416. changeSmallUnitFn(e){
  417. this.smallUnitSelectedData = this.unitData[e.detail.value];
  418. this.form.smallUnitId = this.smallUnitSelectedData.id;
  419. },
  420. changeItemClassFn(e) {
  421. this.itemClassSelectedData = this.itemClassData[e.detail.value];
  422. this.form.classId = this.itemClassSelectedData.id;
  423. },
  424. //从平台选择花材 shish 20210826
  425. getPtItemInfo(ptItemId){
  426. getPtItemDetail({id:ptItemId}).then(res=>{
  427. if (this.$util.isEmpty(res.data)) {
  428. return;
  429. }
  430. Object.keys(this.form).forEach((i, index) => {
  431. this.form[i] = res.data[i];
  432. });
  433. // this.currentImgData.push(res.data.cover)
  434. // this.form.images = [res.data.shortCover]
  435. // this.form.cover = res.data.shortCover
  436. const imageUrls = (res.data.images || '').split(',').filter(i => i);
  437. this.form.images = imageUrls;
  438. this.currentImgData = imageUrls.map(url => {
  439. return this.constant.imgUrl + '/' + url + '?x-oss-process=image/resize,m_fill,h_700,w_700'
  440. });
  441. this.form.cover = res.data.shortCover || '';
  442. if (!this.form.cover && this.form.images.length > 0) {
  443. this.form.cover = this.form.images[0];
  444. }
  445. this.form.stock = ''
  446. this.form.itemId = ptItemId
  447. this.form.classId = ''
  448. this.form.status = 1
  449. this.form.id = 0
  450. this.form.price = ''
  451. this.form.skMore = 6
  452. this.form.addPrice = 3
  453. this.form.hjAddPrice = 3
  454. this.form.discountPrice = 0
  455. this.form.cost = 0
  456. })
  457. },
  458. getDetail() {
  459. return getProductDetail({ id: this.option.id }).then(res => {
  460. if (this.$util.isEmpty(res.data)) {
  461. return;
  462. }
  463. Object.keys(this.form).forEach((i, index) => {
  464. this.form[i] = res.data[i];
  465. });
  466. // this.currentImgData.push(res.data.cover)
  467. // this.form.images = [res.data.shortCover]
  468. // this.form.cover = res.data.shortCover
  469. const imageUrls = (res.data.images || '').split(',').filter(i => i);
  470. this.form.images = imageUrls;
  471. this.currentImgData = imageUrls.map(url => {
  472. return this.constant.imgUrl + '/' + url + '?x-oss-process=image/resize,m_fill,h_700,w_700'
  473. });
  474. this.form.price = res.data.prePrice
  475. this.itemClassSelectedData = this.itemClassData.filter(
  476. e => this.form.classId == e.id
  477. )[0];
  478. this.smallUnitSelectedData = this.unitData.filter(
  479. e => this.form.smallUnitId == e.id
  480. )[0];
  481. this.bigUnitSelectedData = this.unitData.filter(
  482. e => this.form.bigUnitId == e.id
  483. )[0];
  484. this.productData = res.data
  485. });
  486. },
  487. imgUploadSuccess(res) {
  488. var _res = JSON.parse(res.data)
  489. if(_res.code == 1){
  490. this.currentImgData.push(_res.data.bigUrl)
  491. this.form.images.push(_res.data.shortUrl)
  492. if (!this.form.cover) {
  493. this.form.cover.push(_res.data.shortUrl)
  494. }
  495. }
  496. },
  497. imgDeleteFn(res){
  498. const index = res.index
  499. this.form.cover.splice(index,1)
  500. },
  501. init() {
  502. //从平台选择花材
  503. if(!this.$util.isEmpty(this.option.ptItemId)){
  504. uni.setNavigationBarTitle({title: "确认花材信息"})
  505. }
  506. if(this.hasRequest == 1){
  507. return
  508. }
  509. this._getAllUnit().then(res=>{
  510. this._getAllItemClass().then(res => {
  511. if(this.form.id == 0){
  512. this.smallUnitSelectedData = this.unitData.filter(e => 2 == e.id)[0];
  513. this.bigUnitSelectedData = this.unitData.filter(e => 1 == e.id)[0];
  514. //从平台选择花材
  515. if(!this.$util.isEmpty(this.option.ptItemId)){
  516. this.getPtItemInfo(this.option.ptItemId)
  517. }
  518. }else{
  519. this.getDetail();
  520. }
  521. });
  522. })
  523. this.hasRequest = 1
  524. },
  525. async _getAllUnit() {
  526. await getAllUnit().then(res => {
  527. if (this.$util.isEmpty(res.data)){
  528. return false;
  529. }
  530. this.unitData = res.data.list;
  531. });
  532. },
  533. async _getAllItemClass() {
  534. await getAllItemClass().then(res => {
  535. if (this.$util.isEmpty(res.data)){
  536. return false;
  537. }
  538. this.itemClassData = res.data;
  539. });
  540. },
  541. // 确认
  542. confirmFn() {
  543. if (this.$util.isEmpty(this.form.images)) {
  544. this.$msg("请上传图片")
  545. return false
  546. }
  547. // 如果没有选择封面,默认使用第一张图片
  548. if (!this.form.cover && this.form.images.length > 0) {
  549. this.form.cover = this.form.images[0];
  550. }
  551. let requestHost = addProduct
  552. if(this.form.id && this.form.id != 0){
  553. requestHost = updateProduct;
  554. }else{
  555. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.stock) == false){
  556. uni.showToast({title:"请填写库存,没库存填0",icon:"none"})
  557. return;
  558. }
  559. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.discountPrice) == false){
  560. uni.showToast({title:"请填写特价,没特价填0",icon:"none"})
  561. return;
  562. }
  563. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.cost) == false){
  564. uni.showToast({title:"请填写成本",icon:"none"})
  565. return;
  566. }
  567. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.price) == false){
  568. uni.showToast({title:"请填写批发价",icon:"none"})
  569. return;
  570. }
  571. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skPrice) == false){
  572. uni.showToast({title:"请填写零售价",icon:"none"})
  573. return;
  574. }
  575. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.hjPrice) == false){
  576. uni.showToast({title:"请填写大客价",icon:"none"})
  577. return;
  578. }
  579. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.addPrice) == false){
  580. uni.showToast({title:"请填写批发加价",icon:"none"})
  581. return;
  582. }
  583. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skMore) == false){
  584. uni.showToast({title:"请填写零售加价",icon:"none"})
  585. return;
  586. }
  587. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.hjAddPrice) == false){
  588. uni.showToast({title:"请填写大客加价",icon:"none"})
  589. return;
  590. }
  591. }
  592. let form = JSON.parse(JSON.stringify(this.form))
  593. uni.showLoading({mask:true})
  594. requestHost({
  595. ...form,
  596. images:this.form.images,
  597. appVersion:1
  598. }).then(res => {
  599. uni.hideLoading()
  600. if(res.code == 1){
  601. this.$msg("操作成功!");
  602. //返回上一页带参数
  603. let pages = getCurrentPages();
  604. let prevPage = pages[ pages.length - 2 ];
  605. let hidden = 0
  606. if(this.form.stock > this.form.stockWarning){
  607. hidden = 1
  608. }
  609. prevPage.$vm.modifyStock = {id:this.form.id,stock:this.form.stock,hidden:hidden};
  610. uni.navigateBack({})
  611. }
  612. });
  613. },
  614. // 表单验证
  615. formSubmit(e) {
  616. // 表单规则
  617. let rules = [
  618. {
  619. name: "name",
  620. rule: ["required"],
  621. msg: ["请填写名称"]
  622. },
  623. {
  624. name: "py",
  625. rule: ["required"],
  626. msg: ["请填写拼音缩写"]
  627. },{
  628. name: "stock",
  629. rule: ["required"],
  630. msg: ["请填写库存,没有填0"]
  631. },
  632. {
  633. name: "bigUnitId",
  634. rule: ["required"],
  635. msg: ["请选择大单位"]
  636. },
  637. {
  638. name: "smallUnitId",
  639. rule: ["required"],
  640. msg: ["请选择小单位"]
  641. },
  642. {
  643. name: "price",
  644. rule: ["required"],
  645. msg: ["请填写批发价"]
  646. },
  647. {
  648. name: "skPrice",
  649. rule: ["required"],
  650. msg: ["请填写零售价"]
  651. },
  652. {
  653. name: "hjPrice",
  654. rule: ["required"],
  655. msg: ["请填写大客价"]
  656. },
  657. {
  658. name: "skMore",
  659. rule: ["required"],
  660. msg: ["请填写零售加价"]
  661. },
  662. {
  663. name: "addPrice",
  664. rule: ["required"],
  665. msg: ["请填写批发加价"]
  666. },
  667. {
  668. name: "hjAddPrice",
  669. rule: ["required"],
  670. msg: ["请填写大客加价"]
  671. },
  672. {
  673. name: "discountPrice",
  674. rule: ["required"],
  675. msg: ["没特价请填0"]
  676. },
  677. {
  678. name: "cost",
  679. rule: ["required"],
  680. msg: ["请填写成本"]
  681. },
  682. {
  683. name: "weight",
  684. rule: ["required"],
  685. msg: ["请填写重量"]
  686. },
  687. {
  688. name: "classId",
  689. rule: ["required"],
  690. msg: ["请选择分类"]
  691. },
  692. {
  693. name: "stockWarning",
  694. rule: ["required"],
  695. msg: ["请填写库存预警"]
  696. }
  697. ];
  698. // 进行表单检查
  699. let formData = e.detail.value;
  700. let checkRes = form.validation(formData, rules);
  701. // 验证通过!
  702. if (!checkRes) {
  703. this.confirmFn()
  704. } else {
  705. this.$msg(checkRes);
  706. }
  707. }
  708. }
  709. };
  710. </script>
  711. <style lang="scss" scoped>
  712. .app-content {
  713. min-height: calc(100vh - 100upx);
  714. padding-bottom: 150upx;
  715. }
  716. // 公共模块
  717. .module-com {
  718. margin-bottom: 20upx;
  719. background-color: #fff;
  720. color: $fontColor2;
  721. .module-tit {
  722. padding: 20upx 30upx;
  723. font-size: 28upx;
  724. }
  725. .module-det {
  726. padding: 0 30upx;
  727. }
  728. }
  729. .category-wrap {
  730. align-items: flex-start;
  731. padding-bottom: 0 !important;
  732. .tui-input {
  733. @include disFlex(center, flex-start);
  734. flex-wrap: wrap;
  735. .admin-button-com {
  736. margin-right: 20upx;
  737. margin-bottom: 20upx;
  738. position: relative;
  739. z-index: 99;
  740. }
  741. }
  742. }
  743. .use-img{
  744. font-size: 22rpx;
  745. color: #999999;
  746. padding-left: 4rpx 8rpx;
  747. line-height: 1.5;
  748. }
  749. .no-img-tip {
  750. font-size: 26rpx;
  751. color: #cccccc;
  752. padding: 12rpx 0;
  753. }
  754. .summary-wrap {
  755. .goods-summary {
  756. height: 400upx;
  757. }
  758. }
  759. .app-footer {
  760. justify-content: space-evenly;
  761. z-index: 9999;
  762. .admin-button-com {
  763. width: 46%;
  764. }
  765. }
  766. // 权重提醒图标样式
  767. .weight-reminder-icon {
  768. margin-left: 20upx;
  769. padding: 10upx;
  770. width: 60upx;
  771. height: 60upx;
  772. display: flex;
  773. align-items: center;
  774. justify-content: center;
  775. background-color: #f5f5f5;
  776. border-radius: 50%;
  777. border: 1upx solid #ddd;
  778. }
  779. // 权重弹窗样式
  780. .weight-popup-style {
  781. .weight-popup-container {
  782. width: 600upx;
  783. max-height: 80vh;
  784. padding: 30upx;
  785. border-radius: 16upx;
  786. background-color: #fff;
  787. z-index:9999;
  788. .weight-popup-title {
  789. font-size: 32upx;
  790. font-weight: bold;
  791. color: #333;
  792. text-align: center;
  793. margin-bottom: 30upx;
  794. }
  795. .weight-popup-content {
  796. .weight-item {
  797. display: flex;
  798. justify-content: space-between;
  799. align-items: center;
  800. padding: 20upx 0;
  801. border-bottom: 1upx solid #f0f0f0;
  802. &:last-child {
  803. border-bottom: none;
  804. }
  805. .weight-name {
  806. font-size: 28upx;
  807. color: #333;
  808. font-weight: 500;
  809. }
  810. .weight-value {
  811. font-size: 28upx;
  812. color: #666;
  813. }
  814. }
  815. }
  816. .weight-popup-note {
  817. margin-top: 30upx;
  818. padding: 20upx;
  819. background-color: #f8f8f8;
  820. border-radius: 8upx;
  821. font-size: 28upx;
  822. color: #999;
  823. line-height: 1.5;
  824. }
  825. .weight-popup-footer {
  826. margin-top: 30upx;
  827. display: flex;
  828. justify-content: center;
  829. }
  830. }
  831. }
  832. .class-popup-style {
  833. z-index: 99999;
  834. }
  835. </style>