copy.vue 32 KB

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