commoditylist.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" :title="deviceName"></u-navbar>
  5. <view class="title">常用商品清单</view>
  6. <scroll-view class="scrollview" scroll-y="true" scroll-with-animation="true" lower-threshold="100"
  7. @scrolltolower="loadMore" :style="{height:fullHeight}">
  8. <view class="scroll-content" v-if="commodityList&&commodityList.length>0">
  9. <block v-for="(item,index) in commodityList" :key="item.modelId">
  10. <view class="commoditylist-container xy-card">
  11. <view class="commoditylist-content flex flex-direction justify-between">
  12. <view class="flex-sub">清单名称:{{item.name}}</view>
  13. <view class="flex-sub">设备类型:{{item.deviceTypeName}}</view>
  14. <view class="flex-sub">关联商品:{{item.goodsNum}}件</view>
  15. </view>
  16. <view class="flex align-center justify-end btn-box martop">
  17. <view class='marleft'>
  18. <xbutton size="medium" bgColor="red" round='25rpx' padding='0rpx 20rpx' @click='deleted(item)'>删除</xbutton>
  19. </view>
  20. <view class='marleft'>
  21. <xbutton size="medium" round='25rpx' padding='0rpx 20rpx' @click='modify(item)'>修改</xbutton>
  22. </view>
  23. <view class='marleft'>
  24. <xbutton size="medium" round='25rpx' padding='0rpx 20rpx' @click="relatedgoods(item)">关联商品
  25. </xbutton>
  26. </view>
  27. <view class='marleft'>
  28. <xbutton size="medium" round='25rpx' padding='0rpx 20rpx' @click="application(item)">应用到设备</xbutton>
  29. </view>
  30. </view>
  31. </view>
  32. </block>
  33. <u-loadmore :status="loadmoreStatus" />
  34. </view>
  35. <view style="margin-top: 120rpx;" v-else>
  36. <u-empty mode="data" text="数据为空"></u-empty>
  37. </view>
  38. </scroll-view>
  39. <view class="btn safe-bottom">
  40. <xbutton size='large' width='100%' @click="addcommoditylist">新增商品清单</xbutton>
  41. </view>
  42. <xpopup :show="addcommoditylistShow" @open="open" @close="cancel" @confirm="submit" :title="popTitle">
  43. <view class="addcommoditylist-container">
  44. <!-- <u--input class='martop' clearable suffixIcon="arrow-down" v-model="equipmentTypename"
  45. suffixIconStyle="color: #909399" placeholder="设备类型" border="surround" @focus="actionSheetShow=true">
  46. </u--input> -->
  47. <view class='martop'>
  48. <u--input placeholder="请输入商品清单名称" v-model="name" border="surround"></u--input>
  49. </view>
  50. </view>
  51. </xpopup>
  52. <!-- <u-action-sheet :show="actionSheetShow" :actions="equipmentTypeList" title="请选择设备类型"
  53. @close="actionSheetShow = false" @select="actionsheetSelect($event)"></u-action-sheet> -->
  54. </view>
  55. </template>
  56. <script>
  57. import request from '@/utils/request'
  58. import {
  59. page,
  60. save,
  61. update,
  62. saveGoodsDevice,
  63. del
  64. } from "@/api/commoditylist/commoditylist.js"
  65. import {
  66. detail
  67. } from "@/api/device/device.js"
  68. export default {
  69. data() {
  70. return {
  71. fullHeight: 0,
  72. commodityList: [], //商品清单
  73. name: '',
  74. loadmoreStatus: 'loadmore',
  75. popTitle: '新增清单',
  76. type: '',
  77. equipmentTypename: '',
  78. page: 1, //当前分页
  79. size: 10, //分页数据条数
  80. deviceType: '',
  81. actionSheetShow: false,
  82. addcommoditylistShow: false,
  83. deviceId:null,
  84. deviceName:null,
  85. equipmentTypeList:[]
  86. }
  87. },
  88. onLoad(o) {
  89. let _this = this;
  90. const query = uni.createSelectorQuery().in(this);
  91. query.select(".scrollview").boundingClientRect((data) => {
  92. uni.getSystemInfo({
  93. success(res) {
  94. // 针对iPhone X等机型底部安全距离做适配
  95. const model = res.model;
  96. const modelInclude = ["iPhone X", 'iPhone XR', "iPhone XS", "iPhone XS MAX",
  97. "iPhone XS Max"
  98. ];
  99. let safeDistance = modelInclude.includes(model)
  100. //动态设置商品区域高度
  101. console.log(res.windowHeight, data.top)
  102. if (safeDistance) {
  103. _this.fullHeight = res.windowHeight - data.top - 40 + 'px';
  104. } else {
  105. _this.fullHeight = res.windowHeight - data.top + 'px';
  106. }
  107. },
  108. });
  109. }).exec();
  110. this.deviceId=o.id
  111. },
  112. async onShow() {
  113. await this.getDeviceType()
  114. this.reset()
  115. this.getpage()
  116. },
  117. methods: {
  118. getDeviceType(){
  119. return new Promise((resolve,reject)=>{
  120. detail({
  121. deviceId: this.deviceId,
  122. isSysinfo: false,
  123. isStatus: false,
  124. isRegister: false
  125. }).then(res => {
  126. this.deviceType = res.data.deviceType
  127. this.deviceName=res.data.deviceName
  128. resolve(res)
  129. }).catch(err=>{
  130. resolve(err)
  131. })
  132. })
  133. },
  134. //分页查询
  135. getpage() {
  136. page({
  137. page: {
  138. current: this.page,
  139. size: this.size,
  140. },
  141. deviceType:this.deviceType
  142. }).then(res => {
  143. let dicts=res.data.dicts[0]
  144. for (let key in dicts) {
  145. let item=dicts[key]
  146. this.equipmentTypeList.push(item)
  147. }
  148. let newList=res.data.records
  149. newList.forEach(i=>{
  150. this.equipmentTypeList.forEach(j=>{
  151. if(i.deviceType==j.value){
  152. i.deviceTypeName=j.msg
  153. }
  154. })
  155. })
  156. this.commodityList = this.commodityList.concat(newList)
  157. console.log(this.commodityList)
  158. if (newList.length<10) {
  159. this.loadmoreStatus = 'nomore'
  160. } else {
  161. this.loadmoreStatus = 'loadmore'
  162. }
  163. })
  164. },
  165. reset(){
  166. this.page=1
  167. this.commodityList=[]
  168. },
  169. loadMore(e) {
  170. if (this.loadmoreStatus == 'nomore') return
  171. this.page++
  172. this.getpage()
  173. },
  174. open() {
  175. this.addcommoditylistShow = true
  176. },
  177. //新增商品清单
  178. addcommoditylist() {
  179. this.popTitle = '新增清单'
  180. this.addcommoditylistShow = true
  181. },
  182. actionsheetSelect(e) {
  183. this.equipmentTypename = e.name
  184. this.deviceType = e.deviceType
  185. },
  186. cancel() {
  187. this.addcommoditylistShow = false
  188. },
  189. deleted(item) {
  190. uni.showModal({
  191. title: '提示',
  192. content: '是否确认删除',
  193. success: res=> {
  194. if (res.confirm) {
  195. del({
  196. ids: [item.modelId]
  197. }).then(res => {
  198. if (res.code == 200) {
  199. this.addcommoditylistShow = false
  200. this.reset()
  201. this.getpage()
  202. setTimeout(()=>{
  203. this.$modal.msg('删除成功~')
  204. },500)
  205. }
  206. })
  207. } else if (res.cancel) {
  208. console.log('用户点击取消');
  209. }
  210. }
  211. });
  212. },
  213. modify(item) {
  214. this.popTitle = '修改清单'
  215. this.name = item.name
  216. this.modelId=item.modelId
  217. this.addcommoditylistShow = true
  218. },
  219. // 新增商品清单
  220. submit() {
  221. if (!this.name) {
  222. uni.$u.toast('请填写清单名称')
  223. return;
  224. }
  225. if (this.popTitle == '新增清单') {
  226. save({
  227. name: this.name, //清单名称
  228. deviceType: this.deviceType, //设备类型
  229. }).then(res => {
  230. if (res.code == 200) {
  231. this.addcommoditylistShow = false
  232. this.reset()
  233. this.getpage()
  234. setTimeout(()=>{
  235. this.$modal.msg('新增成功~')
  236. },500)
  237. }
  238. })
  239. }
  240. if (this.popTitle == '修改清单') {
  241. update({
  242. modelId: this.modelId, //id
  243. name: this.name, //清单名称
  244. deviceType: this.deviceType //设备类型
  245. }).then(res => {
  246. if (res.code == 200) {
  247. this.addcommoditylistShow = false
  248. this.reset()
  249. this.getpage()
  250. setTimeout(()=>{
  251. this.$modal.msg('修改成功~')
  252. },500)
  253. }
  254. })
  255. }
  256. },
  257. //清单关联商品
  258. relatedgoods(item) {
  259. this.$tab.navigateTo(`comListEdit?modelId=${item.modelId}&title=${item.name}`)
  260. },
  261. //清单应用到设备
  262. application(item) {
  263. uni.showModal({
  264. title: '提示',
  265. content: `是否确认应用清单至设备${this.deviceName}`,
  266. success: res=> {
  267. if (res.confirm) {
  268. saveGoodsDevice({
  269. deviceIds: [this.deviceId], //设备信息id
  270. modelId: item.modelId //商品清单ID
  271. }).then(res => {
  272. this.$tab.navigateBack()
  273. })
  274. } else if (res.cancel) {
  275. console.log('用户点击取消');
  276. }
  277. }
  278. });
  279. // this.$tab.navigateTo(`application?modelId=${item.modelId}&title=${item.name}`)
  280. },
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. .container {
  286. .martop {
  287. margin-top: 20rpx;
  288. }
  289. .marleft {
  290. margin-left: 20rpx;
  291. }
  292. .title {
  293. margin: 20rpx;
  294. }
  295. .scroll-content{
  296. overflow: hidden;
  297. padding-bottom: calc(120rpx + env(safe-area-inset-bottom) / 2);
  298. }
  299. .commoditylist-container {
  300. margin: 0 13rpx;
  301. &+.commoditylist-container{
  302. margin-top: 20rpx;
  303. }
  304. .commoditylist-content {
  305. padding: 20rpx;
  306. >view{
  307. line-height: 50rpx;
  308. }
  309. }
  310. .btn-box{
  311. }
  312. }
  313. .btn {
  314. width: 724rpx;
  315. position: fixed;
  316. left: 13rpx;
  317. bottom: calc(24rpx + env(safe-area-inset-bottom) / 2);
  318. border-radius: 88rpx;
  319. overflow: hidden;
  320. }
  321. .addcommoditylist-container {
  322. padding: 20rpx 30rpx 40rpx;
  323. }
  324. }
  325. </style>