copy.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <view class="app-content">
  3. <!-- 花材基本信息 -->
  4. <form @submit="formSubmit">
  5. <view class="module-com input-line-wrap">
  6. <tui-list-cell class="line-cell" :hover="false">
  7. <view class="tui-title">花材名称</view>
  8. <input v-model="form.name" placeholder-class="phcolor" class="tui-input" name="name" placeholder="请填写名称" @input="fillName($event)" maxlength="50" type="text" />
  9. </tui-list-cell>
  10. <tui-list-cell class="line-cell" :hover="false">
  11. <view class="tui-title">花材品种</view>
  12. <view style="color:#CCCCCC;width:450upx;height:45upx;" @click.stop="notModify">{{productData.ptItemInfo ? productData.ptItemInfo.name : ''}}</view>
  13. </tui-list-cell>
  14. <tui-list-cell class="line-cell" :hover="false">
  15. <view class="tui-title">拼音缩写</view>
  16. <input v-model="form.py" placeholder-class="phcolor" class="tui-input" name="py" placeholder="请填写拼音首字母缩写" maxlength="50" type="text" />
  17. </tui-list-cell>
  18. <tui-list-cell class="line-cell" :hover="false">
  19. <view class="tui-title">售价</view>
  20. <input v-model="form.price" placeholder-class="phcolor" class="tui-input" name="price" @focus="form.price=''" placeholder="请填写售价" maxlength="50" type="digit" />
  21. </tui-list-cell>
  22. <tui-list-cell class="line-cell" :hover="false">
  23. <view class="tui-title">今日特价</view>
  24. <input v-model="form.discountPrice" placeholder-class="phcolor" class="tui-input" name="discountPrice" @focus="form.discountPrice=''" placeholder="不做特价填0" maxlength="50" type="digit" />
  25. </tui-list-cell>
  26. <tui-list-cell class="line-cell" :hover="false">
  27. <view class="tui-title">单支售价系数</view>
  28. <input v-model="form.smallRatio" placeholder-class="phcolor" class="tui-input" name="smallRatio" placeholder="请填写" style="width:230upx;" @focus="form.smallRatio=''"
  29. maxlength="50" type="number" /><text style="color:#CCCCCC;">¥<text>{{smallPrice}}</text></text>
  30. </tui-list-cell>
  31. <tui-list-cell class="line-cell" :hover="false">
  32. <view class="tui-title">库存</view>
  33. <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"/>
  34. <button v-if="productData.id > 0" class="admin-button-com blue middle" @click="goStockDetail(productData.id)">库存变动明细</button>
  35. </tui-list-cell>
  36. <tui-list-cell class="line-cell" :arrow="true">
  37. <view class="tui-title">分类</view>
  38. <picker mode="selector" :value="form.classId" :range="itemClassData" range-key="name" @change="changeItemClassFn" class="tui-input" >
  39. <input v-model="form.classId" name="classId" type="text" hidden />
  40. <view v-if="form.classId" style="height:45upx;" >{{ itemClassSelectedData.name }}</view>
  41. <view class="tui-placeholder" style="height:45upx;" v-else>请选择</view>
  42. </picker>
  43. </tui-list-cell>
  44. <tui-list-cell class="line-cell" :arrow="true">
  45. <div class="tui-title">大单位</div>
  46. <picker mode="selector" :value="form.bigUnitId" :range="unitData" range-key="name" @change="changeBigUnitFn" class="tui-input">
  47. <input v-model="form.bigUnitId" name="bigUnitId" type="text" hidden />
  48. <div v-if="form.bigUnitId">{{ bigUnitSelectedData.name }}</div>
  49. <div class="tui-placeholder" style="height:45upx;" v-else>请选择</div>
  50. </picker>
  51. </tui-list-cell>
  52. <tui-list-cell class="line-cell" :arrow="true">
  53. <div class="tui-title">小单位</div>
  54. <picker mode="selector" :value="form.smallUnitId" :range="unitData" range-key="name" @change="changeSmallUnitFn" class="tui-input">
  55. <input v-model="form.smallUnitId" name="smallUnitId" type="text" hidden />
  56. <div v-if="form.smallUnitId">{{ smallUnitSelectedData.name }}</div>
  57. <div class="tui-placeholder" v-else>请选择</div>
  58. </picker>
  59. </tui-list-cell>
  60. <tui-list-cell class="line-cell" :hover="false">
  61. <view class="tui-title">散客加价</view>
  62. <input v-model="form.skAddPrice" placeholder-class="phcolor" class="tui-input" name="skAddPrice" @focus="form.skAddPrice=''" placeholder="请填写" maxlength="50" type="digit" />
  63. </tui-list-cell>
  64. <tui-list-cell class="line-cell" :hover="false">
  65. <view class="tui-title">花店加价</view>
  66. <input v-model="form.addPrice" placeholder-class="phcolor" class="tui-input" name="addPrice" @focus="form.addPrice=''" placeholder="请填写" maxlength="50" type="digit" />
  67. </tui-list-cell>
  68. <tui-list-cell class="line-cell" :hover="false">
  69. <view class="tui-title">单位比</view>
  70. <input v-model="form.ratio" placeholder-class="phcolor" class="tui-input" name="ratio" @focus="form.ratio=''" placeholder="如:1扎=20支,请填写20" maxlength="50" type="number" />
  71. </tui-list-cell>
  72. <tui-list-cell class="line-cell" :hover="false">
  73. <view class="tui-title">每扎重量</view>
  74. <input v-model="form.weight" placeholder-class="phcolor" class="tui-input" name="weight" @focus="form.weight=''" placeholder="单位:公斤" maxlength="50" type="digit" />
  75. </tui-list-cell>
  76. <tui-list-cell class="line-cell" :hover="false">
  77. <view class="tui-title">库存预警值</view>
  78. <input v-model="form.stockWarning" @focus="form.stockWarning=''" placeholder-class="phcolor" class="tui-input" name="stockWarning" placeholder="请填写" maxlength="50" type="number" />
  79. </tui-list-cell>
  80. <tui-list-cell class="line-cell" :hover="false">
  81. <view class="tui-title">上架状态</view>
  82. <view class="switch_bx">
  83. <switch :checked="form.status == 2 ? false : true" @change="statusChange" style="transform: scale(0.8,0.8)" />
  84. <text v-if="form.status == 1">上架</text>
  85. <text v-else>下架</text>
  86. </view>
  87. </tui-list-cell>
  88. <tui-list-cell class="line-cell" :hover="false">
  89. <view class="tui-title">状态</view>
  90. <view class="switch_bx">
  91. <switch :checked="form.delStatus == 0 ? true : false" @change="delStatusChange" style="transform: scale(0.8,0.8)" />
  92. <text v-if="form.delStatus == 0">启用</text>
  93. <text v-else>停用</text>
  94. </view>
  95. </tui-list-cell>
  96. </view>
  97. <view class="module-com input-line-wrap goods-wrap">
  98. <view class="module-tit">
  99. <span>花材图片</span>
  100. <span class="app-color-3">(建议比例 1:1)</span>
  101. </view>
  102. <view class="module-det">
  103. <htz-image-upload :max="1" :compress="true" v-model="currentImgData" :headers="headers"
  104. @uploadSuccess="imgUploadSuccess" @imgDelete="imgDeleteFn" :action="getLoginInfo.imgUploadApi">
  105. </htz-image-upload>
  106. </view>
  107. </view>
  108. <view class="app-footer">
  109. <button class="admin-button-com big default" @click="goBack()">取消</button>
  110. <button v-if="option.ptItemId" class="admin-button-com big blue" formType="submit" @click="status = 1">添加</button>
  111. <button v-else class="admin-button-com big blue" formType="submit" @click="status = 1">确认</button>
  112. </view>
  113. </form>
  114. </view>
  115. </template>
  116. <script>
  117. import TuiListCell from "@/components/plugin/list-cell";
  118. const form = require("@/utils/formValidation.js");
  119. import { getAllItemClass } from "@/api/item-class";
  120. import { getAllUnit } from "@/api/unit";
  121. import { addProduct,cloneProduct,getProductDetail,py } from "@/api/product";
  122. import { getPtItemDetail } from "@/api/pt-item";
  123. import { mapGetters } from "vuex"
  124. //图片上传插件来源:https://ext.dcloud.net.cn/plugin?id=2922 已改造,不能再升级 shish 20211228
  125. import htzImageUpload from './components/htz-image-upload/htz-image-upload.vue'
  126. export default {
  127. name: "item-detail",
  128. components: {
  129. TuiListCell,
  130. htzImageUpload
  131. },
  132. data() {
  133. return {
  134. status: 1,
  135. currentImgData: [],
  136. form: {
  137. id:0,
  138. name:"",
  139. py:"",
  140. stock:'',
  141. ratio:'',
  142. smallRatio:'',
  143. bigUnitId:1,
  144. smallUnitId:2,
  145. classId:'',
  146. price:'',
  147. skAddPrice:'',
  148. addPrice:'',
  149. discountPrice:'',
  150. weight:'',
  151. cover:[],
  152. stockWarning:'',
  153. status:2,
  154. delStatus:0,
  155. itemId:0,
  156. },
  157. itemClassSelectedData:{},
  158. itemClassData:[],
  159. unitData:[],
  160. smallUnitSelectedData:{},
  161. bigUnitSelectedData:{},
  162. hasRequest:0,
  163. productData:{id:0},
  164. headers:{token:''}
  165. };
  166. },
  167. computed:{
  168. ...mapGetters(["getLoginInfo","getDictionariesInfo"]),
  169. smallPrice(){
  170. let price = 0
  171. if(this.form.price){
  172. let div = Number(this.form.price)/Number(this.form.ratio)
  173. price = div*Number(this.form.smallRatio)
  174. price = parseFloat(price.toFixed(2))
  175. }
  176. return price
  177. }
  178. },
  179. onLoad(option) {
  180. if(option.id){
  181. this.form.id = this.option.id
  182. }
  183. const token = uni.getStorageSync('token')
  184. this.headers.token = token
  185. },
  186. watch:{
  187. },
  188. methods: {
  189. notModify(){
  190. this.$msg('不可修改')
  191. },
  192. goStockDetail(id){
  193. this.$util.pageTo({url: "/pagesStorehouse/stockWarn/detailed?id="+id})
  194. },
  195. statusChange(e){
  196. this.form.status = e.detail.value ? 1 : 2;
  197. },
  198. delStatusChange(e){
  199. this.form.delStatus = e.detail.value ? 0 : 1;
  200. },
  201. //如果库存被修改则花材状态变化
  202. changeStock(event){
  203. let num = Number(event.target.value)
  204. if(num > 0){
  205. this.form.status = 1
  206. }else{
  207. this.form.status = 2
  208. }
  209. },
  210. //获取拼音首字母 shish 20210707
  211. fillName(event){
  212. let val = event.target.value
  213. py({
  214. name:val
  215. }).then(res => {
  216. if(res.data.py){
  217. this.form.py = res.data.py
  218. }
  219. });
  220. },
  221. goBack(){
  222. uni.navigateBack({ delta: 1 })
  223. },
  224. changeBigUnitFn(e){
  225. this.bigUnitSelectedData = this.unitData[e.detail.value];
  226. this.form.bigUnitId = this.bigUnitSelectedData.id;
  227. },
  228. changeSmallUnitFn(e){
  229. this.smallUnitSelectedData = this.unitData[e.detail.value];
  230. this.form.smallUnitId = this.smallUnitSelectedData.id;
  231. },
  232. changeItemClassFn(e) {
  233. this.itemClassSelectedData = this.itemClassData[e.detail.value];
  234. this.form.classId = this.itemClassSelectedData.id;
  235. },
  236. //从平台导入花材 shish 20210826
  237. getPtItemInfo(ptItemId){
  238. getPtItemDetail({id:ptItemId}).then(res=>{
  239. if (this.$util.isEmpty(res.data)) {
  240. return;
  241. }
  242. Object.keys(this.form).forEach((i, index) => {
  243. this.form[i] = res.data[i];
  244. });
  245. this.currentImgData.push(res.data.cover)
  246. this.form.cover = [res.data.shortCover]
  247. this.form.stock = ''
  248. this.form.itemId = ptItemId
  249. this.form.classId = ''
  250. this.form.status = 1
  251. this.form.delStatus = 0
  252. this.form.id = 0
  253. this.form.price = ''
  254. this.form.skAddPrice =''
  255. this.form.addPrice =''
  256. this.form.discountPrice = ''
  257. })
  258. },
  259. getDetail() {
  260. return getProductDetail({ id: this.option.id }).then(res => {
  261. if (this.$util.isEmpty(res.data)) {
  262. return;
  263. }
  264. Object.keys(this.form).forEach((i, index) => {
  265. this.form[i] = res.data[i];
  266. });
  267. this.currentImgData.push(res.data.cover)
  268. this.form.cover = [res.data.shortCover]
  269. this.form.price = res.data.prePrice
  270. this.form.stock = 0
  271. this.itemClassSelectedData = this.itemClassData.filter(
  272. e => this.form.classId == e.id
  273. )[0];
  274. this.smallUnitSelectedData = this.unitData.filter(
  275. e => this.form.smallUnitId == e.id
  276. )[0];
  277. this.bigUnitSelectedData = this.unitData.filter(
  278. e => this.form.bigUnitId == e.id
  279. )[0];
  280. this.productData = res.data
  281. this.productData.id = 0
  282. });
  283. },
  284. imgUploadSuccess(res) {
  285. var _res = JSON.parse(res.data)
  286. if(_res.code == 1){
  287. this.currentImgData.push(_res.data.smallUrl)
  288. this.form.cover.push(_res.data.shortUrl)
  289. }
  290. },
  291. imgDeleteFn(res){
  292. const index = res.index
  293. this.form.cover.splice(index,1)
  294. },
  295. init() {
  296. //从平台导入花材
  297. if(!this.$util.isEmpty(this.option.ptItemId)){
  298. uni.setNavigationBarTitle({title: "确认花材信息"})
  299. }
  300. if(this.hasRequest == 1){
  301. return
  302. }
  303. this._getAllUnit().then(res=>{
  304. this._getAllItemClass().then(res => {
  305. if(this.form.id == 0){
  306. this.smallUnitSelectedData = this.unitData.filter(e => 2 == e.id)[0];
  307. this.bigUnitSelectedData = this.unitData.filter(e => 1 == e.id)[0];
  308. //从平台导入花材
  309. if(!this.$util.isEmpty(this.option.ptItemId)){
  310. this.getPtItemInfo(this.option.ptItemId)
  311. }
  312. }else{
  313. this.getDetail();
  314. }
  315. });
  316. })
  317. this.hasRequest = 1
  318. },
  319. async _getAllUnit() {
  320. await getAllUnit().then(res => {
  321. if (this.$util.isEmpty(res.data)){
  322. return false;
  323. }
  324. this.unitData = res.data.list;
  325. });
  326. },
  327. async _getAllItemClass() {
  328. await getAllItemClass().then(res => {
  329. if (this.$util.isEmpty(res.data)){
  330. return false;
  331. }
  332. this.itemClassData = res.data;
  333. });
  334. },
  335. // 确认
  336. confirmFn() {
  337. if (this.$util.isEmpty(this.form.cover)) {
  338. this.$msg("请上传图片")
  339. return false
  340. }
  341. let requestHost = addProduct
  342. if(this.form.id && this.form.id != 0){
  343. requestHost = cloneProduct;
  344. }else{
  345. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.stock) == false){
  346. uni.showToast({title:"请填写库存,没有请填0",icon:"none"})
  347. return;
  348. }
  349. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.discountPrice) == false){
  350. uni.showToast({title:"请填写特价,没有特价请填0",icon:"none"})
  351. return;
  352. }
  353. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.price) == false){
  354. uni.showToast({title:"请填写售价",icon:"none"})
  355. return;
  356. }
  357. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.skAddPrice) == false){
  358. uni.showToast({title:"请填写散客加价",icon:"none"})
  359. return;
  360. }
  361. if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.form.addPrice) == false){
  362. uni.showToast({title:"请填写普店加价",icon:"none"})
  363. return;
  364. }
  365. }
  366. let form = JSON.parse(JSON.stringify(this.form))
  367. uni.showLoading({mask:true})
  368. requestHost({...form,cover:this.form.cover[0]}).then(res => {
  369. uni.hideLoading()
  370. if(res.code == 1){
  371. this.$msg("操作成功");
  372. //返回上一页带参数
  373. let pages = getCurrentPages();
  374. let prevPage = pages[ pages.length - 2 ];
  375. let hidden = 0
  376. if(this.form.stock > this.form.stockWarning){
  377. hidden = 1
  378. }
  379. prevPage.$vm.modifyStock = {id:this.form.id,stock:this.form.stock,hidden:hidden};
  380. uni.navigateBack({})
  381. }
  382. });
  383. },
  384. // 表单验证
  385. formSubmit(e) {
  386. // 表单规则
  387. let rules = [
  388. {
  389. name: "name",
  390. rule: ["required"],
  391. msg: ["请填写名称"]
  392. },
  393. {
  394. name: "py",
  395. rule: ["required"],
  396. msg: ["请填写拼音缩写"]
  397. },{
  398. name: "stock",
  399. rule: ["required"],
  400. msg: ["请填写库存,没有填0"]
  401. },
  402. {
  403. name: "bigUnitId",
  404. rule: ["required"],
  405. msg: ["请选择大单位"]
  406. },
  407. {
  408. name: "smallUnitId",
  409. rule: ["required"],
  410. msg: ["请选择小单位"]
  411. },
  412. {
  413. name: "ratio",
  414. rule: ["required"],
  415. msg: ["请填写单位比"]
  416. },
  417. {
  418. name: "smallRatio",
  419. rule: ["required"],
  420. msg: ["请填写单支售价系数"]
  421. },
  422. {
  423. name: "price",
  424. rule: ["required"],
  425. msg: ["请填写售价"]
  426. },
  427. {
  428. name: "skAddPrice",
  429. rule: ["required"],
  430. msg: ["请填写散客加价"]
  431. },
  432. {
  433. name: "addPrice",
  434. rule: ["required"],
  435. msg: ["请填写普店加价"]
  436. },
  437. {
  438. name: "discountPrice",
  439. rule: ["required"],
  440. msg: ["不做特价请填0"]
  441. },
  442. {
  443. name: "weight",
  444. rule: ["required"],
  445. msg: ["请填写重量"]
  446. },
  447. {
  448. name: "classId",
  449. rule: ["required"],
  450. msg: ["请选择分类"]
  451. },
  452. {
  453. name: "stockWarning",
  454. rule: ["required"],
  455. msg: ["请填写库存预警值"]
  456. }
  457. ];
  458. // 进行表单检查
  459. let formData = e.detail.value;
  460. let checkRes = form.validation(formData, rules);
  461. // 验证通过!
  462. if (!checkRes) {
  463. this.confirmFn()
  464. } else {
  465. this.$msg(checkRes);
  466. }
  467. }
  468. }
  469. };
  470. </script>
  471. <style lang="scss" scoped>
  472. .app-content {
  473. min-height: calc(100vh - 100upx);
  474. padding-bottom: 150upx;
  475. }
  476. // 公共模块
  477. .module-com {
  478. margin-bottom: 20upx;
  479. background-color: #fff;
  480. color: $fontColor2;
  481. .module-tit {
  482. padding: 20upx 30upx;
  483. font-size: 28upx;
  484. }
  485. .module-det {
  486. padding: 0 30upx;
  487. }
  488. }
  489. .category-wrap {
  490. align-items: flex-start;
  491. padding-bottom: 0 !important;
  492. .tui-input {
  493. @include disFlex(center, flex-start);
  494. flex-wrap: wrap;
  495. .admin-button-com {
  496. margin-right: 20upx;
  497. margin-bottom: 20upx;
  498. position: relative;
  499. z-index: 9999;
  500. }
  501. }
  502. }
  503. .summary-wrap {
  504. .goods-summary {
  505. height: 400upx;
  506. }
  507. }
  508. .app-footer {
  509. justify-content: space-evenly;
  510. z-index: 9999;
  511. .admin-button-com {
  512. width: 46%;
  513. }
  514. }
  515. </style>