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