editShelfHw.vue 11 KB

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