editShelfHw.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <view class="content flex flex_column">
  3. <u-navbar back-text="编辑货位" :border-bottom="false">
  4. <view slot='right'
  5. style="padding: 0 30upx;"
  6. @click="enableShelfProduct"
  7. v-if="type=='edit'&&nowData&&nowData.shelfProductApiEntity&&(!nowData.shelfProductApiEntity.qty||(nowData.shelfProductApiEntity.enableFlag==0&&nowData.shelfProductApiEntity.qty))">
  8. <text :style="{color:nowData&&nowData.shelfProductApiEntity.enableFlag==1?$config('errorColor'):$config('primaryColor')}">{{nowData&&nowData.shelfProductApiEntity.enableFlag==1?'禁用':'启用'}}</text>
  9. </view>
  10. </u-navbar>
  11. <view class="form-body">
  12. <u-form :model="form" label-width="180rpx" :error-type="['toast']" ref="uForm">
  13. <u-form-item label="货位号" required prop="shelfPlaceCode" v-if="productEntity">
  14. <u-input v-model="form.shelfPlaceCode" @input="placeCodeBlur" border :maxlength="6" placeholder="请输入货位号(首字母+数字)格式"/>
  15. </u-form-item>
  16. <u-form-item label="货位号" v-else>
  17. <view class="flex align_center flex_1 justify_between">
  18. <view style="width: 80%;">{{shelfPlaceCode}}</view>
  19. <view style="width: 20%;text-align: center;" @click="editShelf"><u-icon name='edit-pen'></u-icon>修改</view>
  20. </view>
  21. </u-form-item>
  22. <view v-if="productEntity">
  23. <u-form-item label="" prop="productSn">
  24. <view class="flex flex_1 align_center">
  25. <view class="pimgs">
  26. <u-image :src="productEntity.productMsg?productEntity.productMsg:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  27. </view>
  28. <view class="pinfo flex_1">
  29. <view class="ptxt flex align_center justify_between">
  30. <text>{{productEntity.code}}</text>
  31. <text class="pcode" @click="toBindProduct" v-if="type=='bind'||(type=='edit'&&nowData&&nowData.shelfProductApiEntity&&nowData.shelfProductApiEntity.enableFlag==1)">
  32. <u-icon name='reload'></u-icon>
  33. 更换产品
  34. </text>
  35. <text v-else class="pcode" style="color: #999;">
  36. (已禁用)
  37. </text>
  38. </view>
  39. <view class="pname">
  40. {{productEntity.name}}
  41. </view>
  42. <view>
  43. 当前库存:{{productEntity.currQty||0}} {{productEntity.unit}}
  44. </view>
  45. </view>
  46. </view>
  47. </u-form-item>
  48. <u-form-item label="车主价(元)" required prop="price">
  49. <u-input clearable type="number" border :min="0" @input="numberToFixed('price',2,999999)" v-model="form.price" placeholder="请输入销售价,最多两位小数"/>
  50. </u-form-item>
  51. <u-form-item label="结算价(元)" required prop="cost">
  52. <u-input clearable type="number" border :min="0" @input="numberToFixed('cost',2,999999)" v-model="form.cost" placeholder="请输入结算价,最多两位小数"/>
  53. </u-form-item>
  54. <u-form-item label="最大库容(件)" required prop="maxQty">
  55. <u-number-box :min="0" :max="999999" positive-integer v-model="form.maxQty" color="#000" bg-color="#f8f8f8" size="30" :input-height="60" :input-width="150"></u-number-box>
  56. </u-form-item>
  57. </view>
  58. <view class="noproduct" v-else @click="toBindProduct">
  59. <view>
  60. <u-empty :src="`/static/${$config('themePath')}/def_no_data@3x.png`" icon-size="150" text="此货位还未绑定产品" mode="list"></u-empty>
  61. </view>
  62. <view>点击去 <text>绑定产品</text></view>
  63. </view>
  64. </u-form>
  65. </view>
  66. <view class="flex footer-btn">
  67. <u-button v-if="type=='bind'" class="delbtn" :loading='loading' @click="handleDel" type='primary' shape="circle" size="medium">删除货位</u-button>
  68. <u-button :disabled="type=='edit'&&nowData&&nowData.shelfProductApiEntity&&nowData.shelfProductApiEntity.enableFlag==0" :style="{width:type=='bind'?'45%':'100%'}" class="newbtn" :loading='loading' @click="formSubmit" type='primary' shape="circle" size="medium">保存</u-button>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import { clzConfirm, numberToFixed } from '@/libs/tools';
  74. import { shelfProductSave, shelfProductDetail, delShelfPlaceSn, shelfProductEnable } from '@/api/shelf'
  75. export default {
  76. data() {
  77. return {
  78. shelfPlaceCode: '',
  79. form: {
  80. productSn: undefined,
  81. productCode: undefined,
  82. shelfProductSn: undefined,
  83. price: '', // 销售价
  84. cost: '', //结算价
  85. maxQty: 1, // 最大库容
  86. },
  87. rules: {
  88. shelfPlaceCode:[
  89. { required: true, message: '请输入货位号', trigger: 'change' },
  90. {
  91. pattern: /^[a-zA-Z]{1}[0-9]{1,5}$/g,
  92. message: '必须字母开头且后面紧跟数字,最多6位'
  93. }
  94. ],
  95. productSn: [{ required: true, message: '请选择绑定产品', trigger: 'change' }],
  96. price: [{ required: true,type:'number', message: '请输入销售价', trigger: 'change' }],
  97. cost: [{ required: true,type:'number', message: '请输入结算价', trigger: 'change' }],
  98. maxQty: [{ required: true,type:'number', message: '请输入最大库容', trigger: 'change' }],
  99. },
  100. productEntity: null,
  101. customerSn: null,
  102. shelfPlaceSn: null,
  103. loading: false,
  104. type:"",
  105. bakProductSn: null
  106. }
  107. },
  108. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  109. onReady() {
  110. this.$refs.uForm.setRules(this.rules);
  111. },
  112. onLoad(opts) {
  113. const _this = this
  114. this.nowData = this.$store.state.vuex_tempData;
  115. console.log(this.nowData)
  116. this.customerSn = this.nowData.customerSn
  117. this.shelfSn = this.nowData.shelfSn
  118. this.type = opts.type
  119. this.shelfPlaceCode = this.nowData.shelfPlaceCode||''
  120. this.form.shelfPlaceCode = this.shelfPlaceCode
  121. // 选在产品
  122. uni.$on('addProductToHw',function(data){
  123. console.log(data)
  124. _this.productEntity = data
  125. _this.form.price = Number(data.price)
  126. _this.form.cost = Number(data.cost)
  127. _this.form.oldPrice = Number(data.price)
  128. _this.form.oldCost = Number(data.cost)
  129. _this.form.productCode = data.code
  130. _this.form.productSn = data.productSn
  131. // 更换产品
  132. if(_this.bakProductSn != data.productSn){
  133. _this.form.updateProductFlag = 1
  134. }
  135. })
  136. // 修改货位号成功
  137. uni.$on('updateHwNo',(data)=>{
  138. this.shelfPlaceCode = data
  139. this.form.shelfPlaceCode = data
  140. })
  141. if(this.type != 'bind'){
  142. // 获取产品信息
  143. this.getProductInfo()
  144. }
  145. },
  146. onUnload(){
  147. uni.$off("addProductToHw")
  148. uni.$off("updateHwNo")
  149. this.$store.state.vuex_tempData = null
  150. },
  151. methods: {
  152. // 小数点后两位
  153. numberToFixed: function (key, num, max) {
  154. let val = this.form[key]
  155. let ret = numberToFixed(val, num, max)
  156. this.$nextTick(() => {
  157. this.form[key] = ret < 0 ? 0 : ret
  158. })
  159. },
  160. placeCodeBlur(v){
  161. this.$nextTick(() => {
  162. this.form.shelfPlaceCode = this.form.shelfPlaceCode.toLocaleUpperCase()
  163. })
  164. },
  165. // 更换产品
  166. toBindProduct(){
  167. if(this.productEntity && this.productEntity.currQty){
  168. uni.showToast({
  169. icon:'none',
  170. title: '只有当前库存为0时才能更换产品',
  171. duration: 4000
  172. })
  173. return
  174. }
  175. uni.navigateTo({
  176. url: "/pages/shelfSetting/bindProduct?customerSn="+this.customerSn+"&shelfSn="+this.shelfSn
  177. })
  178. },
  179. // 编辑货位号
  180. editShelf(){
  181. const type ='edit'
  182. const params={
  183. customerSn: this.nowData.customerSn,
  184. shelfSn: this.nowData.shelfSn,
  185. id: this.nowData.id,
  186. }
  187. uni.navigateTo({
  188. url: "/pages/shelfSetting/addShelfHw?detailData="+encodeURIComponent(JSON.stringify(params))+"&type="+type+"&shelfPlaceCode="+this.shelfPlaceCode
  189. })
  190. },
  191. // 获取产品信息
  192. getProductInfo () {
  193. shelfProductDetail({ shelfPlaceSn: this.nowData && this.nowData.shelfPlaceSn }).then(res => {
  194. if (res.status == 200 && res.data) {
  195. console.log(res.data)
  196. this.productEntity = {
  197. code: res.data.productCode,
  198. name: res.data.productName,
  199. productMsg: res.data.productImageUrl,
  200. currQty: res.data.qty,
  201. unit: res.data.productEntity.unit,
  202. enabledFlag: res.data.productEntity.enabledFlag,
  203. shelfProductSn: res.data.shelfProductSn
  204. }
  205. this.form.productSn = res.data.productSn
  206. this.bakProductSn = res.data.productSn
  207. this.form.productCode = res.data.productCode
  208. this.form.price = res.data.price
  209. this.form.cost = res.data.cost
  210. this.form.maxQty = res.data.maxQty
  211. this.form.oldPrice = res.data.price
  212. this.form.oldCost = res.data.cost
  213. this.form.oldMaxQty = res.data.maxQty
  214. } else {
  215. this.productEntity = null
  216. }
  217. })
  218. },
  219. // 禁用货位产品
  220. enableShelfProduct(){
  221. const _this = this
  222. const isEnable = this.nowData&&this.nowData.shelfProductApiEntity&&this.nowData.shelfProductApiEntity.enableFlag==1
  223. if(isEnable){
  224. clzConfirm({
  225. title: '提示',
  226. content: '禁用后不参于盘点和补货,但是可以退货、调回,确认禁用吗?',
  227. success (ret) {
  228. if (ret.confirm || ret.index == 0) {
  229. _this.enableFun(isEnable)
  230. }
  231. }
  232. })
  233. }else{
  234. _this.enableFun(isEnable)
  235. }
  236. },
  237. enableFun(isEnable){
  238. const _this = this
  239. const shelfProductSn = this.nowData.shelfProductApiEntity.shelfProductSn
  240. _this.spinning = true
  241. shelfProductEnable({ shelfSn: this.nowData.shelfSn, shelfProductSn: shelfProductSn, enableFlag: isEnable ? 0 : 1 }).then(res => {
  242. if (res.status == 200) {
  243. uni.showToast({
  244. icon: "none",
  245. title: res.message
  246. })
  247. this.nowData.shelfProductApiEntity.enableFlag = isEnable ? 0 : 1
  248. // 获取产品信息
  249. this.getProductInfo()
  250. }
  251. _this.spinning = false
  252. })
  253. },
  254. // 删除货位
  255. handleDel (row) {
  256. const _this = this
  257. clzConfirm({
  258. title: '提示',
  259. content: '删除后无法恢复,确认删除?',
  260. success (ret) {
  261. if (ret.confirm || ret.index == 0) {
  262. _this.loading = true
  263. delShelfPlaceSn({ shelfPlaceSn: _this.nowData.shelfPlaceSn }).then(res => {
  264. if (res.status == 200) {
  265. uni.showToast({
  266. icon: "none",
  267. title: res.message
  268. })
  269. uni.navigateBack()
  270. }
  271. _this.loading = false
  272. })
  273. }
  274. }
  275. })
  276. },
  277. // 表单提交
  278. formSubmit(){
  279. const _this = this
  280. if(!this.productEntity){
  281. uni.showToast({
  282. icon: "none",
  283. title: '请先绑定产品'
  284. })
  285. return
  286. }
  287. this.$refs.uForm.validate(valid => {
  288. if (valid) {
  289. const form = JSON.parse(JSON.stringify(_this.form))
  290. form.shelfSn = _this.nowData && _this.nowData.shelfSn
  291. form.shelfPlaceSn = _this.nowData && _this.nowData.shelfPlaceSn
  292. if(this.type != 'bind'){ // 不是绑定产品
  293. form.shelfProductSn = _this.nowData && _this.nowData.shelfProductApiEntity && _this.nowData.shelfProductApiEntity.shelfProductSn || _this.nowData.shelfProductSn
  294. }
  295. // 开始提交数据
  296. _this.loading = true
  297. shelfProductSave(form).then(res => {
  298. if (res.status == 200) {
  299. uni.showToast({
  300. icon: "none",
  301. title: res.message
  302. })
  303. uni.$emit("updateHw",form.shelfPlaceCode)
  304. uni.navigateBack()
  305. }
  306. _this.loading = false
  307. })
  308. } else {
  309. console.log('验证失败');
  310. }
  311. });
  312. },
  313. }
  314. }
  315. </script>
  316. <style lang="less">
  317. .content{
  318. height: 100vh;
  319. width: 100%;
  320. .form-body{
  321. flex-grow: 1;
  322. > view{
  323. background-color: #fff;
  324. padding: 0 1.5rem;
  325. }
  326. .pimgs{
  327. padding:0.1rem;
  328. background:#f8f8f8;
  329. border-radius:0.3rem;
  330. }
  331. .pinfo{
  332. line-height:normal;
  333. padding-left: 20rpx;
  334. color: #666;
  335. .ptxt{
  336. padding-bottom:20rpx;
  337. }
  338. .pcode{
  339. color:rgb(0, 170, 255);
  340. }
  341. .pname{
  342. font-weight: bold;
  343. }
  344. }
  345. .noproduct{
  346. padding: 40rpx 20rpx;
  347. text-align: center;
  348. color: #999;
  349. >view{
  350. padding: 10rpx 0;
  351. }
  352. text{
  353. color: #00aaff;
  354. margin-left: 10rpx;
  355. }
  356. }
  357. }
  358. .footer-btn{
  359. padding: 0.5rem 2rem;
  360. justify-content: space-between;
  361. button{
  362. min-width: 45%;
  363. }
  364. .newbtn{
  365. background-color: rgb(51, 95, 182);
  366. color: #fff;
  367. }
  368. .delbtn{
  369. background-color: #fff;
  370. color: red;
  371. }
  372. }
  373. }
  374. </style>