index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="padding-20">
  3. <div class="search-box">
  4. <el-form ref="form"
  5. :inline="true"
  6. :model="searchForm"
  7. clearable
  8. label-width="100px"
  9. class="mt-10">
  10. <el-form-item label="创建时间:">
  11. <el-date-picker
  12. :editable="false"
  13. v-model="time"
  14. @change="timearr => {timearr ? (searchForm.start_time = timearr[0] + ' 00:00:00', searchForm.end_time = timearr[1] + ' 23:59:59') : searchForm.start_time = searchForm.end_time = undefined}"
  15. type="daterange"
  16. value-format="yyyy-MM-dd"
  17. start-placeholder="开始时间"
  18. end-placeholder="结束时间"
  19. ></el-date-picker>
  20. </el-form-item>
  21. <el-form-item label="部门名称:">
  22. <el-input v-model="searchForm.department_name" placeholder="请输入部门名称" clearable></el-input>
  23. </el-form-item>
  24. <el-form-item class="ml-10">
  25. <el-button icon="el-icon-search" type="primary" @click="searchSubmit">查询</el-button>
  26. </el-form-item>
  27. <el-form-item class="ml-10">
  28. <el-button icon="el-icon-plus"
  29. type="primary"
  30. @click="add">新增
  31. </el-button>
  32. </el-form-item>
  33. </el-form>
  34. </div>
  35. <el-table :data="tableData"
  36. v-loading="tableLoading"
  37. fit
  38. class="marginT-10 order-table"
  39. :max-height="vheight">
  40. <el-table-column type="expand">
  41. <template slot-scope="props">
  42. <el-form label-position="left"
  43. inline
  44. class="demo-table-expand"
  45. label-width="160px">
  46. <el-form-item label="ID">
  47. <span>{{ props.row.id }}</span>
  48. </el-form-item>
  49. <el-form-item label="商品名称">
  50. <span>{{ props.row.product_name }}</span>
  51. </el-form-item>
  52. <el-form-item label="商品分类">
  53. <span>{{ props.row.category_name }}</span>
  54. </el-form-item>
  55. <el-form-item label="价格(元)">
  56. <span>{{ props.row.product_price | fen2Yuan }}</span>
  57. </el-form-item>
  58. <el-form-item label="出单位置">
  59. <span>{{ ['', '厨房', '柜台'][props.row.product_place] }}</span>
  60. </el-form-item>
  61. <el-form-item label="是否上架">
  62. <span>{{ ['下架', '上架'][props.row.product_status] }}</span>
  63. </el-form-item>
  64. <el-form-item label="商品描述">
  65. <div v-html="props.row.product_desc"></div>
  66. </el-form-item>
  67. <el-form-item label="商品图片">
  68. <el-image style="width: 100px; height: 100px"
  69. :src="props.row.product_img_url"
  70. :preview-src-list="[props.row.product_img_url]">
  71. </el-image>
  72. </el-form-item>
  73. <el-form-item label="创建时间">
  74. <span>{{ props.row.created_at }}</span>
  75. </el-form-item>
  76. <el-form-item label="更新时间">
  77. <span>{{ props.row.updated_at }}</span>
  78. </el-form-item>
  79. <el-form-item label="SKU"></el-form-item>
  80. <div class="table-layout">
  81. <el-row>
  82. <el-col :span="2" class="table-cell-title">ID</el-col>
  83. <el-col :span="8" class="table-cell-title">SKU名</el-col>
  84. <el-col :span="2" class="table-cell-title">库存</el-col>
  85. <el-col :span="2" class="table-cell-title">价格</el-col>
  86. <el-col :span="2" class="table-cell-title">是否上架</el-col>
  87. <el-col :span="4" class="table-cell-title">创建时间</el-col>
  88. <el-col :span="4" class="table-cell-title">更新时间</el-col>
  89. </el-row>
  90. <el-row v-for="(item, index) in props.row.skus"
  91. :key="index">
  92. <el-col :span="2" class="table-cell">{{ item.id }}</el-col>
  93. <el-col :span="8" class="table-cell">{{ item.product_sku }}</el-col>
  94. <el-col :span="2" class="table-cell">{{ item.product_stock }}</el-col>
  95. <el-col :span="2" class="table-cell">{{ item.product_price | fen2Yuan }}</el-col>
  96. <el-col :span="2" class="table-cell">{{ ['下架', '上架'][item.product_status] }}</el-col>
  97. <el-col :span="4" class="table-cell">{{ item.created_at }}</el-col>
  98. <el-col :span="4" class="table-cell">{{ item.updated_at }}</el-col>
  99. </el-row>
  100. </div>
  101. <el-form-item label="规格"></el-form-item>
  102. <div class="table-layout">
  103. <el-row>
  104. <el-col :span="2" class="table-cell-title">ID</el-col>
  105. <el-col :span="6" class="table-cell-title">附加名</el-col>
  106. <el-col :span="8" class="table-cell-title">明细</el-col>
  107. <el-col :span="4" class="table-cell-title">创建时间</el-col>
  108. <el-col :span="4" class="table-cell-title">更新时间</el-col>
  109. </el-row>
  110. <el-row v-for="(item, index) in props.row.attachs"
  111. :key="index">
  112. <el-col :span="2" class="table-cell">{{ item.id }}</el-col>
  113. <el-col :span="6" class="table-cell">{{ item.attach_name }}</el-col>
  114. <el-col :span="8" class="table-cell">
  115. <el-tag
  116. class="af-el-tag"
  117. type="info"
  118. v-for="(tag, idx) in item.attach_content.split(',')"
  119. :key="idx">{{ tag }}
  120. </el-tag>
  121. </el-col>
  122. <el-col :span="4" class="table-cell">{{ item.created_at }}</el-col>
  123. <el-col :span="4" class="table-cell">{{ item.updated_at }}</el-col>
  124. </el-row>
  125. </div>
  126. </el-form>
  127. </template>
  128. </el-table-column>
  129. <el-table-column label="ID" prop="id" width="160"></el-table-column>
  130. <el-table-column label="商品名称" prop="product_name"></el-table-column>
  131. <el-table-column label="商品分类" prop="category_name"></el-table-column>
  132. <!--TODO 价格区间-->
  133. <el-table-column label="价格(元)">
  134. <template slot-scope="scope">
  135. <p>{{ scope.row.product_price | fen2Yuan }}</p>
  136. </template>
  137. </el-table-column>
  138. <el-table-column label="出单位置">
  139. <template slot-scope="scope">
  140. <p>{{ ['', '厨房', '柜台'][scope.row.product_place] }}</p>
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="是否上架" width="100">
  144. <template slot-scope="scope">
  145. <p>{{ ['下架', '上架'][scope.row.product_status] }}</p>
  146. </template>
  147. </el-table-column>
  148. <el-table-column label="操作" width="100">
  149. <template slot-scope="scope">
  150. <el-button type="text" @click="edit(scope.row)">编辑</el-button>
  151. <el-button type="text" @click="del(scope.row)">删除</el-button>
  152. </template>
  153. </el-table-column>
  154. </el-table>
  155. <el-pagination
  156. class="marginT-20"
  157. @size-change="handleSizeChange"
  158. @current-change="handleCurrentChange"
  159. :hide-on-single-page="true"
  160. :current-page="page"
  161. :page-size="page_size"
  162. :page-sizes="[10, 20, 100, 200, 300, 400]"
  163. background
  164. layout="total, sizes, prev, pager, next, jumper"
  165. :total="totalCount"/>
  166. <detail v-if="detailsDialog.show"
  167. v-model="detailsDialog.show"
  168. :exData="detailsDialog.exData"
  169. :categoryData="categoryData"
  170. :goodsAttrData="goodsAttrData"
  171. @success="init"></detail>
  172. </div>
  173. </template>
  174. <script>
  175. import page from '@/mixin/page'
  176. import detail from './details'
  177. export default {
  178. mixins: [page],
  179. components: {
  180. detail,
  181. },
  182. data () {
  183. return {
  184. detailsDialog: {
  185. show: false,
  186. exData: {}
  187. },
  188. time: [],
  189. searchForm: {},
  190. tableData: [],
  191. tableUrl: '/v1/bar/product/list',
  192. categoryData: [],
  193. goodsAttrData: []
  194. }
  195. },
  196. methods: {
  197. add () {
  198. this.detailsDialog.exData = {}
  199. this.detailsDialog.show = true
  200. },
  201. edit (row) {
  202. this.detailsDialog.exData = row
  203. this.detailsDialog.show = true
  204. },
  205. del (row) {
  206. this.$confirm('确定要删除吗', '确认', {
  207. confirmButtonText: '确定',
  208. cancelButtonText: '取消',
  209. type: 'warning'
  210. }).then(async () => {
  211. const data = await this.$fetch('/v1/bar/product/delete', { id: row.id }, 'get')
  212. if (data.code === 200) {
  213. this.$message.success('删除成功')
  214. this.init()
  215. }
  216. }).catch(() => {})
  217. },
  218. // todo 优化,放在全局 获取商品分类列表
  219. async fetchCategory () {
  220. const api = '/v1/bar/product/category/list'
  221. const { code, data } = await this.$fetch(api, {
  222. page: 1,
  223. page_size: 10000
  224. }, 'get')
  225. if (this.tableData && (data.data || data.list) && code === 200) {
  226. this.categoryData = data.data || data.list
  227. }
  228. },
  229. // todo 优化,放在全局 获取规格列表
  230. async fetchGoodsAttr () {
  231. const api = '/v1/bar/product/attach/list'
  232. const { code, data } = await this.$fetch(api, {
  233. page: 1,
  234. page_size: 10000
  235. }, 'get')
  236. if (this.tableData && (data.data || data.list) && code === 200) {
  237. this.goodsAttrData = data.data || data.list
  238. }
  239. }
  240. },
  241. mounted () {
  242. this.init()
  243. this.fetchCategory()
  244. this.fetchGoodsAttr()
  245. },
  246. }
  247. </script>
  248. <style lang="scss" scoped>
  249. .demo-table-expand {
  250. .el-form-item {
  251. width: 50%;
  252. margin-right: 0;
  253. margin-bottom: 0;
  254. ::v-deep &__label {
  255. color: #99a9bf;
  256. }
  257. }
  258. }
  259. .table-layout {
  260. margin-top: 20px;
  261. border-left: 1px solid #DCDFE6;
  262. border-top: 1px solid #DCDFE6;
  263. }
  264. .table-cell {
  265. height: 60px;
  266. line-height: 40px;
  267. border-right: 1px solid #DCDFE6;
  268. border-bottom: 1px solid #DCDFE6;
  269. padding: 10px;
  270. font-size: 14px;
  271. color: #606266;
  272. text-align: center;
  273. overflow: hidden;
  274. }
  275. .table-cell-title {
  276. border-right: 1px solid #DCDFE6;
  277. border-bottom: 1px solid #DCDFE6;
  278. padding: 10px;
  279. background: #F2F6FC;
  280. text-align: center;
  281. font-size: 14px;
  282. color: #303133;
  283. }
  284. .af-el-tag {
  285. margin-right: 6px;
  286. margin-bottom: 6px;
  287. }
  288. </style>