editShelfHw.vue 11 KB

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