editShelfHw.vue 9.3 KB

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