editShelfHw.vue 11 KB

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