add.vue 30 KB

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