copy.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. <view class="tui-title">所属产品</view>
  57. <view>
  58. <block v-if="form.cpInfo && !$util.isEmpty(form.cpInfo)">
  59. <button v-for="(cpItem, cpIndex) in form.cpInfo" class="admin-button-com blue mini-btn" style="margin-right:8upx;" @click.stop="delOneCp(cpItem,cpIndex)">{{cpItem.cpName}} ×</button>
  60. </block>
  61. <button class="admin-button-com default mini-btn" @click.stop="changeCp()">添加产品</button>
  62. </view>
  63. </tui-list-cell>
  64. <tui-list-cell class="line-cell" :hover="false">
  65. <div class="tui-title">比例类型</div>
  66. <radio-group class="tui-input flex-center-between" @change="ratioTypeChange">
  67. <label class="list" for="fixedLink">
  68. <radio id="fixedLink" value="0" :checked="form.ratioType == 0" style="transform: scale(0.7,0.7);" />
  69. <span class="checkbox-text" style="font-size:30upx;">固定</span>
  70. </label>
  71. <label class="list" for="dimLink">
  72. <radio id="dimLink" value="1" :checked="form.ratioType == 1" style="transform: scale(0.7,0.7);" />
  73. <span class="checkbox-text" style="font-size:30upx;">模糊(若干)</span>
  74. </label>
  75. </radio-group>
  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.bigUnitId" :range="unitData" range-key="name" @change="changeBigUnitFn" class="tui-input">
  80. <input v-model="form.bigUnitId" name="bigUnitId" type="text" hidden />
  81. <div v-if="form.bigUnitId">{{ bigUnitSelectedData.name }}</div>
  82. <div class="tui-placeholder" style="height:45upx;" v-else>请选择</div>
  83. </picker>
  84. </tui-list-cell>
  85. <tui-list-cell class="line-cell" :arrow="true">
  86. <div class="tui-title">小单位</div>
  87. <picker mode="selector" :value="form.smallUnitId" :range="unitData" range-key="name" @change="changeSmallUnitFn" class="tui-input">
  88. <input v-model="form.smallUnitId" name="smallUnitId" type="text" hidden />
  89. <div v-if="form.smallUnitId">{{ smallUnitSelectedData.name }}</div>
  90. <div class="tui-placeholder" v-else>请选择</div>
  91. </picker>
  92. </tui-list-cell>
  93. <tui-list-cell class="line-cell" :hover="false" v-if="form.ratioType == 0">
  94. <view class="tui-title">单位比</view>
  95. <input v-model="form.ratio" placeholder-class="phcolor" class="tui-input" name="ratio" @focus="form.ratio=''" placeholder="1扎=20支,请填写20" maxlength="50" type="number" />
  96. </tui-list-cell>
  97. <tui-list-cell class="line-cell" :hover="false">
  98. <view class="tui-title">每扎重量</view>
  99. <input v-model="form.weight" placeholder-class="phcolor" class="tui-input" name="weight" @focus="form.weight=''" placeholder="单位为公斤,参考红玫每扎1.2公斤" maxlength="50" type="digit" />
  100. </tui-list-cell>
  101. <tui-list-cell class="line-cell" :hover="false">
  102. <view class="tui-title">库存预警</view>
  103. <input v-model="form.stockWarning" @focus="form.stockWarning=''" placeholder-class="phcolor" class="tui-input" name="stockWarning" placeholder="请填写" maxlength="50" type="number" />
  104. </tui-list-cell>
  105. <tui-list-cell class="line-cell" :hover="false">
  106. <view class="tui-title">花材状态</view>
  107. <view class="switch_bx">
  108. <text v-if="form.status == 1">上架</text>
  109. <text v-else>下架</text>
  110. </view>
  111. </tui-list-cell>
  112. </view>
  113. <view class="module-com input-line-wrap goods-wrap">
  114. <view class="module-tit">
  115. <span>花材图片</span>
  116. <span class="app-color-3"></span>
  117. </view>
  118. <view class="module-det">
  119. <htz-image-upload :max="1" :compress="true" v-model="currentImgData" :headers="headers"
  120. @uploadSuccess="imgUploadSuccess" @imgDelete="imgDeleteFn" :action="getLoginInfo.imgUploadApi">
  121. </htz-image-upload>
  122. </view>
  123. </view>
  124. <view class="module-com input-line-wrap">
  125. <tui-list-cell class="line-cell" :hover="false">
  126. <view class="tui-title">大客价加价</view>
  127. <input v-model="form.hjAddPrice" placeholder-class="phcolor" class="tui-input" name="hjAddPrice" @focus="form.hjAddPrice=''" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
  128. </tui-list-cell>
  129. <tui-list-cell class="line-cell" :hover="false">
  130. <view class="tui-title">批发价加价</view>
  131. <input v-model="form.addPrice" placeholder-class="phcolor" class="tui-input" name="addPrice" @focus="form.addPrice=''" placeholder="在成本价基础上多卖的金额" maxlength="50" type="digit" />
  132. </tui-list-cell>
  133. <tui-list-cell class="line-cell" :hover="false">
  134. <view class="tui-title">零售价加价</view>
  135. <input v-model="form.skMore" placeholder-class="phcolor" class="tui-input" name="skMore" @focus="form.skMore=''" placeholder="在成本价基础上多卖的金额" type="digit" />
  136. </tui-list-cell>
  137. <tui-list-cell class="line-cell" :hover="false">
  138. <view class="tui-title">顺序值</view>
  139. <input v-model="form.inTurn" placeholder-class="phcolor" class="tui-input" name="inTurn" @focus="form.inTurn=''" placeholder="请填写数字" type="number" />
  140. </tui-list-cell>
  141. <tui-list-cell class="line-cell" :hover="false">
  142. <view class="tui-title">拆散单价</view>
  143. <input v-model="form.smallRatio" @focus="form.smallRatio=''" placeholder-class="phcolor" class="tui-input" name="smallRatio" placeholder="请填写" maxlength="50"
  144. type="number" style="width:160upx;border:1upx solid #cccccc;text-align:center;" />
  145. <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>
  146. </tui-list-cell>
  147. </view>
  148. <view class="app-footer">
  149. <button class="admin-button-com big default" @click="goBack()">取消</button>
  150. <button v-if="option.ptItemId" class="admin-button-com big blue" formType="submit" @click="status = 1">添加</button>
  151. <button v-else class="admin-button-com big blue" formType="submit" @click="status = 1">确认</button>
  152. </view>
  153. </form>
  154. <uni-popup ref="classRef" background-color="#fff" type="center" :animation="false" class="class-popup-style">
  155. <view style="margin-left:30upx;margin-top:19upx;font-size:27upx;font-weight:bold;">请选择分类:</view>
  156. <view style="display:flex;padding:20upx;height:auto;justify-content: space-between;align-items:center;flex-wrap:wrap;max-height:100vh;overflow:auto;">
  157. <view v-for="(item, index) in itemClassData" :key="index" @tap.stop="setThisClass(item)" style="margin-bottom:20upx;margin-left:3upx;">
  158. <image :src="item.cover" style="width:120upx;height:120upx;border-radius:10upx;"></image>
  159. <view style="margin-top:5upx;overflow: hidden;white-space: nowrap;width:120upx;text-align:center;">{{item.name}}</view>
  160. </view>
  161. </view>
  162. </uni-popup>
  163. </view>
  164. </template>
  165. <script>
  166. import TuiListCell from "@/components/plugin/list-cell";
  167. const form = require("@/utils/formValidation.js");
  168. import { getAllItemClass } from "@/api/item-class";
  169. import { getAllUnit } from "@/api/unit";
  170. import { addProduct,cloneProduct,getProductDetail,py } from "@/api/product";
  171. import { getPtItemDetail } from "@/api/pt-item";
  172. import { mapGetters } from "vuex"
  173. //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
  174. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
  175. export default {
  176. name: "item-detail",
  177. components: {
  178. TuiListCell,
  179. htzImageUpload
  180. },
  181. data() {
  182. return {
  183. status: 1,
  184. currentImgData: [],
  185. form: {
  186. id:0,
  187. name:"",
  188. py:"",
  189. stock:0,
  190. ratio:'',
  191. bigUnitId:1,
  192. smallUnitId:2,
  193. classId:'',
  194. className:'',
  195. price:'',
  196. skPrice:'',
  197. hjPrice:'',
  198. skMore:6,
  199. inTurn:100,
  200. addPrice:3,
  201. hjAddPrice:2,
  202. discountPrice:0,
  203. skDiscountPrice:0,
  204. hjDiscountPrice:0,
  205. cost:0,
  206. weight:'',
  207. cover:[],
  208. stockWarning:5,
  209. status:2,
  210. itemId:0,
  211. smallRatio:1,
  212. ratioType:0,
  213. cpInfo:[]
  214. },
  215. itemClassData:[],
  216. unitData:[],
  217. smallUnitSelectedData:{},
  218. bigUnitSelectedData:{},
  219. hasRequest:0,
  220. productData:{id:0},
  221. headers:{token:''},
  222. backCpInfo:{cpId:0,cpName:'',needUpdate:0}
  223. };
  224. },
  225. computed:{
  226. ...mapGetters(["getLoginInfo","getDictionariesInfo"])
  227. },
  228. onLoad(option) {
  229. if(option.id){
  230. this.form.id = this.option.id
  231. }
  232. const token = uni.getStorageSync('token')
  233. this.headers.token = token
  234. },
  235. onShow(){
  236. let that = this
  237. if(this.backCpInfo.needUpdate == 1){
  238. let needAdd = 1;
  239. if (!this.$util.isEmpty(this.form.cpInfo)) {
  240. that.form.cpInfo.forEach((item) => {
  241. if(item.cpId == that.backCpInfo.cpId){
  242. needAdd = 0
  243. }
  244. })
  245. }
  246. if(needAdd == 1){
  247. that.form.cpInfo.push({cpId:that.backCpInfo.cpId,cpName:that.backCpInfo.cpName})
  248. that.backCpInfo.needUpdate = 0
  249. that.$forceUpdate()
  250. }
  251. }
  252. },
  253. methods: {
  254. delOneCp(info,index){
  255. let that = this
  256. that.$util.confirmModal({content:'确认删除'+info.cpName+'?'},() => {
  257. that.form.cpInfo.splice(index,1)
  258. that.$forceUpdate()
  259. })
  260. },
  261. changeCp(item){
  262. this.$util.pageTo({url: '/admin/cp/list?skip=1'})
  263. },
  264. changeClass(item){
  265. this.$refs.classRef.open('center')
  266. },
  267. setThisClass(info){
  268. this.$refs.classRef.close()
  269. this.form.classId = info.id ? info.id : 0
  270. this.form.className = info.name ? info.name : ''
  271. this.$forceUpdate()
  272. },
  273. tjLinkage(){
  274. if(this.form.discountPrice && Number(this.form.discountPrice)>0){
  275. let skMore = this.form.skMore ? Number(this.form.skMore) : 0
  276. let hjAddPrice = this.form.hjAddPrice ? Number(this.form.hjAddPrice) : 0
  277. let addPrice = this.form.addPrice ? Number(this.form.addPrice) : 0
  278. let skAddNum = Number(skMore) - Number(addPrice)
  279. skAddNum = skAddNum.toFixed(2)
  280. let skAmount = Number(skAddNum) + Number(this.form.discountPrice)
  281. if(skAmount>0){
  282. skAmount = skAmount.toFixed(2)
  283. skAmount = parseFloat(skAmount)
  284. this.form.skDiscountPrice = skAmount
  285. }else{
  286. this.form.skDiscountPrice = 0.01
  287. }
  288. let hjSubNum = Number(addPrice) - Number(hjAddPrice)
  289. hjSubNum = hjSubNum.toFixed(2)
  290. let hjAmount = Number(this.form.discountPrice) - Number(hjSubNum)
  291. if(hjAmount > 0){
  292. hjAmount = hjAmount.toFixed(2)
  293. hjAmount = parseFloat(hjAmount)
  294. this.form.hjDiscountPrice = hjAmount
  295. }else{
  296. this.form.hjDiscountPrice = 0.01
  297. }
  298. }else{
  299. this.form.skDiscountPrice = 0
  300. this.form.hjDiscountPrice = 0
  301. }
  302. },
  303. priceLinkage(){
  304. if(this.form.price && Number(this.form.price)>0){
  305. let skMore = this.form.skMore ? Number(this.form.skMore) : 0
  306. let hjAddPrice = this.form.hjAddPrice ? Number(this.form.hjAddPrice) : 0
  307. let addPrice = this.form.addPrice ? Number(this.form.addPrice) : 0
  308. let skAddNum = Number(skMore) - Number(addPrice)
  309. skAddNum = skAddNum.toFixed(2)
  310. let skAmount = Number(skAddNum) + Number(this.form.price)
  311. if(skAmount>0){
  312. skAmount = skAmount.toFixed(2)
  313. skAmount = parseFloat(skAmount)
  314. this.form.skPrice = skAmount
  315. }else{
  316. this.form.skPrice = ''
  317. }
  318. let hjSubNum = Number(addPrice) - Number(hjAddPrice)
  319. hjSubNum = hjSubNum.toFixed(2)
  320. let hjAmount = Number(this.form.price) - Number(hjSubNum)
  321. if(hjAmount > 0){
  322. hjAmount = hjAmount.toFixed(2)
  323. hjAmount = parseFloat(hjAmount)
  324. this.form.hjPrice = hjAmount
  325. }else{
  326. this.form.hjPrice = ''
  327. }
  328. }else{
  329. this.form.skPrice = ''
  330. this.form.hjPrice = ''
  331. this.form.discountPrice = 0
  332. this.form.skDiscountPrice = 0
  333. this.form.hjDiscountPrice = 0
  334. }
  335. },
  336. notModify(){
  337. this.$msg('不可修改')
  338. },
  339. goStockDetail(item){
  340. this.$util.pageTo({url: "/pagesStorehouse/stockWarn/detailed?id="+item.id+'&name='+item.name})
  341. },
  342. statusChange(e){
  343. this.form.status = e.detail.value ? 1 : 2;
  344. },
  345. ratioTypeChange(e){
  346. this.form.ratioType = e.detail.value
  347. },
  348. //如果库存被修改则花材状态变化
  349. changeStock(event){
  350. let num = Number(event.target.value)
  351. if(num > 0){
  352. this.form.status = 1
  353. }else{
  354. this.form.status = 2
  355. }
  356. },
  357. //获取拼音首字母 shish 20210707
  358. fillName(event){
  359. let val = event.target.value
  360. py({
  361. name:val
  362. }).then(res => {
  363. if(res.data.py){
  364. this.form.py = res.data.py
  365. }
  366. });
  367. },
  368. goBack(){
  369. uni.navigateBack({ delta: 1 })
  370. },
  371. changeBigUnitFn(e){
  372. this.bigUnitSelectedData = this.unitData[e.detail.value];
  373. this.form.bigUnitId = this.bigUnitSelectedData.id;
  374. },
  375. changeSmallUnitFn(e){
  376. this.smallUnitSelectedData = this.unitData[e.detail.value];
  377. this.form.smallUnitId = this.smallUnitSelectedData.id;
  378. },
  379. getPtItemInfo(ptItemId){
  380. getPtItemDetail({id:ptItemId}).then(res=>{
  381. if (this.$util.isEmpty(res.data)) {
  382. return;
  383. }
  384. Object.keys(this.form).forEach((i, index) => {
  385. this.form[i] = res.data[i];
  386. });
  387. this.currentImgData.push(res.data.cover)
  388. this.form.cover = [res.data.shortCover]
  389. this.form.stock = ''
  390. this.form.itemId = ptItemId
  391. this.form.classId = ''
  392. this.form.status = 1
  393. this.form.id = 0
  394. this.form.price = ''
  395. this.form.skPrice = ''
  396. this.form.hjPrice = ''
  397. this.form.skMore = 6
  398. this.form.addPrice = 3
  399. this.form.hjAddPrice = 3
  400. this.form.discountPrice = 0
  401. this.form.cost = 0
  402. this.form.inTurn = 100
  403. })
  404. },
  405. getDetail() {
  406. return getProductDetail({ id: this.option.id }).then(res => {
  407. if (this.$util.isEmpty(res.data)) {
  408. return;
  409. }
  410. Object.keys(this.form).forEach((i, index) => {
  411. this.form[i] = res.data[i];
  412. });
  413. this.currentImgData.push(res.data.cover)
  414. this.form.cover = [res.data.shortCover]
  415. this.form.price = res.data.prePrice
  416. this.form.stock = 0
  417. let currentClass = this.itemClassData.filter(
  418. e => this.form.classId == e.id
  419. )[0];
  420. this.form.className = currentClass.name ? currentClass.name : ''
  421. this.smallUnitSelectedData = this.unitData.filter(
  422. e => this.form.smallUnitId == e.id
  423. )[0];
  424. this.bigUnitSelectedData = this.unitData.filter(
  425. e => this.form.bigUnitId == e.id
  426. )[0];
  427. this.productData = res.data
  428. this.productData.id = 0
  429. });
  430. },
  431. imgUploadSuccess(res) {
  432. var _res = JSON.parse(res.data)
  433. if(_res.code == 1){
  434. this.currentImgData.push(_res.data.smallUrl)
  435. this.form.cover.push(_res.data.shortUrl)
  436. }
  437. },
  438. imgDeleteFn(res){
  439. const index = res.index
  440. this.form.cover.splice(index,1)
  441. },
  442. init() {
  443. //从平台选择花材
  444. if(!this.$util.isEmpty(this.option.ptItemId)){
  445. uni.setNavigationBarTitle({title: "确认花材信息"})
  446. }
  447. if(this.hasRequest == 1){
  448. return
  449. }
  450. this._getAllUnit().then(res=>{
  451. this._getAllItemClass().then(res => {
  452. if(this.form.id == 0){
  453. this.smallUnitSelectedData = this.unitData.filter(e => 2 == e.id)[0];
  454. this.bigUnitSelectedData = this.unitData.filter(e => 1 == e.id)[0];
  455. //从平台选择花材
  456. if(!this.$util.isEmpty(this.option.ptItemId)){
  457. this.getPtItemInfo(this.option.ptItemId)
  458. }
  459. }else{
  460. this.getDetail();
  461. }
  462. });
  463. })
  464. this.hasRequest = 1
  465. },
  466. async _getAllUnit() {
  467. await getAllUnit().then(res => {
  468. if (this.$util.isEmpty(res.data)){
  469. return false;
  470. }
  471. this.unitData = res.data.list;
  472. });
  473. },
  474. async _getAllItemClass() {
  475. await getAllItemClass().then(res => {
  476. if (this.$util.isEmpty(res.data)){
  477. return false;
  478. }
  479. this.itemClassData = res.data;
  480. });
  481. },
  482. // 确认
  483. confirmFn() {
  484. if (this.$util.isEmpty(this.form.cover)) {
  485. this.$msg("请上传图片")
  486. return false
  487. }
  488. let requestHost = addProduct
  489. if(this.form.id && this.form.id != 0){
  490. requestHost = cloneProduct;
  491. }else{
  492. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.stock) == false){
  493. uni.showToast({title:"请填写库存,没有请填0",icon:"none"})
  494. return;
  495. }
  496. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.discountPrice) == false){
  497. uni.showToast({title:"请填写特价,没有特价请填0",icon:"none"})
  498. return;
  499. }
  500. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.cost) == false){
  501. uni.showToast({title:"请填写成本",icon:"none"})
  502. return;
  503. }
  504. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.price) == false){
  505. uni.showToast({title:"请填写批发价",icon:"none"})
  506. return;
  507. }
  508. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.hjPrice) == false){
  509. uni.showToast({title:"请填写大客价",icon:"none"})
  510. return;
  511. }
  512. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skPrice) == false){
  513. uni.showToast({title:"请填写零售价",icon:"none"})
  514. return;
  515. }
  516. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.addPrice) == false){
  517. uni.showToast({title:"请填写批发价加价",icon:"none"})
  518. return;
  519. }
  520. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skMore) == false){
  521. uni.showToast({title:"请填写零售价加价",icon:"none"})
  522. return;
  523. }
  524. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.hjAddPrice) == false){
  525. uni.showToast({title:"请填写大客价加价",icon:"none"})
  526. return;
  527. }
  528. }
  529. let form = JSON.parse(JSON.stringify(this.form))
  530. uni.showLoading({mask:true})
  531. requestHost({...form,cover:this.form.cover[0],appVersion:1}).then(res => {
  532. uni.hideLoading()
  533. if(res.code == 1){
  534. this.$msg("操作成功");
  535. //返回上一页带参数
  536. let pages = getCurrentPages();
  537. let prevPage = pages[ pages.length - 2 ];
  538. let hidden = 0
  539. if(this.form.stock > this.form.stockWarning){
  540. hidden = 1
  541. }
  542. prevPage.$vm.modifyStock = {id:this.form.id,stock:this.form.stock,hidden:hidden};
  543. uni.navigateBack({})
  544. }
  545. });
  546. },
  547. // 表单验证
  548. formSubmit(e) {
  549. // 表单规则
  550. let rules = [
  551. {
  552. name: "name",
  553. rule: ["required"],
  554. msg: ["请填写名称"]
  555. },
  556. {
  557. name: "py",
  558. rule: ["required"],
  559. msg: ["请填写拼音缩写"]
  560. },{
  561. name: "stock",
  562. rule: ["required"],
  563. msg: ["请填写库存,没有填0"]
  564. },
  565. {
  566. name: "bigUnitId",
  567. rule: ["required"],
  568. msg: ["请选择大单位"]
  569. },
  570. {
  571. name: "smallUnitId",
  572. rule: ["required"],
  573. msg: ["请选择小单位"]
  574. },
  575. {
  576. name: "price",
  577. rule: ["required"],
  578. msg: ["请填写批发价"]
  579. },
  580. {
  581. name: "skPrice",
  582. rule: ["required"],
  583. msg: ["请填写零售价"]
  584. },
  585. {
  586. name: "hjPrice",
  587. rule: ["required"],
  588. msg: ["请填写大客价"]
  589. },
  590. {
  591. name: "addPrice",
  592. rule: ["required"],
  593. msg: ["请填写批发价加价"]
  594. },
  595. {
  596. name: "hjAddPrice",
  597. rule: ["required"],
  598. msg: ["请填写大客价加价"]
  599. },
  600. {
  601. name: "discountPrice",
  602. rule: ["required"],
  603. msg: ["不做特价请填0"]
  604. },
  605. {
  606. name: "cost",
  607. rule: ["required"],
  608. msg: ["请填写成本"]
  609. },
  610. {
  611. name: "skMore",
  612. rule: ["required"],
  613. msg: ["请填写零售价加价"]
  614. },
  615. {
  616. name: "weight",
  617. rule: ["required"],
  618. msg: ["请填写重量"]
  619. },
  620. {
  621. name: "classId",
  622. rule: ["required"],
  623. msg: ["请选择分类"]
  624. },
  625. {
  626. name: "stockWarning",
  627. rule: ["required"],
  628. msg: ["请填写库存预警"]
  629. }
  630. ];
  631. // 进行表单检查
  632. let formData = e.detail.value;
  633. let checkRes = form.validation(formData, rules);
  634. // 验证通过!
  635. if (!checkRes) {
  636. this.confirmFn()
  637. } else {
  638. this.$msg(checkRes);
  639. }
  640. }
  641. }
  642. };
  643. </script>
  644. <style lang="scss" scoped>
  645. .app-content {
  646. min-height: calc(100vh - 100upx);
  647. padding-bottom: 150upx;
  648. }
  649. // 公共模块
  650. .module-com {
  651. margin-bottom: 20upx;
  652. background-color: #fff;
  653. color: $fontColor2;
  654. .module-tit {
  655. padding: 20upx 30upx;
  656. font-size: 28upx;
  657. }
  658. .module-det {
  659. padding: 0 30upx;
  660. }
  661. }
  662. .category-wrap {
  663. align-items: flex-start;
  664. padding-bottom: 0 !important;
  665. .tui-input {
  666. @include disFlex(center, flex-start);
  667. flex-wrap: wrap;
  668. .admin-button-com {
  669. margin-right: 20upx;
  670. margin-bottom: 20upx;
  671. position: relative;
  672. z-index: 9999;
  673. }
  674. }
  675. }
  676. .summary-wrap {
  677. .goods-summary {
  678. height: 400upx;
  679. }
  680. }
  681. .app-footer {
  682. justify-content: space-evenly;
  683. z-index: 9999;
  684. .admin-button-com {
  685. width: 46%;
  686. }
  687. }
  688. </style>