copy.vue 30 KB

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