add.vue 17 KB

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